From 9608cc5c1fdc93a41d1a62c2ebdbde3e21f8f3df Mon Sep 17 00:00:00 2001 From: Alexander Prikhodko Date: Wed, 7 Apr 2010 12:10:31 +0300 Subject: [PATCH] Utilize internal threading in lavf/ffms --- input/ffms.c | 2 +- input/input.h | 1 + input/lavf.c | 6 ++++++ x264.c | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletions(-) diff --git a/input/ffms.c b/input/ffms.c index a54ae49..6992678 100644 --- a/input/ffms.c +++ b/input/ffms.c @@ -102,7 +102,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c return -1; } - h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, index, 1, seekmode, &e ); + h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, index, opt->demuxer_threads, seekmode, &e ); if( !h->video_source ) { fprintf( stderr, "ffms [error]: could not create video source\n" ); diff --git a/input/input.h b/input/input.h index 7be6fcf..45cfe0f 100644 --- a/input/input.h +++ b/input/input.h @@ -32,6 +32,7 @@ typedef struct char *resolution; /* resolution string parsed by raw yuv input */ char *timebase; int seek; + int demuxer_threads; } cli_input_opt_t; /* properties of the source given by the demuxer */ diff --git a/input/lavf.c b/input/lavf.c index 7daf5f7..15d9e72 100644 --- a/input/lavf.c +++ b/input/lavf.c @@ -207,6 +207,10 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c fprintf( stderr, "lavf [warning]: converting from %s to YV12\n", avcodec_get_pix_fmt_name( h->cur_pix_fmt ) ); + if( opt->demuxer_threads > 1 ) + if( avcodec_thread_init( c, opt->demuxer_threads ) ) + c->thread_count = 1; + if( avcodec_open( c, avcodec_find_decoder( c->codec_id ) ) ) { fprintf( stderr, "lavf [error]: could not find decoder for video stream\n" ); diff --git a/x264.c b/x264.c index 08fd313..ee4256f 100644 --- a/x264.c +++ b/x264.c @@ -560,6 +560,7 @@ static void Help( x264_param_t *defaults, int longhelp ) H1( " --psnr Enable PSNR computation\n" ); H1( " --ssim Enable SSIM computation\n" ); H1( " --threads Force a specific number of threads\n" ); + H1( " --demuxer-threads Force a specific number of threads for demuxer (lavf, ffms)\n" ); H2( " --sliced-threads Low-latency but lower-efficiency threading\n" ); H2( " --thread-input Run Avisynth in its own thread\n" ); H2( " --sync-lookahead Number of buffer frames for threaded lookahead\n" ); @@ -603,6 +604,7 @@ static void Help( x264_param_t *defaults, int longhelp ) #define OPT_TCFILE_OUT 275 #define OPT_TIMEBASE 276 #define OPT_PULLDOWN 277 +#define OPT_DEMUXER_THREADS 278 static char short_options[] = "8A:B:b:f:hI:i:m:o:p:q:r:t:Vvw"; static struct option long_options[] = @@ -702,6 +704,7 @@ static struct option long_options[] = { "zones", required_argument, NULL, 0 }, { "qpfile", required_argument, NULL, OPT_QPFILE }, { "threads", required_argument, NULL, 0 }, + { "demuxer-threads", required_argument, NULL, OPT_DEMUXER_THREADS }, { "sliced-threads", no_argument, NULL, 0 }, { "no-sliced-threads", no_argument, NULL, 0 }, { "slice-max-size", required_argument, NULL, 0 }, @@ -906,6 +909,7 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) x264_param_t defaults; char *profile = NULL; int b_thread_input = 0; + int i_demuxer_threads = 1; int b_turbo = 1; int b_user_ref = 0; int b_user_fps = 0; @@ -1014,6 +1018,9 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) case OPT_THREAD_INPUT: b_thread_input = 1; break; + case OPT_DEMUXER_THREADS: + i_demuxer_threads = atoi( optarg ); + break; case OPT_QUIET: param->i_log_level = X264_LOG_NONE; break; @@ -1124,6 +1131,7 @@ generic_option: input_filename = argv[optind++]; input_opt.resolution = optind < argc ? argv[optind++] : NULL; + input_opt.demuxer_threads = X264_MAX( i_demuxer_threads, 1 ); video_info_t info = {0}; char demuxername[5]; -- 1.7.0.2.msysgit.0