]> git.sesse.net Git - x264/commitdiff
Merge speedcontrol.
authorKieran Kunhya <kieran@kunhya.com>
Mon, 21 Feb 2011 02:57:27 +0000 (02:57 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 23 Apr 2016 10:05:45 +0000 (12:05 +0200)
Makefile
common/common.c
common/common.h
encoder/encoder.c
encoder/ratecontrol.h
x264.c
x264.h

index d0b16338e5c25ca99d70071304c8465e4d9fa4e1..ffae9834b59ae4bcc6790b4e2569d3f496c58e91 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
        common/mvpred.c common/bitstream.c \
        encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
        encoder/set.c encoder/macroblock.c encoder/cabac.c \
+       encoder/speed.c \
        encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
 
 SRCCLI = x264.c input/input.c input/timecode.c input/raw.c input/y4m.c \
index 607aefdd160b9dc22eee9c1d13696bb54832a37f..645b1d31a16234e3303d39ea1c630cb405d10669 100644 (file)
@@ -122,6 +122,11 @@ void x264_param_default( x264_param_t *param )
     param->rc.i_zones = 0;
     param->rc.b_mb_tree = 1;
 
+    // speedcontrol
+    param->sc.f_speed = 0;
+    param->sc.i_buffer_size = 30;
+    param->sc.f_buffer_init = 0.75;
+
     /* Log */
     param->pf_log = x264_log_default;
     param->p_log_private = NULL;
@@ -1016,6 +1021,14 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value )
         p->rc.f_complexity_blur = atof(value);
     OPT("zones")
         p->rc.psz_zones = strdup(value);
+    OPT("speed")
+        p->sc.f_speed = atof(value);
+    OPT("speed-bufsize")
+        p->sc.i_buffer_size = atoi(value);
+    OPT("speed-init")
+        p->sc.f_buffer_init = atof(value);
+    OPT("speed-alt-timer")
+        p->sc.b_alt_timer = atobool(value);
     OPT("crop-rect")
         b_error |= sscanf( value, "%u,%u,%u,%u", &p->crop_rect.i_left, &p->crop_rect.i_top,
                                                  &p->crop_rect.i_right, &p->crop_rect.i_bottom ) != 4;
@@ -1333,6 +1346,9 @@ char *x264_param2string( x264_param_t *p, int b_res )
 
     if( p->b_opencl )
         s += sprintf( s, "opencl=%d ", p->b_opencl );
+
+    // FIXME speedcontrol stuff
+
     s += sprintf( s, "cabac=%d", p->b_cabac );
     s += sprintf( s, " ref=%d", p->i_frame_reference );
     s += sprintf( s, " deblock=%d:%d:%d", p->b_deblocking_filter,
index 3a74c9e7bb60d09208ff46c9b2603f0aee804342..9cb045b6c9430faa6a964314e815ecd14613a97a 100644 (file)
@@ -447,6 +447,7 @@ typedef struct x264_lookahead_t
 } x264_lookahead_t;
 
 typedef struct x264_ratecontrol_t   x264_ratecontrol_t;
