]> git.sesse.net Git - mlt/commitdiff
Attempt at an aspect ratio clean up
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 27 Oct 2004 09:44:49 +0000 (09:44 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 27 Oct 2004 09:44:49 +0000 (09:44 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@492 d19143bc-622f-0410-bfdd-b5b2a6649095

16 files changed:
src/framework/mlt_consumer.c
src/framework/mlt_frame.c
src/framework/mlt_producer.c
src/framework/mlt_tractor.c
src/inigo/inigo.c
src/modules/avformat/consumer_avformat.c
src/modules/avformat/producer_avformat.c
src/modules/core/filter_resize.c
src/modules/core/filter_watermark.c
src/modules/core/producer_colour.c
src/modules/core/producer_noise.c
src/modules/core/transition_composite.c
src/modules/gtk2/producer_pixbuf.c
src/modules/sdl/consumer_sdl.c
src/modules/sdl/consumer_sdl_preview.c
src/modules/sdl/consumer_sdl_still.c

index 268a5e60708fcb4d9e7697ebb75ef8a9eb275152..ae79cf9db2cbeb28ca0a8b2adba64170078d74f2 100644 (file)
@@ -55,7 +55,7 @@ int mlt_consumer_init( mlt_consumer this, void *child )
                        mlt_properties_set_int( properties, "width", 720 );
                        mlt_properties_set_int( properties, "height", 576 );
                        mlt_properties_set_int( properties, "progressive", 0 );
-                       mlt_properties_set_double( properties, "aspect_ratio", 128.0 / 117.0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 59.0 / 54.0 );
                }
                else
                {
@@ -64,7 +64,7 @@ int mlt_consumer_init( mlt_consumer this, void *child )
                        mlt_properties_set_int( properties, "width", 720 );
                        mlt_properties_set_int( properties, "height", 480 );
                        mlt_properties_set_int( properties, "progressive", 0 );
-                       mlt_properties_set_double( properties, "aspect_ratio", 72.0 / 79.0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 );
                }
 
                // Default rescaler for all consumers
index fe86d675d0d5f36b82733ed10001740111882332..6e23964e82e79d0b755b92f84595dac8fe8c7bef 100644 (file)
@@ -53,7 +53,7 @@ mlt_frame mlt_frame_init( )
                        mlt_properties_set_int( properties, "height", 576 );
                        mlt_properties_set_int( properties, "normalised_width", 720 );
                        mlt_properties_set_int( properties, "normalised_height", 576 );
-                       mlt_properties_set_double( properties, "aspect_ratio", 72.0/79.0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 59.0/54.0 );
                }
                else
                {
@@ -61,7 +61,7 @@ mlt_frame mlt_frame_init( )
                        mlt_properties_set_int( properties, "height", 480 );
                        mlt_properties_set_int( properties, "normalised_width", 720 );
                        mlt_properties_set_int( properties, "normalised_height", 480 );
-                       mlt_properties_set_double( properties, "aspect_ratio", 128.0/117.0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 10.0/11.0 );
                }
 
                mlt_properties_set_data( properties, "audio", NULL, 0, NULL, NULL );
index b1c426993e4ff132c5c2a4bdbac0fe4e026bd102..dab5844545a3d0a7a8d63cc11ffe119e3df2af1b 100644 (file)
@@ -78,12 +78,12 @@ int mlt_producer_init( mlt_producer this, void *child )
                        if ( normalisation == NULL || strcmp( normalisation, "NTSC" ) )
                        {
                                mlt_properties_set_double( properties, "fps", 25.0 );
-                               mlt_properties_set_double( properties, "aspect_ratio", 72.0 / 79.0 );
+                               mlt_properties_set_double( properties, "aspect_ratio", 59.0 / 54.0 );
                        }
                        else
                        {
                                mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 );
-                               mlt_properties_set_double( properties, "aspect_ratio", 128.0 / 117.0 );
+                               mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 );
                        }
                        mlt_properties_set_double( properties, "_speed", 1.0 );
                        mlt_properties_set_position( properties, "in", 0 );
