Author Topic: libx264 ratecontrol Documentation  (Read 2026 times)

Offline sluburob

  • Member
  • Posts: 6
    • View Profile
libx264 ratecontrol Documentation
« on: April 03, 2012, 05:59:03 AM »
Hi There,
i've got a problem with the ratecontrol of the x264 codec.

My application is for streaming purposes, so i need a capped bitrate.
at the moment the application works fine with bitrates between 1 and 200 Mbit/s what is fine on my local network but even with a 100Mbit network connection there are problems.

i know how to control quality, and it works fine, but i have to control bitrate so i tried:

Code: [Select]
param.rc.i_bitrate = bitrate;
param.rc.i_rc_method = X264_RC_CQP;
param.rc.i_vbv_max_bitrate = bitrate;
param.rc.i_vbv_buffer_size = bitrate / framerate;
param.rc.f_vbv_buffer_init = 1.0;
param.rc.f_qcompress = 0.01;

but any change of bitrate does no effect.

Is there any documentation out there for such purposes?
what are the differences of the three rate control modes:
X264_RC_CQP
X264_RC_CRF
X264_RC_ABR
?
is there any better description of x264_param_t.rc than in the header file?
i played with the parameters, but there was no luck to get control.

my goal is to get a variable bitrate not exceeding x bytes per frame.
would be great to get a soloution.

Greetz from Blackforest.

Offline skittle

  • Member
  • Posts: 32
    • View Profile
Re: libx264 ratecontrol Documentation
« Reply #1 on: April 03, 2012, 07:46:00 AM »
Obviously! settings CQ and specify bitrate makes no sense!

Read this for some insight:
http://git.videolan.org/?p=x264.git;a=blob_plain;f=doc/ratecontrol.txt;hb=HEAD
also
http://mewiki.project357.com/wiki/X264_Settings#Ratecontrol

For your purpose: 1 or 2 pass ABR with vbv stuffs.
« Last Edit: April 03, 2012, 07:47:38 AM by skittle »

Offline sluburob

  • Member
  • Posts: 6
    • View Profile
Re: libx264 ratecontrol Documentation
« Reply #2 on: April 03, 2012, 01:50:31 PM »
thanks for your answer,
the first link was great. didnt' read that before.

so ok,
CQP is for a constant quality seting over qp, works fine, but not usable here.
ABR is average bitrate?

so i have to set:
Code: [Select]
param.rc.i_rc_method = X264_RC_ABR;
param.rc.i_vbv_max_bitrate = bitrate;
param.rc.i_vbv_buffer_size = bitrate / framerate;
but when i do this, i simply get a stream of near 25Mbit/s (1080@25p).
changing bitrate to other values, tried everything between 2000 and 200000 with no effect.

am i right with param.rc.f_qcompress = 0.01? is this the tolerance for vbv_buffer size?


Offline sluburob

  • Member
  • Posts: 6
    • View Profile
Re: libx264 ratecontrol Documentation
« Reply #3 on: April 04, 2012, 03:19:43 AM »
So tried some parameters and got results.

Code: [Select]

int fps = 25;
int bitrate = 6000

param.i_fps_num =  1;
param.i_fps_den = fps;

param.rc.i_rc_method = X264_RC_ABR;
param.rc.i_bitrate = bitrate / 1000;
param.rc.i_vbv_buffer_size = bitrate / fps;
param.rc.f_qcompress =0.01;

with this parameters i get average 6Mbit/s.
but meassuring the Bitrate frame by frame, i get values around 20MBit/s.

so this works truely average. there is no limit.
lowering bitrate to 2000 most frames are coded with 1,7Mbit/s and some are codede bit higher than 2.

so the ratecontrol works fine but only for average bitrate.
when i raise param.rc.i_bitrate without touching param.rc.i_vbv_buffer_size then param.rc.i_vbv_buffer_size is the limit for the AVERAGE Bitrate. but not for the Bitrate per Frame. lowering param.rc.i_bitrate results in lower AVERAGE bitrate.

param.rc.f_qcompress =0.01; and  param.rc.f_rate_tolerance = 0.01; seems to do nothing. commenting them out follows with same results.

in he header f_rate_tolerance; is for general?
and f_qcompress; is for two pass only?

is there a posibility for real clipping one frame size?


Offline nm

  • Member
  • Posts: 358
    • View Profile
Re: libx264 ratecontrol Documentation
« Reply #4 on: April 04, 2012, 08:02:06 AM »
You're not setting vbv-maxrate?

Have you played with this: http://handbrake.dynaflashtech.net/cgi-bin/vbv_calculator.cgi