]> granicus.if.org Git - handbrake/commitdiff
scan: work around libav mpeg2 dummy first frame
authorjstebbins <jstebbins.hb@gmail.com>
Sun, 15 Feb 2015 21:22:06 +0000 (21:22 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Sun, 15 Feb 2015 21:22:06 +0000 (21:22 +0000)
libav generates a dummy first frame after any seek for some mpeg2 streams.
This results in black preview frames and invalid autocrop values.

So always decode at least 2 frames before using the frame for preview.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6906 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/scan.c

index 74d960117cb13f1fa7c7947fb3c151a5dd2f9f52..d116f6815e1dcad2bf6b74f388401ae0effaffae 100644 (file)
@@ -497,6 +497,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
     int interlaced_preview_count = 0;
     int frame_wait = 0;
     int cc_wait = 10;
+    int frames;
     hb_stream_t  * stream = NULL;
     info_list_t * info_list = calloc( data->preview_count+1, sizeof(*info_list) );
     crop_record_t *crops = crop_record_init( data->preview_count );
@@ -611,6 +612,14 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
                 frame_wait = 10;
             }
         }
+        else
+        {
+            // For certain mpeg-2 streams, libav is delivering a
+            // dummy first frame that is all black.  So always skip
+            // one frame
+            frame_wait = 1;
+        }
+        frames = 0;
 
         hb_buffer_t * vid_buf = NULL;
 
@@ -693,7 +702,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
                     //    additional frames to find the CCs.
                     if (vid_buf != NULL && (frame_wait || cc_wait))
                     {
-                        if (vid_buf->s.frametype == HB_FRAME_I)
+                        if (frames > 0 && vid_buf->s.frametype == HB_FRAME_I)
                             frame_wait = 0;
                         if (frame_wait || cc_wait)
                         {
@@ -701,6 +710,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
                             if (frame_wait) frame_wait--;
                             if (cc_wait) cc_wait--;
                         }
+                        frames++;
                     }
                 }
                 else if( ! AllAudioOK( title ) )