[Ffmpeg-devel] libavformat MPEG 1/2 "buffer underflow" message

August Mayer amayer
Tue May 31 20:51:46 CEST 2005


Hello all,

I'm using FFMPEG to read MPEG-1/2 files, extract the frames (but don't 
decode them), do some processing, and write them out again using 
av_write_frame (I don't fully decode the frames).

However, when writing out the video frames, FFMPEG produces the message 
"buffer underflow" several times. This happens with the CVS version from 
2005-04-09 (Debian package libavcodeccvs-dev), but not with the released 
version 0.4.9-pre1 ; the output also looks correct for the latter 
version (using a self-made MPEG dumper tool); the CVS version puts the 
audio frames into an earlier position.

I've tried av_interleaved_write_frame, but it doesn't help. Actually, 
how is this function different? I don't really understand the doxygen 
description.

I have looked for the responsible piece of code; it's in 
libavformat/mpeg.c, line 1019 (e.g. 
http://www.mplayerhq.hu/~michael/ffmpeg-doxy/mpeg_8c-source.html ):

01019 static int remove_decoded_packets(AVFormatContext <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structAVFormatContext.html> *ctx, int64_t scr){
01020 //    MpegMuxContext *s = ctx->priv_data;
01021     int i;
01022 
01023     for(i=0; i<ctx->nb_streams <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structAVFormatContext.html#o5>; i++){
01024         AVStream <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structAVStream.html> *st = ctx->streams <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structAVFormatContext.html#o6>[i];
01025         StreamInfo <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html> *stream = st->priv_data <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structAVStream.html#o4>;
01026         PacketDesc <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structPacketDesc.html> *pkt_desc= stream->predecode_packet <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o4>;
01027         
01028         while(pkt_desc && scr > pkt_desc->dts <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structPacketDesc.html#o1>){ //FIXME > vs >=
01029             if(stream->buffer_index <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o3> < pkt_desc->size <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structPacketDesc.html#o2> || 
01030                stream->predecode_packet <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o4> == stream->premux_packet <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o5>){
01031                 av_log <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/libavcodec_2utils_8c.html#a58>(ctx, AV_LOG_ERROR, "buffer underflow\n");
01032                 break;
01033             }
01034             stream->buffer_index <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o3> -= pkt_desc->size <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structPacketDesc.html#o2>;
01035 
01036             stream->predecode_packet <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structStreamInfo.html#o4>= pkt_desc->next <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/structPacketDesc.html#o5>;
01037             av_freep <http://www.mplayerhq.hu/%7Emichael/ffmpeg-doxy/libavcodec_2utils_8c.html#a21>(&pkt_desc);
01038         }
01039     }
01040     
01041     return 0;
01042 }


Is it intended that the while loop can only execute once? av_freep sets 
the pkt_desc to NULL, so
the loop quits after that. I suspect that a "pkt_desc = 
stream->predecode_packet;" is missing, but then I don't really know what 
this function actually should do.

(By the way, does av_write_frame correctly split the video frames into 
multiple MPEG PS packets, or does it put the complete frame into one 
packet? Also, av_read_frame splits up the audio packets into several 
frames; does av_write_frame correctly put these together again?)

thanks & greetings    August Mayer








More information about the ffmpeg-devel mailing list