From 7067858fa9cf333f072778d30d31947ca095a308 Mon Sep 17 00:00:00 2001 From: ddennedy Date: Mon, 27 Oct 2008 05:28:01 +0000 Subject: [PATCH] producer_avformat.c: optimize slightly the stream index bugfix and update the video informational properties on the producer when the video index changes. git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1207 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/modules/avformat/producer_avformat.c | 21 +++++++++++++++++++-- 1 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index a8d5480..bf3654f 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -705,10 +705,24 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame ) if ( context && index >= (int) context->nb_streams ) { for ( index = context->nb_streams - 1; index >= 0 && context->streams[ index ]->codec->codec_type != CODEC_TYPE_VIDEO; --index ); + mlt_properties_set_int( properties, "video_index", index ); } if ( context && index > -1 && context->streams[ index ]->codec->codec_type != CODEC_TYPE_VIDEO ) + { index = -1; - mlt_properties_set_int( properties, "video_index", index ); + mlt_properties_set_int( properties, "video_index", index ); + } + + // Update the video properties if the index changed + if ( index > -1 && index != mlt_properties_get_int( properties, "_video_index" ) ) + { + // Fetch the width, height and aspect ratio + AVCodecContext *codec_context = context->streams[ index ]->codec; + mlt_properties_set_int( properties, "_video_index", index ); + mlt_properties_set_int( properties, "width", codec_context->width ); + mlt_properties_set_int( properties, "height", codec_context->height ); + mlt_properties_set_double( properties, "aspect_ratio", av_q2d( codec_context->sample_aspect_ratio ) ); + } // Get the frame properties mlt_properties frame_properties = MLT_FRAME_PROPERTIES( frame ); @@ -1076,10 +1090,13 @@ static void producer_set_up_audio( mlt_producer this, mlt_frame frame ) if ( context && index >= (int) context->nb_streams ) { for ( index = context->nb_streams - 1; index >= 0 && context->streams[ index ]->codec->codec_type != CODEC_TYPE_AUDIO; --index ); + mlt_properties_set_int( properties, "audio_index", index ); } if ( context && index > -1 && context->streams[ index ]->codec->codec_type != CODEC_TYPE_AUDIO ) + { index = -1; - mlt_properties_set_int( properties, "audio_index", index ); + mlt_properties_set_int( properties, "audio_index", index ); + } // Deal with audio context if ( context != NULL && index > -1 ) -- 1.7.4.4