+typedef struct x264_speedcontrol_t  x264_speedcontrol_t;
 
 typedef struct x264_left_table_t
 {
@@ -891,6 +892,7 @@ struct x264_t
 
     /* rate control encoding only */
     x264_ratecontrol_t *rc;
+    x264_speedcontrol_t *sc;
 
     /* stats */
     struct
index 66f83575b45c7c2cfe7b37ce0eed4947343660b2..a5bd0d9ff1a45d9bca5b68edcd9fc961325c68e0 100644 (file)
@@ -1249,6 +1249,8 @@ static int x264_validate_parameters( x264_t *h, int b_open )
         h->param.rc.f_qblur = 0;
     if( h->param.rc.f_complexity_blur < 0 )
         h->param.rc.f_complexity_blur = 0;
+    if( h->param.sc.i_buffer_size < 0 || h->param.sc.f_speed <= 0 )
+        h->param.sc.i_buffer_size = 0;
 
     h->param.i_sps_id &= 31;
 
@@ -1550,6 +1552,10 @@ x264_t *x264_encoder_open( x264_param_t *param )
     mbcmp_init( h );
     chroma_dsp_init( h );
 
+    if( h->param.sc.i_buffer_size )
+        x264_speedcontrol_new( h );
+
+
     p = buf + sprintf( buf, "using cpu capabilities:" );
     for( int i = 0; x264_cpu_names[i].flags; i++ )
     {
@@ -3685,6 +3691,10 @@ int     x264_encoder_encode( x264_t *h,
         overhead += h->out.nal[h->out.i_nal-1].i_payload + h->out.nal[h->out.i_nal-1].i_padding + SEI_OVERHEAD;
     }
 
+    /* Init the speed control */
+    if( h->param.sc.i_buffer_size )
+        x264_speedcontrol_frame( h );
+
     /* Init the rate control */
     /* FIXME: Include slice header bit cost. */
     x264_ratecontrol_start( h, h->fenc->i_qpplus1, overhead*8 );
@@ -3875,6 +3885,9 @@ static int x264_encoder_frame_end( x264_t *h, x264_t *thread_current,
 
     x264_noise_reduction_update( h );
 
+    if( h->param.sc.i_buffer_size )
+        x264_speedcontrol_frame_end( h );
+
     /* ---------------------- Compute/Print statistics --------------------- */
     x264_thread_sync_stat( h, h->thread[0] );
 
@@ -4327,6 +4340,7 @@ void    x264_encoder_close  ( x264_t *h )
 
     /* rc */
     x264_ratecontrol_delete( h );
+    x264_speedcontrol_delete( h );
 
     /* param */
     if( h->param.rc.psz_stat_out )
index 490a1edb591584e147ff0cb324f16c89261f79bc..ca10bf3116e8d913c03b52a474db9e11cc9c01ac 100644 (file)
@@ -64,5 +64,12 @@ int x264_weighted_reference_duplicate( x264_t *h, int i_ref, const x264_weight_t
 void x264_threads_distribute_ratecontrol( x264_t *h );
 void x264_threads_merge_ratecontrol( x264_t *h );
 void x264_hrd_fullness( x264_t *h );
+
+// speedcontrol
+void x264_speedcontrol_new( x264_t *h );
+void x264_speedcontrol_delete( x264_t *h );
+void x264_speedcontrol_frame( x264_t *h );
+void x264_speedcontrol_frame_end( x264_t *h );
+
 #endif
 
diff --git a/x264.c b/x264.c
index b95207192b76d891fa114b37deec3db617e425b2..414252c9b890badb4ce1cac440fc6c296f58d81c 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -761,6 +761,14 @@ static void help( x264_param_t *defaults, int longhelp )
         "                                  K=<I or i> depending on open-gop setting\n"
         "                              QPs are restricted by qpmin/qpmax.\n" );
     H1( "\n" );
+
+    H1( "Speedcontrol:\n" );
+    H1( "\n" );
+    H1( "      --speed <float>         Automatically adjust other options to achieve this\n" );
+    H1( "                                  fraction of realtime.\n" );
+    H1( "      --speed-bufsize <int>   Averaging period for speed. (in frames) [%d]\n", defaults->sc.i_buffer_size );
+    H1( "\n" );
+
     H1( "Analysis:\n" );
     H1( "\n" );
     H1( "  -A, --partitions <string>   Partitions to consider [\"p8x8,b8x8,i8x8,i4x4\"]\n"
@@ -1079,6 +1087,8 @@ static struct option long_options[] =
     { "cplxblur",    required_argument, NULL, 0 },
     { "zones",       required_argument, NULL, 0 },
     { "qpfile",      required_argument, NULL, OPT_QPFILE },
+    { "speed",   required_argument, NULL, 0 },
+    { "speed-bufsize", required_argument, NULL, 0 },
     { "threads",     required_argument, NULL, 0 },
     { "lookahead-threads", required_argument, NULL, 0 },
     { "sliced-threads",    no_argument, NULL, 0 },
diff --git a/x264.h b/x264.h
index 5581ab9b9971ea8eb9a1b944b0b360280bb998d0..fd5c0f7a9372317a31e141f4d41f57cbaf7759b8 100644 (file)
--- a/x264.h
+++ b/x264.h
@@ -456,6 +456,15 @@ typedef struct x264_param_t
     /* frame packing arrangement flag */
     int i_frame_packing;
 
+    /* Speed control parameters */
+    struct
+    {
+        float       f_speed;        /* ratio from realtime */
+        int         i_buffer_size;  /* number of frames */
+        float       f_buffer_init;  /* fraction of size */
+        int         b_alt_timer;    /* use a different method of measuring encode time FIXME */
+    } sc;
+
     /* Muxing parameters */
     int b_aud;                  /* generate access unit delimiters */
     int b_repeat_headers;       /* put SPS/PPS before each keyframe */
@@ -952,6 +961,10 @@ void    x264_encoder_intra_refresh( x264_t * );
  *      Returns 0 on success, negative on failure. */
 int x264_encoder_invalidate_reference( x264_t *, int64_t pts );
 
+/* x264_speedcontrol_sync:
+ *      override speedcontrol's internal clock */
+void    x264_speedcontrol_sync( x264_t *, float f_buffer_fill, int i_buffer_size );
+
 #ifdef __cplusplus
 }
 #endif