index 2b7616c4d451075b984726c635b757a23710555e..6ad86fcd7145ad6729237978cf0c7de4f1ecf518 100644 (file)
@@ -212,9 +212,10 @@ static int producer_get_image( mlt_frame this, uint8_t **buffer, mlt_image_forma
        mlt_properties_set( frame_properties, "rescale.interp", mlt_properties_get( properties, "rescale.interp" ) );
        if ( mlt_properties_get( properties, "distort" ) )
                mlt_properties_set( frame_properties, "distort", mlt_properties_get( properties, "distort" ) );
-       mlt_properties_set_double( frame_properties, "aspect_ratio", mlt_properties_get_double( properties, "aspect_ratio" ) );
        mlt_properties_set_double( frame_properties, "consumer_aspect_ratio", mlt_properties_get_double( properties, "consumer_aspect_ratio" ) );
        mlt_properties_set_int( frame_properties, "consumer_deinterlace", mlt_properties_get_double( properties, "consumer_deinterlace" ) );
+       mlt_properties_set_int( frame_properties, "normalised_width", mlt_properties_get_double( properties, "normalised_width" ) );
+       mlt_properties_set_int( frame_properties, "normalised_height", mlt_properties_get_double( properties, "normalised_height" ) );
        mlt_frame_get_image( frame, buffer, format, width, height, writable );
        mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL );
        mlt_properties_set_int( properties, "width", *width );
index bc4ad7c4cbeefe4886352f614cbbd55d98833205..bc2f156054119e0be233c91c75ebec863a0f2696 100644 (file)
@@ -145,7 +145,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
 {
        mlt_properties properties = mlt_producer_properties( producer );
        int silent = mlt_properties_get_int( mlt_consumer_properties( consumer ), "silent" );
-
+       struct timespec tm = { 0, 40000 };
 
        if ( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
        {
@@ -167,12 +167,16 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
 
                while( mlt_properties_get_int( properties, "done" ) == 0 && !mlt_consumer_is_stopped( consumer ) )
                {
-                       int value = term_read( );
+                       int value = silent ? -1 : term_read( );
+
                        if ( value != -1 )
                                transport_action( producer, ( char * )&value );
 
                        if ( !silent && mlt_properties_get_int( properties, "stats_off" ) == 0 )
                                fprintf( stderr, "Current Position: %10d\r", mlt_producer_position( producer ) );
+
+                       if ( silent )
+                               nanosleep( &tm, NULL );
                }
 
                if ( !silent )
index 318aec6baaced4f5297d1c4f877a4049a0450174..9b431259fe7503f011a6dd9b69b6e40cd8af60fa 100644 (file)
@@ -853,6 +853,14 @@ static void *consumer_thread( void *arg )
                                                uint8_t *q;
 
                                                mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
+
+                                               // This will cause some fx to go awry....
+                                               if ( mlt_properties_get_int( properties, "transcode" ) )
+                                               {
+                                                       mlt_properties_set_int( mlt_frame_properties( frame ), "normalised_width", img_height * 4.0 / 3.0 );
+                                                       mlt_properties_set_int( mlt_frame_properties( frame ), "normalised_height", img_height );
+                                               }
+
                                                mlt_frame_get_image( frame, &image, &img_fmt, &img_width, &img_height, 0 );
 
                                                q = image;
index 85ee4a5a2b17f0d256932fe4d293fc50f3ef9a34..1cebb3f3c5c9496e43461a0f48cb64f539cfed96 100644 (file)
@@ -691,7 +691,7 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame )
                        else
                        {
                                int is_pal = mlt_properties_get_double( properties, "fps" ) == 25.0;
-                               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 128.0/117.0 : 72.0/79.0 );
+                               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
                        }
 
                        //fprintf( stderr, "AVFORMAT: sample aspect %f %dx%d\n", av_q2d( codec_context->sample_aspect_ratio ), codec_context->width, codec_context->height );
index dcaa2d0125a0ecd59fc3b77a704d656362f60d3c..627d9e0b933c1ee943f0d7dbb2c1d577bf36552c 100644 (file)
@@ -62,6 +62,8 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                double input_ar = mlt_frame_get_aspect_ratio( this ) * real_width / real_height;
                double output_ar = mlt_properties_get_double( properties, "consumer_aspect_ratio" ) * owidth / oheight;
                
+               //fprintf( stderr, "normalised %dx%d output %dx%d %f %f\n", normalised_width, normalised_height, owidth, oheight, ( float )output_ar, ( float )mlt_properties_get_double( properties, "consumer_aspect_ratio" ) * owidth / oheight );
+
                // Optimised for the input_ar > output_ar case (e.g. widescreen on standard)
                int scaled_width = input_ar / output_ar * normalised_width + 0.5;
                int scaled_height = normalised_height;
index 9f6b64d38bf8b31528ee294e6b7b8e8cd384b088..aee35ed3ed43f690b76fc092a4fcdad9460fc39f 100644 (file)
@@ -144,6 +144,9 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
                        mlt_properties_set_int( b_props, "consumer_deinterlace", mlt_properties_get_double( a_props, "consumer_deinterlace" ) );
 
+                       mlt_properties_set_int( b_props, "normalised_width", mlt_properties_get_int( a_props, "normalised_width" ) );
+                       mlt_properties_set_int( b_props, "normalised_height", mlt_properties_get_int( a_props, "normalised_height" ) );
+
                        if ( mlt_properties_get_int( properties, "distort" ) )
                        {
                                mlt_properties_set( mlt_transition_properties( composite ), "distort", "true" );
@@ -168,6 +171,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                int count = 0;
                                uint8_t *alpha = NULL;
                                mlt_transition_process( composite, b_frame, frame );
+                               mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_int( a_props, "consumer_aspect_ratio" ) );
                                mlt_properties_set_int( a_props, "consumer_deinterlace", 1 );
                                mlt_properties_set_int( b_props, "consumer_deinterlace", 1 );
                                mlt_properties_set( a_props, "rescale.interp", "nearest" );
index 2cc677905a2fe4b4772a7f23eda68c1aab1c3a23..b4e8da830cf516df2df97085ecb573c1f4024d13 100644 (file)
@@ -199,7 +199,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", 1 );
-               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 128.0/117.0 : 72.0/79.0 );
+               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
 
                // colour is an alias for resource
                if ( mlt_properties_get( producer_props, "colour" ) != NULL )
