[Ffmpeg-devel] Odd AVFrame.linesize Values when Decoding MPEG2

Paul Curtis pfc
Wed Oct 5 23:59:01 CEST 2005

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.



     for (;;) {
        if (pkt_read)

        if (av_read_packet(ic, &pkt) < 0)

        pkt_read = 1;
        bytes_decoded = 0;
        bytes_remaining = pkt.size;
        rawData = pkt.data;

        if (pkt.stream_index == audioIndex) {
           audioSampleCount = 0;
           do {
              samples= av_fast_realloc(samples, &samples_size, 
              bytes_decoded = avcodec_decode_audio(audioCodecCtx, 
samples, &bytes_decoded, rawData, bytes_remaining);
              audioSampleCount += bytes_decoded;
              rawData += bytes_decoded;
              bytes_remaining -= bytes_decoded;
           } while (bytes_remaining > 0);

        if (pkt.stream_index == videoIndex) {
           do {
              bytes_decoded = avcodec_decode_video(videoCodecCtx, 
&frame, &finished, rawData, bytes_remaining);
              rawData += bytes_decoded;
              bytes_remaining -= bytes_decoded;
              if (finished) {
//              fprintf(stderr, " video frame: %d %d %d\n", 
frame.linesize[0], frame.linesize[1], frame.linesize[2]);
                 write(1, frame.data[0], 345600);
                 write(1, frame.data[1], 86400);
                 write(1, frame.data[2], 86400);
           } while (bytes_remaining > 0);
        if (videoStart > 300)

More information about the ffmpeg-devel mailing list