From: Steinar H. Gunderson Date: Tue, 19 Apr 2016 22:37:55 +0000 (+0200) Subject: Get rid of redundant speedcontrol variable fps, and clarify the units of some variables. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=462f09a816cbb24b6de34f9cc591149288dcf281;p=x264 Get rid of redundant speedcontrol variable fps, and clarify the units of some variables. Also fix a bug where the i_buffer_size parameter to x264_speedcontrol_sync() would get ignored, and not update the dependent parameters properly. --- diff --git a/AUTHORS b/AUTHORS index d14deb88..d5d8a142 100644 --- a/AUTHORS +++ b/AUTHORS @@ -97,3 +97,6 @@ N: Radek Czyz E: radoslaw AT syskin DOT cjb DOT net D: Cached motion compensation +N: Google Inc +E: opensource AT google DOT com +D: speedcontrol bug fixes diff --git a/encoder/speed.c b/encoder/speed.c index faade8e6..df8e2d8a 100644 --- a/encoder/speed.c +++ b/encoder/speed.c @@ -9,10 +9,10 @@ struct x264_speedcontrol_t // all times are in usec int64_t timestamp; // when was speedcontrol last invoked int64_t cpu_time; // time spent encoding the previous frame - int64_t buffer_size; // assumed application-side buffer of frames to be streamed, + int64_t buffer_size; // assumed application-side buffer of frames to be streamed (measured in microseconds), int64_t buffer_fill; // where full = we don't have to hurry int64_t compensation_period; // how quickly we try to return to the target buffer fullness - float fps, spf; + float uspf; // microseconds per frame int preset; // which setting was used in the previous frame int prev_frame; float cplx_num; // rolling average of estimated spf for preset #0 @@ -39,12 +39,12 @@ void x264_speedcontrol_new( x264_t *h ) if( h->param.sc.f_speed <= 0 ) h->param.sc.f_speed = 1; - sc->fps = h->param.i_fps_num / h->param.i_fps_den; - sc->spf = 1e6 / sc->fps; + float fps = h->param.i_fps_num / h->param.i_fps_den; + sc->uspf = 1e6 / fps; h->param.sc.i_buffer_size = X264_MAX( 3, h->param.sc.i_buffer_size ); - sc->buffer_size = h->param.sc.i_buffer_size * 1e6 / sc->fps; + sc->buffer_size = h->param.sc.i_buffer_size * sc->uspf; sc->buffer_fill = sc->buffer_size * h->param.sc.f_buffer_init; - sc->buffer_fill = x264_clip3( sc->buffer_fill, sc->spf, sc->buffer_size ); + sc->buffer_fill = x264_clip3( sc->buffer_fill, sc->uspf, sc->buffer_size ); sc->compensation_period = sc->buffer_size/4; sc->timestamp = x264_mdate(); sc->preset = -1; @@ -170,7 +170,7 @@ void x264_speedcontrol_frame( x264_t *h ) delta_f = h->i_frame - sc->prev_frame; delta_t = t - sc->timestamp; - delta_buffer = delta_f * sc->spf / h->param.sc.f_speed - delta_t; + delta_buffer = delta_f * sc->uspf / h->param.sc.f_speed - delta_t; if( !sc->buffer_complete ) sc->buffer_fill += delta_buffer; sc->prev_frame = h->i_frame; @@ -216,7 +216,7 @@ void x264_speedcontrol_frame( x264_t *h ) { // pick the preset that should return the buffer to 3/4-full within a time // specified by compensation_period - float target = sc->spf / h->param.sc.f_speed + float target = sc->uspf / h->param.sc.f_speed * (sc->buffer_fill + sc->compensation_period) / (sc->buffer_size*3/4 + sc->compensation_period); float cplx = sc->cplx_num / sc->cplx_den; @@ -262,8 +262,10 @@ void x264_speedcontrol_sync( x264_t *h, float f_buffer_fill, int i_buffer_size, if( !h->param.sc.i_buffer_size ) return; if( i_buffer_size ) - h->param.sc.i_buffer_size = X264_MAX( 3, h->param.sc.i_buffer_size ); - sc->buffer_size = h->param.sc.i_buffer_size * 1e6 / sc->fps; + h->param.sc.i_buffer_size = X264_MAX( 3, i_buffer_size ); + sc->buffer_size = h->param.sc.i_buffer_size * sc->uspf; + sc->cplx_decay = 1 - 1./h->param.sc.i_buffer_size; + sc->compensation_period = sc->buffer_size/4; sc->buffer_fill = sc->buffer_size * f_buffer_fill; sc->buffer_complete = !!buffer_complete; }