diff -uNrp a/common/common.c b/common/common.c --- a/common/common.c 2008-09-24 23:45:02 +0300 +++ b/common/common.c 2008-09-25 17:27:53 +0300 @@ -44,6 +44,8 @@ void x264_param_default( x264_param_t /* CPU autodetect */ param->cpu = x264_cpu_detect(); param->i_threads = 1; + param->i_threads_boost = 0; + param->i_thread_input_boost = 0; param->b_deterministic = 1; /* Video properties */ @@ -267,6 +269,14 @@ int x264_param_parse( x264_param_t *p, c else p->i_threads = atoi(value); } + OPT("threads-boost") + { + p->i_threads_boost = atoi(value); + } + OPT("thread-input-boost") + { + p->i_thread_input_boost = atoi(value); + } OPT2("deterministic", "n-deterministic") p->b_deterministic = atobool(value); OPT2("level", "level-idc") diff -uNrp a/encoder/encoder.c b/encoder/encoder.c --- a/encoder/encoder.c 2008-09-24 23:45:03 +0300 +++ b/encoder/encoder.c 2008-09-25 17:36:48 +0300 @@ -357,6 +357,8 @@ static int x264_validate_parameters( x26 return -1; } + h->param.i_threads_boost = x264_clip3( h->param.i_threads_boost, -2, 2 ); + h->param.i_thread_input_boost = x264_clip3( h->param.i_thread_input_boost, -2, 2 ); if( h->param.i_threads == 0 ) h->param.i_threads = x264_cpu_num_processors() * 3/2; h->param.i_threads = x264_clip3( h->param.i_threads, 1, X264_THREAD_MAX ); @@ -1558,7 +1560,14 @@ do_encode: /* Write frame */ if( h->param.i_threads > 1 ) { - x264_pthread_create( &h->thread_handle, NULL, (void*)x264_slices_write, h ); + pthread_attr_t t_attr; + struct sched_param prio; + prio.sched_priority = h->param.i_threads_boost; + + pthread_attr_init(&t_attr); + pthread_attr_setschedparam(&t_attr, &prio); + + x264_pthread_create( &h->thread_handle, &t_attr, (void*)x264_slices_write, h ); h->b_thread_active = 1; } else diff -uNrp a/muxers.c b/muxers.c --- a/muxers.c 2008-09-24 23:45:03 +0300 +++ b/muxers.c 2008-09-25 17:31:50 +0300 @@ -429,6 +429,7 @@ typedef struct { int frame_total; int in_progress; struct thread_input_arg_t *next_args; + int priority; } thread_input_t; typedef struct thread_input_arg_t { @@ -442,6 +443,7 @@ int open_file_thread( char *psz_filename { thread_input_t *h = malloc(sizeof(thread_input_t)); x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height ); + h->priority = p_param->i_thread_input_boost; h->p_read_frame = p_read_frame; h->p_close_infile = p_close_infile; h->p_handle = *p_handle; @@ -494,7 +496,14 @@ int read_frame_thread( x264_picture_t *p h->next_frame = h->next_args->i_frame = i_frame+1; h->next_args->pic = &h->pic; - x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args ); + + pthread_attr_t t_attr; + struct sched_param prio; + prio.sched_priority = h->priority; + pthread_attr_init(&t_attr); + pthread_attr_setschedparam(&t_attr, &prio); + + x264_pthread_create( &h->tid, &t_attr, (void*)read_frame_thread_int, h->next_args ); h->in_progress = 1; } else diff -uNrp a/x264.c b/x264.c --- a/x264.c 2008-09-24 23:45:03 +0300 +++ b/x264.c 2008-09-25 17:35:27 +0300 @@ -326,7 +326,16 @@ static void Help( x264_param_t *defaults H0( " --no-psnr Disable PSNR computation\n" ); H0( " --no-ssim Disable SSIM computation\n" ); H0( " --threads Parallel encoding\n" ); + H1( " --threads-boost Tune priority for encoding threads [%d]\n" + " -2: LOWEST\n" + " -1: BELOW_NORMAL\n" + " 0: NORMAL\n" + " 1: ABOVE_NORMAL\n" + " 2: HIGHEST\n", + defaults->i_threads_boost ); H0( " --thread-input Run Avisynth in its own thread\n" ); + H1( " --thread-input-boost Tune priority for input thread (Values as in 'threads-boost') [%d]\n", + defaults->i_thread_input_boost ); H1( " --non-deterministic Slightly improve quality of SMP, at the cost of repeatability\n" ); H1( " --asm Override CPU detection\n" ); H1( " --no-asm Disable all CPU optimizations\n" ); @@ -453,6 +462,8 @@ static int Parse( int argc, char **argv { "zones", required_argument, NULL, 0 }, { "qpfile", required_argument, NULL, OPT_QPFILE }, { "threads", required_argument, NULL, 0 }, + { "threads-boost", required_argument, NULL, 0 }, + { "thread-input-boost", required_argument, NULL, 0 }, { "thread-input", no_argument, NULL, OPT_THREAD_INPUT }, { "non-deterministic", no_argument, NULL, 0 }, { "no-psnr", no_argument, NULL, 0 }, diff -uNrp a/x264.h b/x264.h --- a/x264.h 2008-09-24 23:45:03 +0300 +++ b/x264.h 2008-09-25 17:28:21 +0300 @@ -151,6 +151,8 @@ typedef struct x264_param_t /* CPU flags */ unsigned int cpu; int i_threads; /* encode multiple frames in parallel */ + int i_threads_boost; /* priority of encoding threads */ + int i_thread_input_boost; /* priority of input thread */ int b_deterministic; /* whether to allow non-deterministic optimizations when threaded */ /* Video Properties */