jordanh
12th May 2013, 20:51
It seems that a lot or most, or even all filters have problems when it comes to picture resolution widths that are not multiples of 8. I am not sure about this, thats why i made a topic out of it.
As i am currently developing a Source Filter that of course targets to be compatible to virtually "all" other AVisynth filters, i got to this problem:
720x576 = OK, 1920x1080 = OK, 852x480=FAIL
I needed to experiment more than i liked in order to find out, that all my problems are about about the Pitch. I always assumed that
width*height*bytesperpixel = buffersize //incorrect
but thats WRONG. The correct formula can only be done using the pich:
Height*Pitch = buffersize //correct
Which means for source plugins, they need to find out the pitch dynamically for each resolution and send avisynth the bytes it needs.
What i dont understand is, why video engines like AVISynth and also Carboncoder actually have something like a pitch. (in carbon they call it "stride") What is it good for? - i know that encoders need it that way, or maybe decoders decode it that way.. but is it really neccessary within a framework?
Everything seems to come down to either a multiple of 8 or a multiple of 16. AVISynth seems to keep a stride of multiple of 8.
When i do env->NewVideoFrame(InputVideoInfo), and then GetPitch() on this frame, it will return the next bigger value than the width that a multiple of 8.
e.g. 852 will have a stride of 856*2 (=1712) for yuy2 colorspace (2 bytes per pixel)
and one cannot change that.
Here is some picture visualizing the pitch (its the green bar on the right)
input video 852x480 from carbon where pitch is a multiple of 16, so the pitch is a 864x480 frame
http://img577.imageshack.us/img577/1216/852x480withstride.png (http://imageshack.us/photo/my-images/577/852x480withstride.png/)
...a frame dump of avisynth would have a smaller green bar because the pitch needs to be only 8 bytes less.
The question at this time is, if it can be that i am right and nearly all plugins have troubles with sources thats width isnt a multiple of 8. By now i only tested directshowsource and the Convertto functions. All had problems.
Can i write my source filter in a way that i provide a source that 852 in the "right way" so that the user does not need to do the resize in the avs script?
Harry
Some additional information:
___________________________________________________________________________________________________________________________________________________
Here is how i copy the frames: (unit->stride is actually the pitch)
for (int i=0; i<unit->height;i++){
unsigned char* _in = (unsigned char*) (in_ptr + (i * m_carboncode_inputpitch));//source
unsigned char* _out = (unsigned char*)(out_ptr + (i * m_avisynth_inputpitch));//target
memcpy(_out,_in,unit->width*2);//*2 = hardcodec aligned yuv422 support (2 bytes per pixel)
}
While i am developing my source filter, of course i always prove where things go wrong. I think i proved that the ConvertTo...() functions and the monitor filter have the problems, and i cannot really help them besides resizing the picture to an easy "by 8" resolution
1) "Hello World" just returns the same clip than the Source Plugin:
http://img713.imageshack.us/img713/814/cleanx.png (http://imageshack.us/photo/my-images/713/cleanx.png/)
Uploaded with ImageShack.us (http://imageshack.us)
2) When we use some filterint, the picture lines are shifted
http://img7.imageshack.us/img7/4336/1converttoyuyerror.png (http://imageshack.us/photo/my-images/7/1converttoyuyerror.png/)
Uploaded with ImageShack.us (http://imageshack.us)
3) We can workaround this by resizing the picture before doing other filtering
http://img46.imageshack.us/img46/4181/resizemakesitwork.png (http://imageshack.us/photo/my-images/46/resizemakesitwork.png/)
Uploaded with ImageShack.us (http://imageshack.us)
4) Just for fun, we test if tht monitor plugin is able to process the original resolution while Carboncoder on the right side shows the finally returned clip
http://img198.imageshack.us/img198/3375/monitorpluginhasalsopro.png (http://imageshack.us/photo/my-images/198/monitorpluginhasalsopro.png/)
Uploaded with ImageShack.us (http://imageshack.us)
5) When we use the monitor after the resize, it works as expected
http://img195.imageshack.us/img195/1215/monitorafterresconvert.png (http://imageshack.us/photo/my-images/195/monitorafterresconvert.png/)
Uploaded with ImageShack.us (http://imageshack.us)
As i am currently developing a Source Filter that of course targets to be compatible to virtually "all" other AVisynth filters, i got to this problem:
720x576 = OK, 1920x1080 = OK, 852x480=FAIL
I needed to experiment more than i liked in order to find out, that all my problems are about about the Pitch. I always assumed that
width*height*bytesperpixel = buffersize //incorrect
but thats WRONG. The correct formula can only be done using the pich:
Height*Pitch = buffersize //correct
Which means for source plugins, they need to find out the pitch dynamically for each resolution and send avisynth the bytes it needs.
What i dont understand is, why video engines like AVISynth and also Carboncoder actually have something like a pitch. (in carbon they call it "stride") What is it good for? - i know that encoders need it that way, or maybe decoders decode it that way.. but is it really neccessary within a framework?
Everything seems to come down to either a multiple of 8 or a multiple of 16. AVISynth seems to keep a stride of multiple of 8.
When i do env->NewVideoFrame(InputVideoInfo), and then GetPitch() on this frame, it will return the next bigger value than the width that a multiple of 8.
e.g. 852 will have a stride of 856*2 (=1712) for yuy2 colorspace (2 bytes per pixel)
and one cannot change that.
Here is some picture visualizing the pitch (its the green bar on the right)
input video 852x480 from carbon where pitch is a multiple of 16, so the pitch is a 864x480 frame
http://img577.imageshack.us/img577/1216/852x480withstride.png (http://imageshack.us/photo/my-images/577/852x480withstride.png/)
...a frame dump of avisynth would have a smaller green bar because the pitch needs to be only 8 bytes less.
The question at this time is, if it can be that i am right and nearly all plugins have troubles with sources thats width isnt a multiple of 8. By now i only tested directshowsource and the Convertto functions. All had problems.
Can i write my source filter in a way that i provide a source that 852 in the "right way" so that the user does not need to do the resize in the avs script?
Harry
Some additional information:
___________________________________________________________________________________________________________________________________________________
Here is how i copy the frames: (unit->stride is actually the pitch)
for (int i=0; i<unit->height;i++){
unsigned char* _in = (unsigned char*) (in_ptr + (i * m_carboncode_inputpitch));//source
unsigned char* _out = (unsigned char*)(out_ptr + (i * m_avisynth_inputpitch));//target
memcpy(_out,_in,unit->width*2);//*2 = hardcodec aligned yuv422 support (2 bytes per pixel)
}
While i am developing my source filter, of course i always prove where things go wrong. I think i proved that the ConvertTo...() functions and the monitor filter have the problems, and i cannot really help them besides resizing the picture to an easy "by 8" resolution
1) "Hello World" just returns the same clip than the Source Plugin:
http://img713.imageshack.us/img713/814/cleanx.png (http://imageshack.us/photo/my-images/713/cleanx.png/)
Uploaded with ImageShack.us (http://imageshack.us)
2) When we use some filterint, the picture lines are shifted
http://img7.imageshack.us/img7/4336/1converttoyuyerror.png (http://imageshack.us/photo/my-images/7/1converttoyuyerror.png/)
Uploaded with ImageShack.us (http://imageshack.us)
3) We can workaround this by resizing the picture before doing other filtering
http://img46.imageshack.us/img46/4181/resizemakesitwork.png (http://imageshack.us/photo/my-images/46/resizemakesitwork.png/)
Uploaded with ImageShack.us (http://imageshack.us)
4) Just for fun, we test if tht monitor plugin is able to process the original resolution while Carboncoder on the right side shows the finally returned clip
http://img198.imageshack.us/img198/3375/monitorpluginhasalsopro.png (http://imageshack.us/photo/my-images/198/monitorpluginhasalsopro.png/)
Uploaded with ImageShack.us (http://imageshack.us)
5) When we use the monitor after the resize, it works as expected
http://img195.imageshack.us/img195/1215/monitorafterresconvert.png (http://imageshack.us/photo/my-images/195/monitorafterresconvert.png/)
Uploaded with ImageShack.us (http://imageshack.us)