]> git.sesse.net Git - mlt/commitdiff
consumer_avformat.c, producer_avformat.c: add FFmpeg multi-thread support via
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 11 Feb 2008 08:37:12 +0000 (08:37 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 11 Feb 2008 08:37:12 +0000 (08:37 +0000)
"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
src/modules/avformat/producer_avformat.c

index 5a1ab27201c5faf0709a8cdee2eae8f2e7f9f9ca..60d62ff9f24f6d630af89735a0ebcbf1942f0653 100644 (file)
@@ -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" );
index dda7299ec8f7208ff8b5ab27ea35e52d9feef881..22331591de818308de1df58d409c55ad1584bde7 100644 (file)
@@ -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 );