[Ffmpeg-devel] Odd AVFrame.linesize Values when Decoding MPEG2
Rich Felker
dalias
Thu Oct 6 00:11:01 CEST 2005
On Wed, Oct 05, 2005 at 05:59:01PM -0400, Paul Curtis wrote:
> I'm writing what I thought was a quick program. The program is only a
> decoder, and only is writing the YUV420 to standard out. The input file
> is a standard MPEG2, playable everywhere.
>
> So as I decode the video, I wait until avcodec_decode_video() indicates
> the frame is finished. However, the linesizes for the three planes are
> not correct. The Y plane linesize is 32 longer than the width of 720,
> and the UV plane linesizes are 16 greater than the width / 2.
>
> Needless to say, attempting to play the decoded video using 'mplayer
> -rawvideo on:w=720:h=480 -' plays a video that looks like the horizontal
> hold (for those who remember) is broken.
>
> I'll leave the initialization code out, but here is the meat of the
> decoder. The code is hardcoded to NTSC 720x480. I'll change that when I
> can get a usuable YUV on standard out.
It's up to your program to pack it in an acceptable fashion. linesize
can be absolutely anything; it has nothing to do with the width of the
picture. In fact it can be negative if the decoder stores the picture
upside-down, iirc.
If you enable edge emulation (which also makes decoding faster) then
linesize will be equal to width as long as width is a multiple of 16,
but you should not rely on this to be the case. Just make your program
write out one line at a time rather than whole frames. If you need to
optimize this for performance you can use stdio buffering or (even
better) the writev syscall.
Rich
More information about the ffmpeg-devel
mailing list