Index: libhb/hb.c =================================================================== --- libhb/hb.c (revision 1485) +++ libhb/hb.c (working copy) @@ -657,7 +657,7 @@ int pixel_aspect_width = job->pixel_aspect_width; int pixel_aspect_height = job->pixel_aspect_height; - if (cropped_width <= 706) + if (cropped_width <= 706 && !title->pixel_aspect_width && !title->pixel_aspect_height) { /* Handle ITU PARs */ if (title->height == 480) Index: libhb/decavcodec.c =================================================================== --- libhb/decavcodec.c (revision 1485) +++ libhb/decavcodec.c (working copy) @@ -483,11 +483,15 @@ (double)context->width / (double)context->sample_aspect_ratio.den / (double)context->height + 0.05 ) * HB_ASPECT_BASE; + info->pixel_aspect_width = context->sample_aspect_ratio.num; + info->pixel_aspect_height = context->sample_aspect_ratio.den; - if( context->sample_aspect_ratio.num == 0 ) - { - info->aspect = (double)context->width / (double)context->height * HB_ASPECT_BASE; - } + if( context->sample_aspect_ratio.num == 0 ) + { + info->aspect = (double)context->width / (double)context->height * HB_ASPECT_BASE; + info->pixel_aspect_width = 1; + info->pixel_aspect_height = 1; + } info->profile = context->profile; info->level = context->level; info->name = context->codec->name; Index: libhb/scan.c =================================================================== --- libhb/scan.c (revision 1487) +++ libhb/scan.c (working copy) @@ -176,6 +176,12 @@ /* Autocrop by default. Gnark gnark */ memcpy( job->crop, title->crop, 4 * sizeof( int ) ); + if( title->pixel_aspect_width && title->pixel_aspect_height ) + { + job->pixel_aspect_width = title->pixel_aspect_width; + job->pixel_aspect_height = title->pixel_aspect_height; + } + if( title->aspect == 16 && !job->pixel_aspect_width && !job->pixel_aspect_height) { hb_reduce( &job->pixel_aspect_width, &job->pixel_aspect_height, @@ -345,6 +351,9 @@ title->width = vid_info.width; title->height = vid_info.height; + title->pixel_aspect_width = vid_info.pixel_aspect_width; + title->pixel_aspect_height = vid_info.pixel_aspect_height; + title->rate = vid_info.rate; title->rate_base = vid_info.rate_base; if ( vid_info.aspect != 0 ) @@ -354,21 +363,25 @@ hb_log( "aspect ratio changed from %g to %g", last_ar, vid_info.aspect ); } - switch ( (int)vid_info.aspect ) + + if( !title->pixel_aspect_width && !title->pixel_aspect_height ) { - case HB_ASPECT_BASE * 4 / 3: - ++ar4_count; - break; - case HB_ASPECT_BASE * 16 / 9: - ++ar16_count; - break; - default: - hb_log( "unknown aspect ratio %g", vid_info.aspect ); - /* if the aspect is closer to 4:3 use that - * otherwise use 16:9 */ - vid_info.aspect < HB_ASPECT_BASE * 14 / 9 ? ++ar4_count : - ++ar16_count; - break; + switch ( (int)vid_info.aspect ) + { + case HB_ASPECT_BASE * 4 / 3: + ++ar4_count; + break; + case HB_ASPECT_BASE * 16 / 9: + ++ar16_count; + break; + default: + hb_log( "unknown aspect ratio %g", vid_info.aspect ); + /* if the aspect is closer to 4:3 use that + * otherwise use 16:9 */ + vid_info.aspect < HB_ASPECT_BASE * 14 / 9 ? ++ar4_count : + ++ar16_count; + break; + } } last_ar = vid_info.aspect; } @@ -489,23 +502,31 @@ if ( vid_buf ) hb_buffer_close( &vid_buf ); } + + if( title->pixel_aspect_width && title->pixel_aspect_width ) + { + title->aspect = ( (double)title->pixel_aspect_width * + (double)title->width / + (double)title->pixel_aspect_height / + (double)title->height + 0.05 ) * HB_ASPECT_BASE; + } + else + { + /* 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 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; - title->crop[0] = EVEN( title->crop[0] ); title->crop[1] = EVEN( title->crop[1] ); title->crop[2] = EVEN( title->crop[2] ); title->crop[3] = EVEN( title->crop[3] ); - hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, aspect %s", + hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, aspect %.2f", npreviews, title->width, title->height, (float) title->rate / (float) title->rate_base, title->crop[0], title->crop[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" ); + title->crop[2], title->crop[3], (float)title->aspect/(float)HB_ASPECT_BASE); if( interlaced_preview_count >= ( npreviews / 2 ) ) { Index: libhb/common.h =================================================================== --- libhb/common.h (revision 1485) +++ libhb/common.h (working copy) @@ -437,6 +437,8 @@ int width; int height; int aspect; + int pixel_aspect_width; + int pixel_aspect_height; int rate; int rate_base; int crop[4]; @@ -521,6 +523,8 @@ struct { // info only valid for video decoders int width; int height; + int pixel_aspect_width; + int pixel_aspect_height; double aspect; }; struct { // info only valid for audio decoders