+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 );
+
+ if ( !strcmp( name, "s" ) )
+ {
+ // Obtain the size property
+ char *size = mlt_properties_get( properties, "s" );
+ int width = mlt_properties_get_int( properties, "width" );
+ int height = mlt_properties_get_int( properties, "height" );
+ int tw, th;
+
+ if ( sscanf( size, "%dx%d", &tw, &th ) == 2 && tw > 0 && th > 0 )
+ {
+ width = tw;
+ height = th;
+ }
+ else
+ {
+ mlt_log_warning( MLT_CONSUMER_SERVICE(self), "Invalid size property %s - ignoring.\n", size );
+ }
+
+ // Now ensure we honour the multiple of two requested by libavformat
+ width = ( width / 2 ) * 2;
+ 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" ) || !strcmp( name, "width" ) || !strcmp( name, "height" ) )
+ {
+ recompute_aspect_ratio( properties );
+ }
+ // Handle the ffmpeg command line "-r" property for frame rate
+ else if ( !strcmp( name, "r" ) )
+ {
+ double frame_rate = mlt_properties_get_double( properties, "r" );
+ AVRational rational = av_d2q( frame_rate, 255 );
+ mlt_properties_set_int( properties, "frame_rate_num", rational.num );
+ mlt_properties_set_int( properties, "frame_rate_den", rational.den );
+ }
+}
+