From 6ff5549dc913d3976ef611d4c056b0fcb5d520e5 Mon Sep 17 00:00:00 2001 From: ddennedy Date: Sat, 21 Feb 2004 16:01:35 +0000 Subject: [PATCH] fix broken aspect handling again git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@160 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/modules/avformat/producer_avformat.c | 5 +-- src/modules/core/filter_resize.c | 33 ++++++++++--------- src/modules/core/transition_composite.c | 41 +++++++++++++++--------- src/modules/core/transition_luma.c | 2 +- src/tests/Makefile | 2 +- src/tests/dan.c | 19 +++++++---- 6 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index b1631f6f..f1ca0a78 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -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; diff --git a/src/modules/core/filter_resize.c b/src/modules/core/filter_resize.c index 6b29d98c..7e7fac3a 100644 --- a/src/modules/core/filter_resize.c +++ b/src/modules/core/filter_resize.c @@ -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 diff --git a/src/modules/core/transition_composite.c b/src/modules/core/transition_composite.c index b5121edc..3e4a7eab 100644 --- a/src/modules/core/transition_composite.c +++ b/src/modules/core/transition_composite.c @@ -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 ); diff --git a/src/modules/core/transition_luma.c b/src/modules/core/transition_luma.c index c55a88b5..9a180d1b 100644 --- a/src/modules/core/transition_luma.c +++ b/src/modules/core/transition_luma.c @@ -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; diff --git a/src/tests/Makefile b/src/tests/Makefile index e6883dd8..3b48d274 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -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 diff --git a/src/tests/dan.c b/src/tests/dan.c index 8f0dca5d..051fb398 100644 --- a/src/tests/dan.c +++ b/src/tests/dan.c @@ -1,5 +1,8 @@ #include +#include "../modules/dv/producer_libdv.h" +#include "../modules/dv/consumer_libdv.h" +//#include "../modules/sdl/consumer_sdl.h" #include @@ -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 -- 2.39.2