index 54d0474dc8882964360452b8c211b034c74c9353..435e7e68c17d3b2b4ccc9f649fb3ca54abf305d4 100644 (file)
@@ -55,8 +55,10 @@ mlt_producer producer_noise_init( void *arg )
        // Initialise the producer
        if ( this != NULL )
        {
+               int is_pal = mlt_properties_get_int( mlt_producer_properties( this ), "normalised_height" ) == 576;
+
                // Synthetic - aspect ratio of 1
-               mlt_properties_set_double( mlt_producer_properties( this ), "aspect_ratio", 1 );
+               mlt_properties_set_double( mlt_producer_properties( this ), "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
 
                // Callback registration
                this->get_frame = producer_get_frame;
@@ -156,7 +158,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
                int is_pal = mlt_properties_get_double( producer_props, "fps" ) == 25.0;
 
                // Aspect ratio is 1?
-               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 128.0/117.0 : 72.0/79.0 );
+               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", 1 );
index 88d6b57cbb58caf8e71066bddb324e02adbe4c82..e03e69b1d6bf302644fb74738a8a62ce85de0f3c 100644 (file)
@@ -866,13 +866,13 @@ static struct geometry_s *composite_calculate( struct geometry_s *result, mlt_tr
        // Structures for geometry
        struct geometry_s *start = mlt_properties_get_data( properties, "geometries", NULL );
 
+       // Obtain the normalised width and height from the a_frame
+       int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
+       int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
+
        // Now parse the geometries
-       if ( start == NULL || mlt_properties_get_int( properties, "refresh" ) )
+       if ( start == NULL || mlt_properties_get_int( properties, "refresh" ) || start->nw != normalised_width || start->nh != normalised_height )
        {
-               // Obtain the normalised width and height from the a_frame
-               int normalised_width = mlt_properties_get_int( a_props, "normalised_width" );
-               int normalised_height = mlt_properties_get_int( a_props, "normalised_height" );
-
                // Parse the transitions properties
                start = transition_parse_keys( this, normalised_width, normalised_height );
 
@@ -1051,6 +1051,8 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                // consumer properties from the a_frame
                mlt_properties_set_double( b_props, "consumer_deinterlace", mlt_properties_get_double( a_props, "consumer_deinterlace" ) );
                mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
+               mlt_properties_set_int( b_props, "normalised_width", mlt_properties_get_double( a_props, "normalised_width" ) );
+               mlt_properties_set_int( b_props, "normalised_height", mlt_properties_get_double( a_props, "normalised_height" ) );
 
                // Special case for titling...
                if ( mlt_properties_get_int( properties, "titles" ) )
index 10b5b8bb6bc7d76653f7fddebecd32ebbf8b183b..4cd7a4cde7723a3fdd81289ce2c62d61631c80d0 100644 (file)
@@ -374,6 +374,9 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
                // Obtain properties of frame and producer
                mlt_properties properties = mlt_frame_properties( *frame );
 
+               // Determine if we're rendering for PAL or NTSC
+               int is_pal = mlt_properties_get_int( properties, "normalised_height" ) == 576;
+
                // Set the producer on the frame properties
                mlt_properties_set_data( properties, "producer_pixbuf", this, 0, NULL, NULL );
 
@@ -388,7 +391,7 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i
 
                // Set producer-specific frame properties
                mlt_properties_set_int( properties, "progressive", 1 );
-               mlt_properties_set_double( properties, "aspect_ratio", 1 );
+               mlt_properties_set_double( properties, "aspect_ratio", is_pal ? 59.0/54.0 : 10.0/11.0 );
 
                // Set alpha call back
                ( *frame )->get_alpha_mask = producer_get_alpha_mask;
index 58741522bf25f0d7a43b98febeadb9836acc879e..b707f78696d89d0bf5bccae0260f3c9e2fb8dc75 100644 (file)
@@ -386,7 +386,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                        SDL_Event event;
        
                        changed = consumer_get_dimensions( &this->window_width, &this->window_height );
-       
+
                        while ( SDL_PollEvent( &event ) )
                        {
                                mlt_events_fire( this->properties, "consumer-sdl-event", &event, NULL );
@@ -420,7 +420,6 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                if ( width != this->width || height != this->height || 
                         ( ( int )( this->last_frame_aspect * 1000 ) != ( int )( mlt_frame_get_aspect_ratio( frame ) * 1000 ) &&
                         ( mlt_frame_get_aspect_ratio( frame ) != 1.0 || this->last_frame_aspect == 0.0 ) ) )
-
                {
                        this->width = width;
                        this->height = height;
@@ -430,12 +429,6 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
 
                if ( this->running && ( this->sdl_screen == NULL || changed ) )
                {
-                       // Determine frame's display aspect ratio
-                       float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * this->width / this->height;
-                       
-                       // Determine window's new display aspect ratio
-                       float this_aspect = ( float )this->window_width / this->window_height;
-
                        // Force an overlay recreation
                        if ( this->sdl_overlay != NULL )
                                SDL_FreeYUVOverlay( this->sdl_overlay );
@@ -446,9 +439,17 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                        sdl_unlock_display();
                        if ( consumer_get_dimensions( &this->window_width, &this->window_height ) )
                                this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
-                       SDL_Flip( this->sdl_screen );
+                       //SDL_Flip( this->sdl_screen );
                        mlt_properties_set_int( properties, "changed", 0 );
-               
+
+                       // Determine window's new display aspect ratio
+                       float this_aspect = ( float )this->window_width / this->window_height;
+
+                       // Determine frame's display aspect ratio
+                       float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * width / height;
+                       this->width = width;
+                       this->height = height;
+
                        // If using hardware scaler
                        if ( mlt_properties_get( properties, "rescale" ) != NULL &&
                                !strcmp( mlt_properties_get( properties, "rescale" ), "none" ) )
@@ -508,13 +509,12 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                                sdl_unlock_display();
                        }
                }
-                       
-               if ( mlt_properties_get_int( properties, "changed" ) )
+               else if ( mlt_properties_get_int( properties, "changed" ) )
                {
                        sdl_lock_display();
                        this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 0, this->sdl_flags );
                        SDL_SetClipRect( this->sdl_screen, &this->rect );
-                       SDL_Flip( this->sdl_screen );
+                       //SDL_Flip( this->sdl_screen );
                        sdl_unlock_display();
                        mlt_properties_set_int( properties, "changed", 0 );
                }
@@ -658,7 +658,8 @@ static void *consumer_thread( void *arg )
                        consumer_get_dimensions( &this->window_width, &this->window_height );
        }
 
-       SDL_InitSubSystem( SDL_INIT_AUDIO );
+       if ( !mlt_properties_get_int( mlt_consumer_properties( consumer ), "audio_off" ) )
+               SDL_InitSubSystem( SDL_INIT_AUDIO );
 
        // Loop until told not to
        while( this->running )
@@ -715,7 +716,8 @@ static void *consumer_thread( void *arg )
        if ( this->sdl_overlay != NULL )
                SDL_FreeYUVOverlay( this->sdl_overlay );
 
-       SDL_QuitSubSystem( SDL_INIT_AUDIO );
+       if ( !mlt_properties_get_int( mlt_consumer_properties( consumer ), "audio_off" ) )
+               SDL_QuitSubSystem( SDL_INIT_AUDIO );
 
        if ( mlt_properties_get_int( mlt_consumer_properties( consumer ), "sdl_started" ) == 0 )
                SDL_Quit( );
index 8bf9e7c775071f46d7b3b19d9d8309fcd46a57af..4b7e11691fad1396984650e6013dad6b100e2490 100644 (file)
@@ -204,6 +204,9 @@ static void *consumer_thread( void *arg )
        mlt_properties_set_data( play, "app_unlock", mlt_properties_get_data( properties, "app_unlock", NULL ), 0, NULL, NULL );
        mlt_properties_set_data( still, "app_unlock", mlt_properties_get_data( properties, "app_unlock", NULL ), 0, NULL, NULL );
 
+       mlt_properties_set_int( play, "progressive", 1 );
+       mlt_properties_set_int( still, "progressive", 1 );
+
        mlt_properties_set_int( play, "put_mode", 1 );
        mlt_properties_set_int( still, "put_mode", 1 );
 
@@ -259,7 +262,6 @@ static void *consumer_thread( void *arg )
                                {
                                        this->last_speed = use_speed;
                                        this->active = this->still;
-                                       this->ignore_change = 5;
                                        mlt_consumer_start( this->still );
                                }
                                mlt_properties_set_int( still, "changed", changed );
index dc0c79e6ebe1f4884ecedf34093354c790429f56..3cf9d097051195964e7cc18ab893b9578801db02 100644 (file)
@@ -176,6 +176,8 @@ static int consumer_start( mlt_consumer parent )
                        mlt_properties_set_int( this->properties, "height", this->height );
                }
 
+               //this->width = this->height * this->display_aspect;
+
                // Inherit the scheduling priority
                pthread_attr_init( &thread_attributes );
                pthread_attr_setinheritsched( &thread_attributes, PTHREAD_INHERIT_SCHED );
@@ -228,8 +230,9 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
        mlt_properties properties = this->properties;
 
        mlt_image_format vfmt = mlt_image_rgb24;
-       int width = this->width, height = this->height;
-       uint8_t *image;
+       int height = this->height;
+       int width = this->width;
+       uint8_t *image = NULL;
        int changed = 0;
 
        void ( *lock )( void ) = mlt_properties_get_data( properties, "app_lock", NULL );
@@ -276,13 +279,9 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                }
        }
 
