]> git.sesse.net Git - mlt/commitdiff
Fix aspect ratio if width or height are set after aspect property.
authorDan Dennedy <dan@dennedy.org>
Tue, 21 Jan 2014 06:47:24 +0000 (22:47 -0800)
committerDan Dennedy <dan@dennedy.org>
Tue, 21 Jan 2014 06:47:24 +0000 (22:47 -0800)
src/modules/avformat/consumer_avformat.c

index 72dcaea75c11be91be23fb13b9dc070d86585b00..367d8aaad0c2979682aa0e4d60a0606162a4b8a2 100644 (file)
@@ -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" ) )