fix broken aspect handling again
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sat, 21 Feb 2004 16:01:35 +0000 (16:01 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sat, 21 Feb 2004 16:01:35 +0000 (16:01 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@160 d19143bc-622f-0410-bfdd-b5b2a6649095

src/modules/avformat/producer_avformat.c
src/modules/core/filter_resize.c
src/modules/core/transition_composite.c
src/modules/core/transition_luma.c
src/tests/Makefile
src/tests/dan.c

index b1631f6..f1ca0a7 100644 (file)
@@ -558,16 +558,17 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame )
                                double source_fps = 0;
 
                                // Set aspect ratio
-                               if ( codec_context->sample_aspect_ratio.num == 0) 
+                               if ( codec_context->sample_aspect_ratio.num == 0 ) 
                                        aspect_ratio = 0;
                                else
                                        aspect_ratio = av_q2d( codec_context->sample_aspect_ratio ) * codec_context->width / codec_context->height;
 
+                               // XXX: This assumes square pixels!
                        if (aspect_ratio <= 0.0)
                                        aspect_ratio = ( double )codec_context->width / ( double )codec_context->height;
 
                                mlt_properties_set_double( properties, "aspect_ratio", aspect_ratio );
-                               fprintf( stderr, "AVFORMAT: sample aspect %f\n", aspect_ratio );
+                               fprintf( stderr, "AVFORMAT: sample aspect %f computed display aspect %f\n", av_q2d( codec_context->sample_aspect_ratio ), aspect_ratio );
 
                                // Determine the fps
                                source_fps = ( double )codec_context->frame_rate / codec_context->frame_rate_base;
index 6b29d98..7e7fac3 100644 (file)
@@ -53,41 +53,42 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        if ( mlt_properties_get( properties, "distort" ) == NULL )
        {
-               // Now do additional calcs based on real_width/height etc
+               // Normalise the input and out display aspect
                int normalised_width = mlt_properties_get_int( properties, "normalised_width" );
                int normalised_height = mlt_properties_get_int( properties, "normalised_height" );
-               int real_width = get_value( properties, "real_width", "width" );
-               int real_height = get_value( properties, "real_height", "height" );
                double input_ar = mlt_frame_get_aspect_ratio( this );
                double output_ar = mlt_properties_get_double( properties, "consumer_aspect_ratio" );
-               int scaled_width = ( input_ar > output_ar ? input_ar / output_ar : output_ar / input_ar ) * real_width;
-               int scaled_height = ( input_ar > output_ar ? input_ar / output_ar : output_ar / input_ar ) * real_height;
+               
+               // Optimised for the input_ar > output_ar case (e.g. widescreen on standard)
+               int scaled_width = normalised_width;
+               int scaled_height = output_ar / input_ar * normalised_height;
 
                // Now ensure that our images fit in the normalised frame
-               if ( scaled_width > normalised_width )
-               {
-                       scaled_height = scaled_height * normalised_width / scaled_width;
-                       scaled_width = normalised_width;
-               }
                if ( scaled_height > normalised_height )
                {
-                       scaled_width = scaled_width * normalised_height / scaled_height;
+                       scaled_width = input_ar / output_ar * normalised_width;
                        scaled_height = normalised_height;
                }
+               //fprintf( stderr, "resize: %dx%d from %dx%d input aspect %f output aspect %f\n",
+               //      scaled_width, scaled_height, normalised_width, normalised_height, input_ar, output_ar );
 
-               if ( input_ar == output_ar && scaled_height == normalised_height )
-               {
-                       scaled_width = normalised_width;
-               }
-               else if ( ( real_height * 2 ) == normalised_height )
+#if 0
+               int real_width = get_value( properties, "real_height", "height" );
+               int real_height = get_value( properties, "real_height", "height" );
+               // DRD> Why?
+               if ( ( real_height * 2 ) == normalised_height )
                {
                        scaled_width = normalised_width;
                        scaled_height = normalised_height;
                }
+#endif
        
                // Now calculate the actual image size that we want
                owidth = scaled_width * owidth / normalised_width;
                oheight = scaled_height * oheight / normalised_height;
+
+               // Tell frame we have conformed the aspect to the consumer
+               mlt_frame_set_aspect_ratio( this, output_ar );
        }
 
        // Now pass on the calculations down the line
index b5121ed..3e4a7ea 100644 (file)
@@ -322,18 +322,34 @@ static int get_b_frame_image( mlt_frame b_frame, uint8_t **image, int *width, in
 
        if ( mlt_properties_get( properties, "distort" ) == NULL )
        {
-               // Now do additional calcs based on real_width/height etc
+               // Adjust b_frame pixel aspect
                int normalised_width = geometry->w;
                int normalised_height = geometry->h;
-               //int real_width = get_value( b_props, "real_width", "width" );
+               int real_width = get_value( b_props, "real_width", "width" );
                int real_height = get_value( b_props, "real_height", "height" );
                double input_ar = mlt_frame_get_aspect_ratio( b_frame );
                double output_ar = mlt_properties_get_double( b_props, "consumer_aspect_ratio" );
                //int scaled_width = ( input_ar > output_ar ? input_ar / output_ar : output_ar / input_ar ) * real_width;
                //int scaled_height = ( input_ar > output_ar ? input_ar / output_ar : output_ar / input_ar ) * real_height;
-               int scaled_width = ( float )geometry->nw / geometry->nh / output_ar * real_height * input_ar;
+               int scaled_width = real_width;
                int scaled_height = real_height;
-               //fprintf( stderr, "composite: real %dx%d scaled %dx%d normalised %dx%d\n", real_width, real_height, scaled_width, scaled_height, normalised_width, normalised_height );
+               double output_sar = ( double ) geometry->nw / geometry->nh / output_ar;
+
+               // We always normalise pixel aspect by requesting a larger than normal
+               // image in order to maximise usage of the bounding rectangle
+
+               // These calcs are optimised by reducing factors in equations
+               if ( output_sar < 1.0 )
+                       // If the output is skinny pixels (PAL) then stretch our input vertically
+                       // derived from: input_sar / output_sar * real_height
+                       scaled_height = ( double )real_width / input_ar / output_sar;
+
+               else
+                       // If the output is fat pixels (NTSC) then stretch our input horizontally
+                       // derived from: output_sar / input_sar * real_width
+                       scaled_width = output_sar * real_height * input_ar;
+                       
+//             fprintf( stderr, "composite: real %dx%d scaled %dx%d normalised %dx%d\n", real_width, real_height, scaled_width, scaled_height, normalised_width, normalised_height );
 
                // Now ensure that our images fit in the normalised frame
                if ( scaled_width > normalised_width )
@@ -347,9 +363,12 @@ static int get_b_frame_image( mlt_frame b_frame, uint8_t **image, int *width, in
                        scaled_height = normalised_height;
                }
 
+#if 0
+               // DRD> Why?
                // Special case
                if ( scaled_height == normalised_height )
                        scaled_width = normalised_width;
+#endif
 
                // Now we need to align to the geometry
                if ( scaled_width <= geometry->w && scaled_height <= geometry->h )
@@ -357,20 +376,12 @@ static int get_b_frame_image( mlt_frame b_frame, uint8_t **image, int *width, in
                        // Save the new scaled dimensions
                        geometry->sw = scaled_width;
                        geometry->sh = scaled_height;
-                       
-                       mlt_properties_set( b_props, "distort", "true" );
                }
-               else
-               {
-                       mlt_properties_set( b_props, "distort", "true" );
-               }
-       }
-       else
-       {
-               // We want to ensure that we bypass resize now...
-               mlt_properties_set( b_props, "distort", "true" );
        }
 
+       // We want to ensure that we bypass resize now...
+       mlt_properties_set( b_props, "distort", "true" );
+
        // Take into consideration alignment for optimisation
        alignment_calculate( geometry );
 
index c55a88b..9a180d1 100644 (file)
@@ -160,7 +160,7 @@ static void luma_composite( mlt_frame a_frame, mlt_frame b_frame, int luma_width
 
        uint8_t y;
        uint8_t uv;
-       float value;
+       float value;
 
        float x_diff = ( float )luma_width / ( float )*width;
        float y_diff = ( float )luma_height / ( float )*height;
index e6883dd..3b48d27 100644 (file)
@@ -2,7 +2,7 @@ TARGET = dan charlie pango pixbuf dissolve luma
 
 CFLAGS = -O3 -I .. -Wall -rdynamic -pthread
 
-LDFLAGS = -L ../framework -lmlt 
+LDFLAGS = -L ../framework -L ../modules -lmlt -lmltdv -lmltsdl
 
 ifeq ($(MLT_GPROF),true)
 CFLAGS+=-p
index 8f0dca5..051fb39 100644 (file)
@@ -1,5 +1,8 @@
 
 #include <framework/mlt.h>
+#include "../modules/dv/producer_libdv.h"
+#include "../modules/dv/consumer_libdv.h"
+//#include "../modules/sdl/consumer_sdl.h"
 
 #include <stdio.h>
 
@@ -9,7 +12,8 @@ int main( int argc, char **argv )
        char *file1 = NULL;
        char *file2 = NULL;
 
-       mlt_factory_init( "../modules" );
+//     mlt_factory_init( "../modules" );
+       mlt_pool_init( );
 
        if ( argc >= 2 )
                file1 = argv[ 1 ];
@@ -19,13 +23,15 @@ int main( int argc, char **argv )
        // Start the consumer...
        int vstd = mlt_video_standard_ntsc;
        //mlt_consumer consumer = mlt_factory_consumer( "bluefish", &vstd );
-       mlt_consumer consumer = mlt_factory_consumer( "westley", NULL );
+       //mlt_consumer consumer = mlt_factory_consumer( "sdl", NULL );
+       mlt_consumer consumer = consumer_libdv_init( NULL );
 
        // Create the producer(s)
-       mlt_producer dv1 = mlt_factory_producer( "westley", file1 );
+       //mlt_producer dv1 = mlt_factory_producer( "libdv", file1 );
+       mlt_producer dv1 = producer_libdv_init( file1 );
        //mlt_producer_set_in_and_out( dv1, 0, 5 );
 
-       mlt_producer dv2 = mlt_factory_producer( "libdv", file2 );
+       mlt_producer dv2;// = mlt_factory_producer( "libdv", file2 );
        //mlt_producer_set_in_and_out( dv2, 10.0, 30.0 );
 
 #if 1
@@ -34,10 +40,11 @@ int main( int argc, char **argv )
 
        // Do stuff until we're told otherwise...
        mlt_consumer_start( consumer );
-//     fprintf( stderr, "Press return to continue\n" );
-//     fgets( temp, 132, stdin );
+       fprintf( stderr, "Press return to continue\n" );
+       fgets( temp, 132, stdin );
        mlt_consumer_stop( consumer );
        mlt_consumer_close( consumer );
+       mlt_pool_close( );
        return 0;
 #endif