From: Dan Dennedy Date: Tue, 21 Jan 2014 06:47:24 +0000 (-0800) Subject: Fix aspect ratio if width or height are set after aspect property. X-Git-Url: https://git.sesse.net/?p=mlt;a=commitdiff_plain;h=15c48aa98ea595211ff9156c5a5a0b92e788d474 Fix aspect ratio if width or height are set after aspect property. --- diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 72dcaea7..367d8aaa 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -196,6 +196,27 @@ mlt_consumer consumer_avformat_init( mlt_profile profile, char *arg ) return consumer; } +static void recompute_aspect_ratio( mlt_properties properties ) +{ + double ar = mlt_properties_get_double( properties, "aspect" ); + AVRational rational = av_d2q( ar, 255 ); + int width = mlt_properties_get_int( properties, "width" ); + int height = mlt_properties_get_int( properties, "height" ); + + // Update the profile and properties as well since this is an alias + // for mlt properties that correspond to profile settings + mlt_properties_set_int( properties, "display_aspect_num", rational.num ); + mlt_properties_set_int( properties, "display_aspect_den", rational.den ); + + // Now compute the sample aspect ratio + rational = av_d2q( ar * height / FFMAX(width, 1), 255 ); + + // Update the profile and properties as well since this is an alias + // for mlt properties that correspond to profile settings + mlt_properties_set_int( properties, "sample_aspect_num", rational.num ); + mlt_properties_set_int( properties, "sample_aspect_den", rational.den ); +} + static void property_changed( mlt_properties owner, mlt_consumer self, char *name ) { mlt_properties properties = MLT_CONSUMER_PROPERTIES( self ); @@ -223,27 +244,12 @@ static void property_changed( mlt_properties owner, mlt_consumer self, char *nam height = ( height / 2 ) * 2; mlt_properties_set_int( properties, "width", width ); mlt_properties_set_int( properties, "height", height ); + recompute_aspect_ratio( properties ); } // "-aspect" on ffmpeg command line is display aspect ratio - else if ( !strcmp( name, "aspect" ) ) + else if ( !strcmp( name, "aspect" ) || !strcmp( name, "width" ) || !strcmp( name, "height" ) ) { - double ar = mlt_properties_get_double( properties, "aspect" ); - AVRational rational = av_d2q( ar, 255 ); - int width = mlt_properties_get_int( properties, "width" ); - int height = mlt_properties_get_int( properties, "height" ); - - // Update the profile and properties as well since this is an alias - // for mlt properties that correspond to profile settings - mlt_properties_set_int( properties, "display_aspect_num", rational.num ); - mlt_properties_set_int( properties, "display_aspect_den", rational.den ); - - // Now compute the sample aspect ratio - rational = av_d2q( ar * height / FFMAX(width, 1), 255 ); - - // Update the profile and properties as well since this is an alias - // for mlt properties that correspond to profile settings - mlt_properties_set_int( properties, "sample_aspect_num", rational.num ); - mlt_properties_set_int( properties, "sample_aspect_den", rational.den ); + recompute_aspect_ratio( properties ); } // Handle the ffmpeg command line "-r" property for frame rate else if ( !strcmp( name, "r" ) )