-       if ( width != this->width || height != this->height || 
-                ( ( int )( this->last_frame_aspect * 1000 ) != ( int )( mlt_frame_get_aspect_ratio( frame ) * 1000 ) &&
+       if ( ( ( int )( this->last_frame_aspect * 1000 ) != ( int )( mlt_frame_get_aspect_ratio( frame ) * 1000 ) &&
                 ( mlt_frame_get_aspect_ratio( frame ) != 1.0 || this->last_frame_aspect == 0.0 ) ) )
-
        {
-               this->width = width;
-               this->height = height;
                this->last_frame_aspect = mlt_frame_get_aspect_ratio( frame );
                changed = 1;
        }
@@ -293,58 +292,25 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
                this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 16, this->sdl_flags );
                if ( consumer_get_dimensions( &this->window_width, &this->window_height ) )
                        this->sdl_screen = SDL_SetVideoMode( this->window_width, this->window_height, 16, this->sdl_flags );
+
                changed = 1;
                mlt_properties_set_int( properties, "changed", 0 );
 
-               // Determine frame's display aspect ratio
-               float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * this->width / this->height;
-               
+               // May as well use the mlt rescaler...
+               //if ( mlt_properties_get( properties, "rescale" ) != NULL && !strcmp( mlt_properties_get( properties, "rescale" ), "none" ) )
+                       //mlt_properties_set( properties, "rescale", "nearest" );
+
                // Determine window's new display aspect ratio
-               float this_aspect = ( float )this->window_width / this->window_height;
+               float this_aspect = this->display_aspect / ( ( float )this->window_width / ( float )this->window_height );
 
-               // If using hardware scaler
-               if ( mlt_properties_get( properties, "rescale" ) != NULL &&
-                       !strcmp( mlt_properties_get( properties, "rescale" ), "none" ) )
-               {
-                       // Special case optimisation to negate odd effect of sample aspect ratio
-                       // not corresponding exactly with image resolution.
-                       if ( ( (int)( this_aspect * 1000 ) == (int)( this->display_aspect * 1000 ) ) && 
-                                ( (int)( mlt_frame_get_aspect_ratio( frame ) * 1000 ) == (int)( this->aspect_ratio * 1000 ) ) )
-                       {
-                               this->rect.w = this->window_width;
-                               this->rect.h = this->window_height;
-                       }
-                       else
-                       {
-                               // Use hardware scaler to normalise display aspect ratio
-                               this->rect.w = frame_aspect / this_aspect * this->window_width;
-                               this->rect.h = this->window_height;
-                               if ( this->rect.w > this->window_width )
-                               {
-                                       this->rect.w = this->window_width;
-                                       this->rect.h = this_aspect / frame_aspect * this->window_height;
-                               }
-                       }
-               }
-               // Special case optimisation to negate odd effect of sample aspect ratio
-               // not corresponding exactly with image resolution.
-               else if ( (int)( this_aspect * 1000 ) == (int)( this->display_aspect * 1000 ) ) 
-               {
-                       this->rect.w = this->window_width;
-                       this->rect.h = this->window_height;
-               }
-               // Use hardware scaler to normalise sample aspect ratio
-               else if ( this->window_height * this->display_aspect > this->window_width )
+               this->rect.w = this_aspect * this->window_width;
+               this->rect.h = this->window_height;
+               if ( this->rect.w > this->window_width )
                {
                        this->rect.w = this->window_width;
-                       this->rect.h = this->window_width / this->display_aspect;
-               }
-               else
-               {
-                       this->rect.w = this->window_height * this->display_aspect;
-                       this->rect.h = this->window_height;
+                       this->rect.h = ( 1.0 / this_aspect ) * this->window_height;
                }
-               
+
                this->rect.x = ( this->window_width - this->rect.w ) / 2;
                this->rect.y = ( this->window_height - this->rect.h ) / 2;
 
@@ -374,9 +340,21 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame )
        this->last_producer = mlt_properties_get_data( mlt_frame_properties( frame ), "_producer", NULL );
 
        // Get the image, width and height
-       mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
-       mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
-       
+       if ( image == NULL )
+       {
+               mlt_events_fire( properties, "consumer-frame-show", frame, NULL );
+
+               // I would like to provide upstream scaling here, but this is incorrect
+               // Something? (or everything?) is too sensitive to aspect ratio
+               //width = this->rect.w;
+               //height = this->rect.h;
+               //mlt_properties_set( mlt_frame_properties( frame ), "distort", "true" );
+               //mlt_properties_set_int( mlt_frame_properties( frame ), "normalised_width", width );
+               //mlt_properties_set_int( mlt_frame_properties( frame ), "normalised_height", height );
+
+               mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
+       }
+
        if ( this->sdl_screen != NULL )
        {
                // Calculate the scan length