[FFmpeg-devel] [RFC] H.264 error concealment and mpegvideo frame handling

Jason Garrett-Glaser darkshikari
Wed Sep 22 10:29:35 CEST 2010


ffh264 does not handle the case of missing reference frames correctly.
 Suppose we have 16 refs and we just decoded frame num 18.  Here's our
reflist:

18 17 16 15 14 13 12 11 10 9 8 7 6 5 4

Then, we decode frame num 20 (19 went missing):

4 18 17 16 15 14 13 12 11 10 9 8 7 6 5

This is obviously buggy and wrong.  So I do this to fix it:

--- libavcodec/h264.c	(revision 25148)
+++ libavcodec/h264.c	(working copy)
@@ -1905,6 +1905,8 @@
             s->current_picture_ptr->frame_num= h->prev_frame_num;
             ff_generate_sliding_window_mmcos(h);
             ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);
+            ff_copy_picture(h->short_ref[0], h->short_ref[1]);
+            h->short_ref[0]->frame_num = h->prev_frame_num;
         }

         /* See if we have a decoded first field looking for a pair... */

This gives us:

18 18 17 16 15 14 13 12 11 10 9 8 7 6 5

But this breaks because ffh264's ref reordering searches from the
front, not the back, to find a frame, so it dumps them from the list
in the wrong order.

This is fixed as follows:

--- libavcodec/h264_refs.c	(revision 25148)
+++ libavcodec/h264_refs.c	(working copy)
@@ -362,7 +370,7 @@
     MpegEncContext * const s = &h->s;
     int i;

-    for(i=0; i<h->short_ref_count; i++){
+    for(i=h->short_ref_count-1; i>=0; i--){
         Picture *pic= h->short_ref[i];
         if(s->avctx->debug&FF_DEBUG_MMCO)
             av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i,
pic->frame_num, pic);

But now it crashes on shutdown in mpegvideo Picture handling, because
apparently ff_copy_frame doesn't do what I think it does.  What is the
correct way to copy a frame so that buffer handling knows not to
double-free it?

Dark Shikari



More information about the ffmpeg-devel mailing list