]> granicus.if.org Git - handbrake/commitdiff
Don't crash while scanning when we can't get previews for some title.
authorvan <vanj.hb@gmail.com>
Fri, 29 Feb 2008 18:33:45 +0000 (18:33 +0000)
committervan <vanj.hb@gmail.com>
Fri, 29 Feb 2008 18:33:45 +0000 (18:33 +0000)
 - if we get no previews for some title, ignore the title
 - use the most common aspect ratio found from our 10 previews rather than just the aspect of preview 2 (otherwise we'll crash in hb_fix_aspect if we don't get preview 2).
 - check parameters in hb_fix_aspect so we don't divide by zero.

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

libhb/common.c
libhb/decmpeg2.c
libhb/internal.h
libhb/scan.c

index 5f634179025aa319d1d9ec23b76a7300b17ef7c2..d802f41a548d27330c3b49e1e8e89613d9a8cd13 100644 (file)
@@ -111,6 +111,15 @@ void hb_fix_aspect( hb_job_t * job, int keep )
     hb_title_t * title = job->title;
     int          i;
 
+    /* don't do anything unless the title has complete size info */
+    if ( title->height == 0 || title->width == 0 || title->aspect == 0 )
+    {
+        hb_log( "hb_fix_aspect: incomplete info for title %d: "
+                "height = %d, width = %d, aspect = %d", 
+                title->height, title->width, title->aspect );
+        return;
+    }
+
     /* Sanity checks:
        Widths and heights must be multiples of 16 and greater than or
        equal to 16
index cca18369714a23ecddebac4cfd3fa2ec303f2a59..576b04591c91144ced31a300ed6df9cb71239b7c 100644 (file)
@@ -321,6 +321,13 @@ void hb_libmpeg2_info( hb_libmpeg2_t * m, int * width, int * height,
     *aspect_ratio = m->aspect_ratio;
 }
 
+int hb_libmpeg2_clear_aspect_ratio( hb_libmpeg2_t * m )
+{
+    int ar = m->aspect_ratio;
+    m->aspect_ratio = 0;
+    return ar;
+}
+
 /**********************************************************************
  * hb_libmpeg2_close
  **********************************************************************
index bb111c2adb4788c5297a2d9cec205ce309e66d11..8dfc3afac2748c5ab7fd13e164cc2f3108941328 100644 (file)
@@ -112,6 +112,7 @@ int              hb_libmpeg2_decode( hb_libmpeg2_t *,
 void             hb_libmpeg2_info( hb_libmpeg2_t * m, int * width,
                                     int * height, int * rate, int * aspect_ratio );
 void             hb_libmpeg2_close( hb_libmpeg2_t ** );
+int              hb_libmpeg2_clear_aspect_ratio( hb_libmpeg2_t * );
 
 /***********************************************************************
  * mpegdemux.c
index 25ca92723881c25c547473e9441b47bf300833e9..fd93ca4829b97ac2ac6fbc72e262a14ff6326b8c 100644 (file)
@@ -281,11 +281,12 @@ static void ScanFunc( void * _data )
  **********************************************************************/
 static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
 {
-    int             i, ret;
+    int             i, npreviews = 0;
     hb_buffer_t   * buf_ps, * buf_es, * buf_raw;
     hb_list_t     * list_es, * list_raw;
     hb_libmpeg2_t * mpeg2;
     int progressive_count = 0;
+    int ar16_count = 0, ar4_count = 0;
 
     buf_ps   = hb_buffer_init( HB_DVD_READ_BUFFER_SIZE );
     list_es  = hb_list_init();
@@ -349,6 +350,12 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
                 if( buf_es->id == 0xE0 && !hb_list_count( list_raw ) )
                 {
                     hb_libmpeg2_decode( mpeg2, buf_es, list_raw );
+                    int ar = hb_libmpeg2_clear_aspect_ratio( mpeg2 );
+                    if ( ar != 0 )
+                    {
+                        ( ar == (HB_ASPECT_BASE * 4 / 3) ) ?
+                            ++ar4_count : ++ar16_count ;
+                    }
                 }
                 else if( !i )
                 {
@@ -383,6 +390,11 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
         hb_libmpeg2_info( mpeg2, &title->width, &title->height,
                           &title->rate_base, &ar );
 
+        /* if we found mostly 4:3 previews use that as the aspect ratio otherwise
+           use 16:9 */
+        title->aspect = ar4_count > ar16_count ?
+                            HB_ASPECT_BASE * 4 / 3 : HB_ASPECT_BASE * 16 / 9;
+
         if( title->rate_base == 1126125 )
         {
             /* Frame FPS is 23.976 (meaning it's progressive), so
@@ -421,12 +433,9 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
             title->rate_base = 1126125;
         }
 
-        if( i == 2) // Use the third frame's info, so as to skip opening logos
+        // start from third frame to skip opening logos
+        if( i >= 2)
         {
-            // The aspect ratio may have already been set by parsing the VOB/IFO details on a DVD, however
-            // if we're working with program/transport streams that data needs to come from within the stream.
-            if (title->aspect <= 0)
-              title->aspect = ar;
             title->crop[0] = title->crop[1] = title->height / 2;
             title->crop[2] = title->crop[3] = title->width / 2;
         }
@@ -493,6 +502,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title )
                     break;
                 }
         }
+        ++npreviews;
 
 skip_preview:
         while( ( buf_raw = hb_list_item( list_raw, 0 ) ) )
@@ -507,16 +517,16 @@ skip_preview:
     title->crop[2] = EVEN( title->crop[2] );
     title->crop[3] = EVEN( title->crop[3] );
 
-    hb_log( "scan: %dx%d, %.3f fps, autocrop = %d/%d/%d/%d",
-            title->width, title->height, (float) title->rate /
+    hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, aspect %s",
+            npreviews, title->width, title->height, (float) title->rate /
             (float) title->rate_base, title->crop[0], title->crop[1],
-            title->crop[2], title->crop[3] );
-
-    ret = 1;
+            title->crop[2], title->crop[3],
+            title->aspect == HB_ASPECT_BASE * 16 / 9 ? "16:9" :
+                title->aspect == HB_ASPECT_BASE * 4 / 3 ? "4:3" : "none" );
     goto cleanup;
 
 error:
-    ret = 0;
+    npreviews = 0;
 
 cleanup:
     hb_buffer_close( &buf_ps );
@@ -535,7 +545,7 @@ cleanup:
     if (data->dvd)
       hb_dvd_stop( data->dvd );
 
-    return ret;
+    return npreviews;
 }
 
 static void LookForAC3AndDCA( hb_title_t * title, hb_buffer_t * b )