summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
Diffstat (limited to 'libhb')
-rw-r--r--libhb/common.c9
-rw-r--r--libhb/decmpeg2.c7
-rw-r--r--libhb/internal.h1
-rw-r--r--libhb/scan.c36
4 files changed, 40 insertions, 13 deletions
diff --git a/libhb/common.c b/libhb/common.c
index 5f6341790..d802f41a5 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -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
diff --git a/libhb/decmpeg2.c b/libhb/decmpeg2.c
index cca183697..576b04591 100644
--- a/libhb/decmpeg2.c
+++ b/libhb/decmpeg2.c
@@ -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
**********************************************************************
diff --git a/libhb/internal.h b/libhb/internal.h
index bb111c2ad..8dfc3afac 100644
--- a/libhb/internal.h
+++ b/libhb/internal.h
@@ -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
diff --git a/libhb/scan.c b/libhb/scan.c
index 25ca92723..fd93ca482 100644
--- a/libhb/scan.c
+++ b/libhb/scan.c
@@ -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 )