From efd5f25f6fe70f75f9787e9c7f2b53730ecf6048 Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Tue, 21 Jun 2005 20:59:39 +0000 Subject: [PATCH] src/framework/mlt_consumer.c src/framework/mlt_consumer.h + Added a general profile handling for size, aspect ratio and display ratio src/framework/mlt_producer.c + Correction to aspect ratio properties src/inigo/inigo.c + Minimalist support for sdl_preview (still not very good) src/modules/avformat/consumer_avformat.c + Takes consumer profile into account src/modules/core/filter_resize.c + Corrections for synthesised producers and aspect ratio (inherits from consumer) src/modules/core/producer_colour.c src/modules/core/producer_noise.c src/modules/gtk2/producer_pango.c + Ensures that resize picks up consumer aspect ratio src/modules/dv/consumer_libdv.c + Honour wide screen output src/modules/gtk2/producer_pixbuf.c + Correction for 1:1 aspect ratio src/modules/kino/Makefile src/modules/kino/avi.cc src/modules/kino/avi.h src/modules/kino/configure src/modules/kino/filehandler.cc + Attempt to allow mov dv files to provide audio src/modules/sdl/consumer_sdl.c src/modules/sdl/consumer_sdl_preview.c src/modules/sdl/consumer_sdl_still.c + Takes consumer profile into account git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@736 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_consumer.c | 194 +++++++++++++++++++++++++++++- src/framework/mlt_consumer.h | 1 + src/framework/mlt_producer.c | 8 +- src/inigo/inigo.c | 4 + src/modules/avformat/consumer_avformat.c | 41 +++++-- src/modules/core/filter_resize.c | 7 +- src/modules/core/producer_colour.c | 5 +- src/modules/core/producer_noise.c | 10 +-- src/modules/dv/consumer_libdv.c | 2 +- src/modules/gtk2/producer_pango.c | 2 +- src/modules/gtk2/producer_pixbuf.c | 5 +- src/modules/kino/Makefile | 6 + src/modules/kino/avi.cc | 43 +++++++- src/modules/kino/avi.h | 43 +++++++- src/modules/kino/configure | 6 + src/modules/kino/filehandler.cc | 25 ++-- src/modules/sdl/consumer_sdl.c | 57 ++++----- src/modules/sdl/consumer_sdl_preview.c | 4 + src/modules/sdl/consumer_sdl_still.c | 41 ++----- 19 files changed, 388 insertions(+), 116 deletions(-) diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 8f99db4..5b48e6d 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -53,23 +53,33 @@ int mlt_consumer_init( mlt_consumer this, void *child ) { mlt_properties_set( properties, "normalisation", "PAL" ); mlt_properties_set_double( properties, "fps", 25.0 ); - mlt_properties_set_int( properties, "frame_rate_den", 25 ); - mlt_properties_set_int( properties, "frame_rate_num", 1 ); + mlt_properties_set_int( properties, "frame_rate_num", 25 ); + mlt_properties_set_int( properties, "frame_rate_den", 1 ); 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", 59.0 / 54.0 ); + mlt_properties_set_int( properties, "aspect_ratio_num", 59 ); + mlt_properties_set_int( properties, "aspect_ratio_den", 54 ); + mlt_properties_set_double( properties, "display_ratio", 4.0 / 3.0 ); + mlt_properties_set_int( properties, "display_ratio_num", 4 ); + mlt_properties_set_int( properties, "display_ratio_den", 3 ); } else { mlt_properties_set( properties, "normalisation", "NTSC" ); mlt_properties_set_double( properties, "fps", 30000.0 / 1001.0 ); - mlt_properties_set_int( properties, "frame_rate_den", 30000 ); - mlt_properties_set_int( properties, "frame_rate_num", 1001 ); + mlt_properties_set_int( properties, "frame_rate_num", 30000 ); + mlt_properties_set_int( properties, "frame_rate_den", 1001 ); 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", 10.0 / 11.0 ); + mlt_properties_set_int( properties, "aspect_ratio_num", 10 ); + mlt_properties_set_int( properties, "aspect_ratio_den", 11 ); + mlt_properties_set_double( properties, "display_ratio", 4.0 / 3.0 ); + mlt_properties_set_int( properties, "display_ratio_num", 4 ); + mlt_properties_set_int( properties, "display_ratio_den", 3 ); } // Default rescaler for all consumers @@ -166,6 +176,16 @@ int mlt_consumer_start( mlt_consumer this ) // Determine if there's a test card producer char *test_card = mlt_properties_get( properties, "test_card" ); + // Handle profiles + char *profile = mlt_properties_get( properties, "profile" ); + int profile_ok = mlt_consumer_profile( properties, profile ); + + // Check that everything is OK + if ( !profile_ok ) + fprintf( stderr, "Unrecognised profile %s - continuing with defaults.\n", mlt_properties_get( properties, "profile" ) ); + else if ( profile_ok < 0 ) + fprintf( stderr, "Recognised profile %s with warnings - trying to continue with some defaults.\n", mlt_properties_get( properties, "profile" ) ); + // Just to make sure nothing is hanging around... mlt_frame_close( this->put ); this->put = NULL; @@ -327,6 +347,168 @@ static inline long time_difference( struct timeval *time1 ) return time1->tv_sec * 1000000 + time1->tv_usec - time2.tv_sec * 1000000 - time2.tv_usec; } +int mlt_consumer_profile( mlt_properties properties, char *profile ) +{ + double fps = mlt_properties_get_double( properties, "fps" ); + int recognised = 1; + double display_num = 0; + double display_den = 0; + double pixel_num = 0; + double pixel_den = 0; + int width = 0; + int height = 0; + + if ( fps == 25.0 && profile != NULL ) + { + width = 720; + height = 576; + display_num = 4; + display_den = 3; + pixel_num = 59; + pixel_den = 54; + + if ( !strcmp( profile, "dv_wide" ) ) + { + display_num = 16; + display_den = 9; + pixel_num = 118; + pixel_den = 81; + } + else if ( !strncmp( profile, "square_wide", 11 ) ) + { + display_num = 16; + display_den = 9; + pixel_num = 1; + pixel_den = 1; + width = 1024; + height = 576; + } + else if ( !strncmp( profile, "square", 6 ) ) + { + pixel_num = 1; + pixel_den = 1; + width = 768; + height = 576; + } + else if ( !strncmp( profile, "vcd", 3 ) ) + { + width = 352; + height = 288; + } + else if ( !strncmp( profile, "cvd", 3 ) ) + { + width = 352; + height = 576; + pixel_num = 59; + pixel_den = 27; + } + else if ( !strncmp( profile, "svcd_wide", 9 ) ) + { + width = 480; + height = 576; + pixel_num = 59; + pixel_den = 27; + display_num = 16; + display_den = 9; + } + else if ( !strncmp( profile, "svcd", 4 ) ) + { + width = 480; + height = 576; + pixel_num = 59; + pixel_den = 36; + } + else if ( strncmp( profile, "frame", 5 ) && strcmp( profile, "dv" ) ) + { + recognised = 0; + } + } + else if ( profile != NULL ) + { + width = 720; + height = 480; + display_num = 4; + display_den = 3; + pixel_num = 10; + pixel_den = 11; + + if ( !strcmp( profile, "dv_wide" ) ) + { + display_num = 16; + display_den = 9; + pixel_num = 40; + pixel_den = 33; + } + else if ( !strncmp( profile, "square_wide", 11 ) ) + { + display_num = 16; + display_den = 9; + pixel_num = 1; + pixel_den = 1; + width = 854; + height = 480; + } + else if ( !strncmp( profile, "square", 6 ) ) + { + pixel_num = 1; + pixel_den = 1; + width = 640; + height = 480; + } + else if ( !strncmp( profile, "vcd", 3 ) ) + { + width = 352; + height = 240; + } + else if ( !strncmp( profile, "cvd", 3 ) ) + { + width = 352; + height = 480; + pixel_num = 20; + pixel_den = 11; + } + else if ( !strncmp( profile, "svcd_wide", 9 ) ) + { + width = 480; + height = 480; + pixel_num = 20; + pixel_den = 11; + display_num = 16; + display_den = 9; + } + else if ( !strncmp( profile, "svcd", 4 ) ) + { + width = 480; + height = 480; + pixel_num = 15; + pixel_den = 11; + } + else if ( strncmp( profile, "frame", 5 ) && strcmp( profile, "dv" ) ) + { + recognised = 0; + } + } + + // If width (or any of the above are 0), we use defaults otherwise we switch to recognised + if ( width != 0 && recognised ) + { + if ( recognised && strchr( profile, ':' ) ) + if ( sscanf( strchr( profile, ':' ) + 1, "%dx%d", &width, &height ) != 2 ) + recognised = -1; + + mlt_properties_set_int( properties, "width", width ); + mlt_properties_set_int( properties, "height", height ); + mlt_properties_set_double( properties, "aspect_ratio", pixel_num / pixel_den ); + mlt_properties_set_int( properties, "aspect_ratio_num", pixel_num ); + mlt_properties_set_int( properties, "aspect_ratio_den", pixel_den ); + mlt_properties_set_double( properties, "display_ratio", display_num / display_den ); + mlt_properties_set_int( properties, "display_ratio_num", display_num ); + mlt_properties_set_int( properties, "display_ratio_den", display_den ); + } + + return recognised; +} + static void *consumer_read_ahead_thread( void *arg ) { // The argument is the consumer @@ -407,6 +589,10 @@ static void *consumer_read_ahead_thread( void *arg ) // Continue to read ahead while ( this->ahead ) { + // Fetch width/height again + width = mlt_properties_get_int( properties, "width" ); + height = mlt_properties_get_int( properties, "height" ); + // Put the current frame into the queue pthread_mutex_lock( &this->mutex ); while( this->ahead && mlt_deque_count( this->queue ) >= buffer ) diff --git a/src/framework/mlt_consumer.h b/src/framework/mlt_consumer.h index 873f421..82a08b4 100644 --- a/src/framework/mlt_consumer.h +++ b/src/framework/mlt_consumer.h @@ -75,5 +75,6 @@ extern int mlt_consumer_stop( mlt_consumer self ); extern int mlt_consumer_is_stopped( mlt_consumer self ); extern void mlt_consumer_stopped( mlt_consumer self ); extern void mlt_consumer_close( mlt_consumer ); +extern int mlt_consumer_profile( mlt_properties properties, char *profile ); #endif diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index 4963baa..f3233f9 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -89,15 +89,15 @@ 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_int( properties, "frame_rate_den", 25 ); - mlt_properties_set_int( properties, "frame_rate_num", 1 ); + mlt_properties_set_int( properties, "frame_rate_num", 25 ); + mlt_properties_set_int( properties, "frame_rate_den", 1 ); 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_int( properties, "frame_rate_den", 30000 ); - mlt_properties_set_int( properties, "frame_rate_num", 1001 ); + mlt_properties_set_int( properties, "frame_rate_num", 30000 ); + mlt_properties_set_int( properties, "frame_rate_den", 1001 ); mlt_properties_set_double( properties, "aspect_ratio", 10.0 / 11.0 ); } mlt_properties_set_double( properties, "_speed", 1.0 ); diff --git a/src/inigo/inigo.c b/src/inigo/inigo.c index f7ffffc..5c8e9b8 100644 --- a/src/inigo/inigo.c +++ b/src/inigo/inigo.c @@ -11,6 +11,7 @@ static void transport_action( mlt_producer producer, char *value ) { mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer ); mlt_multitrack multitrack = mlt_properties_get_data( properties, "multitrack", NULL ); + mlt_consumer consumer = mlt_properties_get_data( properties, "transport_consumer", NULL ); mlt_properties_set_int( properties, "stats_off", 0 ); @@ -122,6 +123,8 @@ static void transport_action( mlt_producer producer, char *value ) } break; } + + mlt_properties_set_int( MLT_CONSUMER_PROPERTIES( consumer ), "refresh", 1 ); } mlt_properties_set_int( properties, "stats_off", 0 ); @@ -138,6 +141,7 @@ static mlt_consumer create_consumer( char *id, mlt_producer producer ) mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer ); mlt_properties_set_data( properties, "transport_callback", transport_action, 0, NULL, NULL ); mlt_properties_set_data( properties, "transport_producer", producer, 0, NULL, NULL ); + mlt_properties_set_data( MLT_PRODUCER_PROPERTIES( producer ), "transport_consumer", consumer, 0, NULL, NULL ); } return consumer; } diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index febd134..fbb978e 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -158,7 +158,6 @@ mlt_consumer consumer_avformat_init( char *arg ) mlt_properties_set_int( properties, "audio_bit_rate", 128000 ); mlt_properties_set_int( properties, "video_bit_rate", 200 * 1000 ); mlt_properties_set_int( properties, "video_bit_rate_tolerance", 4000 * 1000 ); - mlt_properties_set_int( properties, "frame_rate_base", 1 ); mlt_properties_set_int( properties, "gop_size", 12 ); mlt_properties_set_int( properties, "b_frames", 0 ); mlt_properties_set_int( properties, "mb_decision", FF_MB_DECISION_SIMPLE ); @@ -331,6 +330,17 @@ static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int c c->bit_rate = mlt_properties_get_int( properties, "audio_bit_rate" ); c->sample_rate = mlt_properties_get_int( properties, "frequency" ); c->channels = mlt_properties_get_int( properties, "channels" ); + + // Allow the user to override the audio fourcc + if ( mlt_properties_get( properties, "afourcc" ) ) + { + char *tail = NULL; + char *arg = mlt_properties_get( properties, "afourcc" ); + int tag = strtol( arg, &tail, 0); + if( !tail || *tail ) + tag = arg[ 0 ] + ( arg[ 1 ] << 8 ) + ( arg[ 2 ] << 16 ) + ( arg[ 3 ] << 24 ); + c->codec_tag = tag; + } } else { @@ -417,8 +427,8 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c c->bit_rate_tolerance = mlt_properties_get_int( properties, "video_bit_rate_tolerance" ); c->width = mlt_properties_get_int( properties, "width" ); c->height = mlt_properties_get_int( properties, "height" ); - c->time_base.den = mlt_properties_get_int( properties, "frame_rate_den" ); - c->time_base.num = mlt_properties_get_int( properties, "frame_rate_num" ); + c->time_base.num = mlt_properties_get_int( properties, "frame_rate_den" ); + c->time_base.den = mlt_properties_get_int( properties, "frame_rate_num" ); c->gop_size = mlt_properties_get_int( properties, "gop_size" ); c->pix_fmt = PIX_FMT_YUV420P; @@ -430,7 +440,7 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c } c->mb_decision = mlt_properties_get_int( properties, "mb_decision" ); - c->sample_aspect_ratio = av_d2q( mlt_properties_get_double( properties, "aspect_ratio" ), 255 ); + c->sample_aspect_ratio = av_d2q( mlt_properties_get_double( properties, "display_ratio" ) * c->height / c->width, 255 ); c->mb_cmp = mlt_properties_get_int( properties, "mb_cmp" ); c->ildct_cmp = mlt_properties_get_int( properties, "ildct_cmp" ); c->me_sub_cmp = mlt_properties_get_int( properties, "sub_cmp" ); @@ -459,10 +469,19 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c st->quality = FF_QP2LAMBDA * mlt_properties_get_double( properties, "qscale" ); } - // Some formats want stream headers to be seperate (hmm) - if( !strcmp( oc->oformat->name, "mp4" ) || - !strcmp( oc->oformat->name, "mov" ) || - !strcmp( oc->oformat->name, "3gp" ) ) + // Allow the user to override the video fourcc + if ( mlt_properties_get( properties, "vfourcc" ) ) + { + char *tail = NULL; + const char *arg = mlt_properties_get( properties, "vfourcc" ); + int tag = strtol( arg, &tail, 0); + if( !tail || *tail ) + tag = arg[ 0 ] + ( arg[ 1 ] << 8 ) + ( arg[ 2 ] << 16 ) + ( arg[ 3 ] << 24 ); + c->codec_tag = tag; + } + + // Some formats want stream headers to be seperate + if ( oc->oformat->flags & AVFMT_GLOBALHEADER ) c->flags |= CODEC_FLAG_GLOBAL_HEADER; c->rc_max_rate = mlt_properties_get_int( properties, "video_rc_max_rate" ); @@ -538,7 +557,7 @@ static int open_video(AVFormatContext *oc, AVStream *st) if( codec && codec->supported_framerates ) { const AVRational *p = codec->supported_framerates; - AVRational req = ( AVRational ){ video_enc->time_base.den, video_enc->time_base.num }; + AVRational req = ( AVRational ){ video_enc->time_base.num, video_enc->time_base.den }; const AVRational *best = NULL; AVRational best_error = (AVRational){ INT_MAX, 1 }; for( ; p->den!=0; p++ ) @@ -552,8 +571,8 @@ static int open_video(AVFormatContext *oc, AVStream *st) best = p; } } - video_enc->time_base.den = best->num; - video_enc->time_base.num = best->den; + video_enc->time_base.num = best->num; + video_enc->time_base.den = best->den; } if( codec && codec->pix_fmts ) diff --git a/src/modules/core/filter_resize.c b/src/modules/core/filter_resize.c index d245ed0..c9884e8 100644 --- a/src/modules/core/filter_resize.c +++ b/src/modules/core/filter_resize.c @@ -43,6 +43,10 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * int owidth = *width; int oheight = *height; + // Check for the special case - no aspect ratio means no problem :-) + if ( mlt_frame_get_aspect_ratio( this ) == 0 ) + mlt_properties_set_double( properties, "aspect_ratio", mlt_properties_get_double( properties, "consumer_aspect_ratio" ) ); + // Hmmm... char *rescale = mlt_properties_get( properties, "rescale.interp" ); if ( rescale != NULL && !strcmp( rescale, "none" ) ) @@ -61,6 +65,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * real_height = mlt_properties_get_int( properties, "height" ); 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 ); @@ -74,7 +79,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format * scaled_width = normalised_width; scaled_height = output_ar / input_ar * normalised_height + 0.5; } - + // Now calculate the actual image size that we want owidth = scaled_width * owidth / normalised_width; oheight = scaled_height * oheight / normalised_height; diff --git a/src/modules/core/producer_colour.c b/src/modules/core/producer_colour.c index c1fa168..c2f645b 100644 --- a/src/modules/core/producer_colour.c +++ b/src/modules/core/producer_colour.c @@ -199,9 +199,6 @@ static int producer_get_frame( mlt_producer producer, mlt_frame_ptr frame, int i // Obtain properties of producer mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); - // Determine if we're producing PAL or NTSC - int is_pal = mlt_properties_get_double( producer_props, "fps" ) == 25.0; - // Set the producer on the frame properties mlt_properties_set_data( properties, "producer_colour", producer, 0, NULL, NULL ); @@ -210,7 +207,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 ? 59.0/54.0 : 10.0/11.0 ); + mlt_properties_set_double( properties, "aspect_ratio", 0 ); // colour is an alias for resource if ( mlt_properties_get( producer_props, "colour" ) != NULL ) diff --git a/src/modules/core/producer_noise.c b/src/modules/core/producer_noise.c index 8bc21c3..1b71cda 100644 --- a/src/modules/core/producer_noise.c +++ b/src/modules/core/producer_noise.c @@ -151,14 +151,8 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index // Obtain properties of frame mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); - // Obtain properties of producer - mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( this ); - - // Determine if we're producing PAL or NTSC - 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 ? 59.0/54.0 : 10.0/11.0 ); + // Aspect ratio is whatever it needs to be + mlt_properties_set_double( properties, "aspect_ratio", 0 ); // Set producer-specific frame properties mlt_properties_set_int( properties, "progressive", 1 ); diff --git a/src/modules/dv/consumer_libdv.c b/src/modules/dv/consumer_libdv.c index c8f58bd..dbb817e 100644 --- a/src/modules/dv/consumer_libdv.c +++ b/src/modules/dv/consumer_libdv.c @@ -280,7 +280,7 @@ static void consumer_encode_audio( mlt_consumer this, uint8_t *dv_frame, mlt_fra time_t start = time( NULL ); int height = mlt_properties_get_int( this_properties, "height" ); int is_pal = height == 576; - int is_wide = mlt_properties_get_double( frame_properties, "fps" ) == ( ( double ) 16.0 / 9.0 ); + int is_wide = mlt_properties_get_int( this_properties, "display_ratio_num" ) == 16; // Temporary - audio buffer allocation int16_t *audio_buffers[ 4 ]; diff --git a/src/modules/gtk2/producer_pango.c b/src/modules/gtk2/producer_pango.c index 37b1abb..84082db 100644 --- a/src/modules/gtk2/producer_pango.c +++ b/src/modules/gtk2/producer_pango.c @@ -493,7 +493,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", 0 ); // Set alpha call back ( *frame )->get_alpha_mask = producer_get_alpha_mask; diff --git a/src/modules/gtk2/producer_pixbuf.c b/src/modules/gtk2/producer_pixbuf.c index e007ccd..df23189 100644 --- a/src/modules/gtk2/producer_pixbuf.c +++ b/src/modules/gtk2/producer_pixbuf.c @@ -383,9 +383,6 @@ 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 ); @@ -400,7 +397,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 ? 59.0/54.0 : 10.0/11.0 ); + mlt_properties_set_double( properties, "aspect_ratio", 1 ); // Set alpha call back ( *frame )->get_alpha_mask = producer_get_alpha_mask; diff --git a/src/modules/kino/Makefile b/src/modules/kino/Makefile index dd51d4b..a0dc327 100644 --- a/src/modules/kino/Makefile +++ b/src/modules/kino/Makefile @@ -14,6 +14,12 @@ CXXFLAGS+=`lqt-config --cflags` LDFLAGS+=`lqt-config --libs` endif +ifdef HAVE_LIBDV +CFLAGS += `pkg-config --cflags libdv` +LDFLAGS += `pkg-config --libs libdv` +endif + + SRCS := $(OBJS:.o=.c) $(CPPOBJS:.o=.cc) all: $(TARGET) diff --git a/src/modules/kino/avi.cc b/src/modules/kino/avi.cc index 1ed29ad..2ee0c99 100644 --- a/src/modules/kino/avi.cc +++ b/src/modules/kino/avi.cc @@ -21,6 +21,45 @@ * Change log: * * $Log$ +* Revision 1.2 2005/06/21 20:59:39 lilo_booter +* src/framework/mlt_consumer.c src/framework/mlt_consumer.h +* + Added a general profile handling for size, aspect ratio and display ratio +* +* src/framework/mlt_producer.c +* + Correction to aspect ratio properties +* +* src/inigo/inigo.c +* + Minimalist support for sdl_preview (still not very good) +* +* src/modules/avformat/consumer_avformat.c +* + Takes consumer profile into account +* +* src/modules/core/filter_resize.c +* + Corrections for synthesised producers and aspect ratio (inherits from consumer) +* +* src/modules/core/producer_colour.c +* src/modules/core/producer_noise.c +* src/modules/gtk2/producer_pango.c +* + Ensures that resize picks up consumer aspect ratio +* +* src/modules/dv/consumer_libdv.c +* + Honour wide screen output +* +* src/modules/gtk2/producer_pixbuf.c +* + Correction for 1:1 aspect ratio +* +* src/modules/kino/Makefile +* src/modules/kino/avi.cc +* src/modules/kino/avi.h +* src/modules/kino/configure +* src/modules/kino/filehandler.cc +* + Attempt to allow mov dv files to provide audio +* +* src/modules/sdl/consumer_sdl.c +* src/modules/sdl/consumer_sdl_preview.c +* src/modules/sdl/consumer_sdl_still.c +* + Takes consumer profile into account +* * Revision 1.1 2005/04/15 14:28:26 lilo_booter * Initial version * @@ -376,7 +415,7 @@ void AVIFile::Init( int format, int sampleFrequency, int indexType ) { indx[ i ] ->wLongsPerEntry = 4; indx[ i ] ->bIndexSubType = 0; - indx[ i ] ->bIndexType = AVI_INDEX_OF_INDEXES; + indx[ i ] ->bIndexType = KINO_AVI_INDEX_OF_INDEXES; indx[ i ] ->nEntriesInUse = 0; indx[ i ] ->dwReserved[ 0 ] = 0; indx[ i ] ->dwReserved[ 1 ] = 0; @@ -983,7 +1022,7 @@ void AVIFile::FlushIndx( int stream ) ix[ stream ] ->wLongsPerEntry = 2; ix[ stream ] ->bIndexSubType = 0; - ix[ stream ] ->bIndexType = AVI_INDEX_OF_CHUNKS; + ix[ stream ] ->bIndexType = KINO_AVI_INDEX_OF_CHUNKS; ix[ stream ] ->nEntriesInUse = 0; ix[ stream ] ->dwChunkId = indx[ stream ] ->dwChunkId; ix[ stream ] ->qwBaseOffset = offset + length; diff --git a/src/modules/kino/avi.h b/src/modules/kino/avi.h index e7ce66c..68f2ea4 100644 --- a/src/modules/kino/avi.h +++ b/src/modules/kino/avi.h @@ -21,6 +21,45 @@ * Change log: * * $Log$ +* Revision 1.3 2005/06/21 20:59:39 lilo_booter +* src/framework/mlt_consumer.c src/framework/mlt_consumer.h +* + Added a general profile handling for size, aspect ratio and display ratio +* +* src/framework/mlt_producer.c +* + Correction to aspect ratio properties +* +* src/inigo/inigo.c +* + Minimalist support for sdl_preview (still not very good) +* +* src/modules/avformat/consumer_avformat.c +* + Takes consumer profile into account +* +* src/modules/core/filter_resize.c +* + Corrections for synthesised producers and aspect ratio (inherits from consumer) +* +* src/modules/core/producer_colour.c +* src/modules/core/producer_noise.c +* src/modules/gtk2/producer_pango.c +* + Ensures that resize picks up consumer aspect ratio +* +* src/modules/dv/consumer_libdv.c +* + Honour wide screen output +* +* src/modules/gtk2/producer_pixbuf.c +* + Correction for 1:1 aspect ratio +* +* src/modules/kino/Makefile +* src/modules/kino/avi.cc +* src/modules/kino/avi.h +* src/modules/kino/configure +* src/modules/kino/filehandler.cc +* + Attempt to allow mov dv files to provide audio +* +* src/modules/sdl/consumer_sdl.c +* src/modules/sdl/consumer_sdl_preview.c +* src/modules/sdl/consumer_sdl_still.c +* + Takes consumer profile into account +* * Revision 1.2 2005/04/15 14:37:03 lilo_booter * Minor correction * @@ -110,8 +149,8 @@ #define AVI_SMALL_INDEX (0x01) #define AVI_LARGE_INDEX (0x02) -#define AVI_INDEX_OF_INDEXES (0x00) -#define AVI_INDEX_OF_CHUNKS (0x01) +#define KINO_AVI_INDEX_OF_INDEXES (0x00) +#define KINO_AVI_INDEX_OF_CHUNKS (0x01) #define AVI_INDEX_2FIELD (0x01) enum { AVI_PAL, AVI_NTSC, AVI_AUDIO_48KHZ, AVI_AUDIO_44KHZ, AVI_AUDIO_32KHZ }; diff --git a/src/modules/kino/configure b/src/modules/kino/configure index 7c57d91..17c00f3 100755 --- a/src/modules/kino/configure +++ b/src/modules/kino/configure @@ -6,12 +6,18 @@ then lqt-config --prefix > /dev/null 2>&1 lqt_disabled=$? + pkg-config libdv 2> /dev/null + libdv_disabled=$? + echo > config.h [ "$lqt_disabled" = "0" ] && echo "#define HAVE_LIBQUICKTIME" >> config.h + [ "$libdv_disabled" = "0" ] && echo "#define HAVE_LIBDV" >> config.h echo > config.mak [ "$lqt_disabled" = "0" ] && echo "HAVE_LIBQUICKTIME=1" >> config.mak + [ "$libdv_disabled" = "0" ] && echo "HAVE_LIBDV=1" >> config.mak [ "$lqt_disabled" != "0" ] && echo "- libquicktime not found: only enabling dv avi support" + [ "$libdv_disabled" != 0 -a "$lqt_disabled" = "0" ] && echo "- libdv not found: mov dv may not have audio" echo "kino libmltkino$LIBSUF" >> ../producers.dat fi diff --git a/src/modules/kino/filehandler.cc b/src/modules/kino/filehandler.cc index 5c4de52..67412fd 100644 --- a/src/modules/kino/filehandler.cc +++ b/src/modules/kino/filehandler.cc @@ -38,6 +38,11 @@ using std::setfill; #include #include +// libdv header files +#ifdef HAVE_LIBDV +#include +#endif + #include "filehandler.h" #include "error.h" #include "riff.h" @@ -884,30 +889,24 @@ int QtHandler::GetFrame( uint8_t *data, int frameNum ) quicktime_set_video_position( fd, frameNum, 0 ); quicktime_read_frame( fd, data, 0 ); -#if 0 +#ifdef HAVE_LIBDV if ( quicktime_has_audio( fd ) ) { - AudioInfo info; - double samples; - if ( ! isFullyInitialized ) - { - cerr << ">>> using audio from separarate Quicktime audio track" << endl; AllocateAudioBuffers(); - } - info.channels = channels; - info.frequency = quicktime_sample_rate( fd, 0 ); - samples = info.frequency / quicktime_frame_rate( fd, 0 ); - info.samples = (int) samples; + int frequency = quicktime_sample_rate( fd, 0 ); + int samples = ( int )( frequency / quicktime_frame_rate( fd, 0 ) ); for ( int i = 0; i < channels; i++ ) { quicktime_set_audio_position( fd, ( int64_t )( frameNum * samples ), 0 ); quicktime_decode_audio( fd, audioChannelBuffer[ i ], NULL, (long) samples, i ); } - frame.EncodeAudio( info, audioChannelBuffer ); + dv_encoder_t *encoder = dv_encoder_new( 0, 0, 0 ); + encoder->samples_this_frame = samples; + dv_encode_full_audio( encoder, audioChannelBuffer, channels, frequency, data ); + dv_encoder_free( encoder ); } - frame.ExtractHeader(); #endif return 0; diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index 91925c9..62d33e7 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -57,9 +57,8 @@ struct consumer_sdl_s pthread_cond_t video_cond; int window_width; int window_height; - float aspect_ratio; - float display_aspect; - double last_frame_aspect; + int previous_width; + int previous_height; int width; int height; int playing; @@ -117,6 +116,9 @@ mlt_consumer consumer_sdl_init( char *arg ) mlt_service service = MLT_CONSUMER_SERVICE( parent ); this->properties = MLT_SERVICE_PROPERTIES( service ); + // Default display aspect ratio + double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" ); + // Set the default volume mlt_properties_set_double( this->properties, "volume", 1.0 ); @@ -138,15 +140,9 @@ mlt_consumer consumer_sdl_init( char *arg ) // Default audio buffer mlt_properties_set_int( this->properties, "audio_buffer", 512 ); - // Get sample aspect ratio - this->aspect_ratio = mlt_properties_get_double( this->properties, "aspect_ratio" ); - // Ensure we don't join on a non-running object this->joined = 1; - // Default display aspect ratio - this->display_aspect = 4.0 / 3.0; - // process actual param if ( arg == NULL || sscanf( arg, "%dx%d", &this->width, &this->height ) != 2 ) { @@ -155,7 +151,7 @@ mlt_consumer consumer_sdl_init( char *arg ) } // Default window size - this->window_width = ( float )this->height * this->display_aspect; + this->window_width = ( float )this->height * display_ratio; this->window_height = this->height; // Set the sdl flags @@ -203,6 +199,11 @@ int consumer_start( mlt_consumer parent ) mlt_properties_set_int( this->properties, "width", this->width ); mlt_properties_set_int( this->properties, "height", this->height ); } + else + { + this->width = mlt_properties_get_int( this->properties, "width" ); + this->height = mlt_properties_get_int( this->properties, "height" ); + } pthread_create( &this->thread, NULL, consumer_thread, this ); } @@ -461,8 +462,13 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) // Determine window's new display aspect ratio float this_aspect = ( float )this->window_width / this->window_height; + // Get the display aspect ratio + double display_ratio = mlt_properties_get_double( properties, "display_ratio" ); + // Determine frame's display aspect ratio float frame_aspect = mlt_frame_get_aspect_ratio( frame ) * width / height; + + // Store the width and height received this->width = width; this->height = height; @@ -470,42 +476,31 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) 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 ) ) ) + // 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->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; - } + 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 ) ) + else if ( (int)( this_aspect * 1000 ) == (int)( display_ratio * 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 ) + else if ( this->window_height * display_ratio > this->window_width ) { this->rect.w = this->window_width; - this->rect.h = this->window_width / this->display_aspect; + this->rect.h = this->window_width / display_ratio; } else { - this->rect.w = this->window_height * this->display_aspect; + this->rect.w = this->window_height * display_ratio; this->rect.h = this->window_height; } @@ -525,7 +520,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) SDL_SetClipRect( this->sdl_screen, &this->rect ); SDL_Flip( this->sdl_screen ); sdl_lock_display(); - this->sdl_overlay = SDL_CreateYUVOverlay( this->width, this->height, SDL_YUY2_OVERLAY, this->sdl_screen ); + this->sdl_overlay = SDL_CreateYUVOverlay( width, height, SDL_YUY2_OVERLAY, this->sdl_screen ); sdl_unlock_display(); } diff --git a/src/modules/sdl/consumer_sdl_preview.c b/src/modules/sdl/consumer_sdl_preview.c index 4e55bd6..eaaac2e 100644 --- a/src/modules/sdl/consumer_sdl_preview.c +++ b/src/modules/sdl/consumer_sdl_preview.c @@ -232,6 +232,10 @@ static void *consumer_thread( void *arg ) mlt_properties_set_int( still, "width", mlt_properties_get_int( properties, "width" ) ); mlt_properties_set_int( play, "height", mlt_properties_get_int( properties, "height" ) ); mlt_properties_set_int( still, "height", mlt_properties_get_int( properties, "height" ) ); + mlt_properties_set_double( play, "aspect_ratio", mlt_properties_get_double( properties, "aspect_ratio" ) ); + mlt_properties_set_double( still, "aspect_ratio", mlt_properties_get_double( properties, "aspect_ratio" ) ); + mlt_properties_set_double( play, "display_ratio", mlt_properties_get_double( properties, "display_ratio" ) ); + mlt_properties_set_double( still, "display_ratio", mlt_properties_get_double( properties, "display_ratio" ) ); mlt_properties_set_int( play, "progressive", progressive ); mlt_properties_set_int( still, "progressive", progressive ); diff --git a/src/modules/sdl/consumer_sdl_still.c b/src/modules/sdl/consumer_sdl_still.c index c76740a..c0848db 100644 --- a/src/modules/sdl/consumer_sdl_still.c +++ b/src/modules/sdl/consumer_sdl_still.c @@ -45,9 +45,6 @@ struct consumer_sdl_s int running; int window_width; int window_height; - float aspect_ratio; - float display_aspect; - double last_frame_aspect; int width; int height; int playing; @@ -86,13 +83,16 @@ mlt_consumer consumer_sdl_still_init( char *arg ) // Get the parent consumer object mlt_consumer parent = &this->parent; - // We have stuff to clean up, so override the close method - parent->close = consumer_close; - // get a handle on properties mlt_service service = MLT_CONSUMER_SERVICE( parent ); this->properties = MLT_SERVICE_PROPERTIES( service ); + // Get the default display ratio + double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" ); + + // We have stuff to clean up, so override the close method + parent->close = consumer_close; + // Default scaler (for now we'll use nearest) mlt_properties_set( this->properties, "rescale", "nearest" ); @@ -102,15 +102,9 @@ mlt_consumer consumer_sdl_still_init( char *arg ) // Default progressive true mlt_properties_set_int( this->properties, "progressive", 1 ); - // Get sample aspect ratio - this->aspect_ratio = mlt_properties_get_double( this->properties, "aspect_ratio" ); - // Ensure we don't join on a non-running object this->joined = 1; - // Default display aspect ratio - this->display_aspect = 4.0 / 3.0; - // process actual param if ( arg == NULL || sscanf( arg, "%dx%d", &this->width, &this->height ) != 2 ) { @@ -119,7 +113,7 @@ mlt_consumer consumer_sdl_still_init( char *arg ) } // Default window size - this->window_width = ( float )this->height * this->display_aspect; + this->window_width = ( float )this->height * display_ratio; this->window_height = this->height; // Set the sdl flags @@ -181,8 +175,6 @@ static int consumer_start( mlt_consumer parent ) mlt_properties_set_int( this->properties, "height", this->height ); } - //this->width = this->height * this->display_aspect; - pthread_create( &this->thread, NULL, consumer_thread, this ); } @@ -355,6 +347,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) int width = this->width; uint8_t *image = NULL; int changed = 0; + double display_ratio = mlt_properties_get_double( this->properties, "display_ratio" ); void ( *lock )( void ) = mlt_properties_get_data( properties, "app_lock", NULL ); void ( *unlock )( void ) = mlt_properties_get_data( properties, "app_unlock", NULL ); @@ -431,27 +424,15 @@ 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 - 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 ); - } + mlt_events_fire( properties, "consumer-frame-show", frame, NULL ); + mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 ); if ( image != NULL ) { char *rescale = mlt_properties_get( properties, "rescale" ); if ( rescale != NULL && strcmp( rescale, "none" ) ) { - float this_aspect = this->display_aspect / ( ( float )this->window_width / ( float )this->window_height ); + float this_aspect = display_ratio / ( ( float )this->window_width / ( float )this->window_height ); this->rect.w = this_aspect * this->window_width; this->rect.h = this->window_height; if ( this->rect.w > this->window_width ) -- 1.7.4.4