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

August Mayer amayer
Sun Jun 5 19:59:10 CEST 2005


Hello again,

I'd like to follow up once more on my "buffer underflow" issue. Is some 
information missing in the mail, or is nobody working on this at 
current? Sorry for the code formatting, it was the E-Mail program.

thanks & greetings   August Mayer


August Mayer wrote:

> 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 *ctx, int64_t 
> scr){
> 01020   // MpegMuxContext *s = ctx->priv_data;
> 01021   int i;
> 01022
> 01023   for(i=0; i<ctx->nb_streams; i++){
> 01024     AVStream *st = ctx->streams[i];
> 01025     StreamInfo *stream = st->priv_data;
> 01026     PacketDesc *pkt_desc= stream->predecode_packet;
> 01027
> 01028     while(pkt_desc && scr > pkt_desc->dts){ //FIXME > vs >=
> 01029       if(stream->buffer_index < pkt_desc->size ||
> 01030           stream->predecode_packet == stream->premux_packet ){
> 01031         av_log (ctx, AV_LOG_ERROR, "buffer underflow\n");
> 01032         break;
> 01033       }
> 01034       stream->buffer_index -= pkt_desc->size;
> 01035
> 01036       stream->predecode_packet = pkt_desc->next;
> 01037       av_freep (&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