From 52ba2d01d33ce1b489f06444560524e5fae250b6 Mon Sep 17 00:00:00 2001 From: ddennedy Date: Mon, 11 Feb 2008 08:37:12 +0000 Subject: [PATCH] consumer_avformat.c, producer_avformat.c: add FFmpeg multi-thread support via "threads" property or MLT_AVFORMAT_THREADS environment variable git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1066 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/modules/avformat/consumer_avformat.c | 20 +++++++++++++++++++- src/modules/avformat/producer_avformat.c | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletions(-) diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 5a1ab27..60d62ff 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -326,6 +326,10 @@ static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int c if ( st != NULL ) { AVCodecContext *c = st->codec; + int thread_count = mlt_properties_get_int( properties, "threads" ); + if ( thread_count == 0 && getenv( "MLT_AVFORMAT_THREADS" ) ) + thread_count = atoi( getenv( "MLT_AVFORMAT_THREADS" ) ); + c->codec_id = codec_id; c->codec_type = CODEC_TYPE_AUDIO; @@ -347,6 +351,11 @@ static AVStream *add_audio_stream( mlt_consumer this, AVFormatContext *oc, int c tag = arg[ 0 ] + ( arg[ 1 ] << 8 ) + ( arg[ 2 ] << 16 ) + ( arg[ 3 ] << 24 ); c->codec_tag = tag; } + if ( thread_count > 1 ) + { + avcodec_thread_init( c, thread_count ); + c->thread_count = thread_count; + } } else { @@ -427,6 +436,10 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c char *pix_fmt = mlt_properties_get( properties, "pix_fmt" ); double ar = mlt_properties_get_double( properties, "display_ratio" ); AVCodecContext *c = st->codec; + int thread_count = mlt_properties_get_int( properties, "threads" ); + if ( thread_count == 0 && getenv( "MLT_AVFORMAT_THREADS" ) ) + thread_count = atoi( getenv( "MLT_AVFORMAT_THREADS" ) ); + c->codec_id = codec_id; c->codec_type = CODEC_TYPE_VIDEO; @@ -526,7 +539,12 @@ static AVStream *add_video_stream( mlt_consumer this, AVFormatContext *oc, int c if ( mlt_properties_get_int( properties, "ilme" ) ) c->flags |= CODEC_FLAG_INTERLACED_ME; } - } + if ( thread_count > 1 ) + { + avcodec_thread_init( c, thread_count ); + c->thread_count = thread_count; + } + } else { fprintf( stderr, "Could not allocate a stream for video\n" ); diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c index dda7299..2233159 100644 --- a/src/modules/avformat/producer_avformat.c +++ b/src/modules/avformat/producer_avformat.c @@ -693,6 +693,16 @@ static void producer_set_up_video( mlt_producer this, mlt_frame frame ) // Initialise the codec if necessary if ( codec == NULL ) { + // Initialise multi-threading + int thread_count = mlt_properties_get_int( properties, "threads" ); + if ( thread_count == 0 && getenv( "MLT_AVFORMAT_THREADS" ) ) + thread_count = atoi( getenv( "MLT_AVFORMAT_THREADS" ) ); + if ( thread_count > 1 ) + { + avcodec_thread_init( codec_context, thread_count ); + codec_context->thread_count = thread_count; + } + // Find the codec codec = avcodec_find_decoder( codec_context->codec_id ); @@ -1009,6 +1019,16 @@ static void producer_set_up_audio( mlt_producer this, mlt_frame frame ) // Initialise the codec if necessary if ( codec == NULL ) { + // Initialise multi-threading + int thread_count = mlt_properties_get_int( properties, "threads" ); + if ( thread_count == 0 && getenv( "MLT_AVFORMAT_THREADS" ) ) + thread_count = atoi( getenv( "MLT_AVFORMAT_THREADS" ) ); + if ( thread_count > 1 ) + { + avcodec_thread_init( codec_context, thread_count ); + codec_context->thread_count = thread_count; + } + // Find the codec codec = avcodec_find_decoder( codec_context->codec_id ); -- 1.7.4.4