]> granicus.if.org Git - handbrake/commitdiff
scan: fix very slow scanning for some files
authorJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 12 Apr 2017 21:09:26 +0000 (15:09 -0600)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 12 Apr 2017 21:09:26 +0000 (15:09 -0600)
The threshold in bytes for when to give up trying to decode a frame was
too big for a lot of streams.  It was made large to accomodate 4K raw
video.  Instead of counting bytes, count frames fed to the decoder.
This is more consistant regardless of video resolution and codec.

libhb/common.h
libhb/decavcodec.c
libhb/scan.c

index e6ef1270d62f2c5494a563e9e15b2a397af9e781..a9bc3d412b914112996a564a6dc16babcac01bf0 100644 (file)
@@ -1151,6 +1151,7 @@ struct hb_work_object_s
     volatile int      * done;
     volatile int      * die;
     int                 status;
+    int                 frame_count;
     int                 codec_param;
     hb_title_t        * title;
 
index 7b94274e130cd085c9c43259f0699aae0b1696f4..cf62002fe2043ac49a07bc3632893705de638354 100644 (file)
@@ -1375,6 +1375,7 @@ static void decodeVideo( hb_work_object_t *w, hb_buffer_t * in)
             pv->packet_info.dts          = parser_dts;
 
             decodeFrame(w, &pv->packet_info);
+            w->frame_count++;
 
             // There could have been an unfinished packet when we entered
             // decodeVideo that is now finished.  The next packet is associated
index 8b5c5d47a5e5d97b9d722351f9994b7f90ee37cd..86d1f324d98d77070b578cbc024898ad486379d2 100644 (file)
@@ -31,7 +31,7 @@ typedef struct
     uint64_t       min_title_duration;
 } hb_scan_t;
 
-#define PREVIEW_READ_THRESH (1024 * 1024 * 300)
+#define PREVIEW_READ_THRESH (200)
 
 static void ScanFunc( void * );
 static int  DecodePreviews( hb_scan_t *, hb_title_t * title, int flush );
@@ -676,8 +676,9 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
 
         hb_buffer_t * vid_buf = NULL;
 
-        int total_read = 0, packets = 0;
-        while (total_read < PREVIEW_READ_THRESH ||
+        int packets = 0;
+        vid_decoder->frame_count = 0;
+        while (vid_decoder->frame_count < PREVIEW_READ_THRESH ||
               (!AllAudioOK(title) && packets < 10000))
         {
             if (data->bd)
@@ -741,7 +742,6 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
                 abort = 1;
                 goto skip_preview;
             }
-            total_read += buf->size;
             packets++;
 
             (hb_demux[title->demuxer])(buf, &list_es, 0 );