[x264-devel] X264 dynamic rate control
BugMaster
BugMaster at narod.ru
Thu Nov 5 18:34:54 CET 2015
On Thu, 05 Nov 2015 11:07:26 +0200, Ralf Globisch wrote:
> Hi,
> I'm experimenting with x264 rate control, specifically with
> changing the target rate to adapt to network congestion.
> From what I've read
> (http://forum.doom9.org/archive/index.php/t-153168.html), this
> should be possible by doing the following:
> On initialisation:
> x264_param_t p;
> x264_param_default_preset(&p, "ultrafast", "zerolatency");
> p.i_threads = 1;
> p.i_width = _width;
> p.i_height = _height;
> p.i_fps_num = _fps;
> p.i_fps_den = 1;
> p.i_log_level = X264_LOG_DEBUG;
> p.rc.i_rc_method = X264_RC_ABR ;
> p.rc.i_bitrate = bitrate_kbps;
> p.i_nal_hrd = X264_NAL_HRD_CBR;
> p.rc.i_vbv_buffer_size = bitrate_kbps;
> cbr_factor = 0.8;
> p.rc.i_vbv_max_bitrate = bitrate_kbps * cbr_factor;
> encoder = x264_encoder_open(&p)
> And then to change rate at some time later:
> x264_param_t p;
> x264_encoder_parameters( encoder, &p );
> p.rc.i_bitrate = new_bitrate_kbps;
> p.rc.i_vbv_buffer_size = new_bitrate_kbps;
> p.rc.i_vbv_max_bitrate = new_bitrate_kbps *cbr_factor;
> int res = x264_encoder_reconfig(encoder, &p);
> x264_encoder_reconfig doesn't return an error, but there seems to be no effect on bitrate.
> Using a test sequence of 300 frames, if the starting bitrate is 100
> kbps, and I switch to 200 kbps at frame 150,
> there is no noticeable adjustment in encoded frame size, and x264
> outputs close to the starting bitrate when it finishes.
> Is there something (obviously) wrong in the configuration?
> Thanks for any input.
> Ralf
Hi.
Ratecontrol reconfiguration is not possible when using NAL HRD. You
should see warning:
"VBV parameters cannot be changed when NAL HRD is in use\n"
http://git.videolan.org/gitweb.cgi?p=x264.git;a=blob;f=encoder/ratecontrol.c;hb=HEAD#l706
Why do you use i_nal_hrd? It is not like you encoding for bluray that
you need it. Also why do you use X264_NAL_HRD_CBR and not
X264_NAL_HRD_VBR which imho more effective for network bandwidth
utilization? If you really want CBR than you can use:
p.rc.b_filler = 1;
instead of:
p.i_nal_hrd = X264_NAL_HRD_CBR;
More information about the x264-devel
mailing list