[x264-devel] rate control

Jason Garrett-Glaser darkshikari at gmail.com
Tue Sep 14 21:22:17 CEST 2010


On Tue, Sep 14, 2010 at 11:04 AM, Dennis Munsie <dmunsie at gmail.com> wrote:
> Hi --
> I'm trying to figure out how to properly use rate control in x264 -- I am
> encoding a stream where the frame rate changes periodically (it's a webcam
> that drops the framerate while it's re-focusing).  How does x264 handle
> applying rate control when it doesn't necessarily know how many frames it is
> going to get over time?  When I set rc.i_bitrate, I do see the stream's
> bitrate change, but it's always off by some amount -- i.e, I ask for
> 2500kbps and my stream will be 3500kbps.  If I ask for 500kbps, it will be
> 1000kbps.  It gets closer, but not quite there.  I assume this has to do
> with not setting up the x264_param_t struct correctly, but I'm really not
> sure what I need to set it up with.

Bitrate is an average bitrate over time.  If you're streaming, that's
not what you want; you want to set maxrate and bufsize accordingly.

> I am using low-latency mode already -- is there anything specific I should
> be setting?  b_vfr_input, i_fps_num/den and i_timebase_num/den look like
> things I should be looking into, but I'm currently at a loss as to how to
> set these correctly given my source stream.

There are a few ways to deal with variable input FPS:

1.  Set b_vfr_input back to 1 (goes to zero in low-latency mode) and
pass in valid timestamps for each frame.  Adds one frame of latency
(to allow x264 to figure out the duration of each frame).
2.  Start with the higher possible FPS and just let the encoder use
fewer bits in cases where the framerate goes down.  Suitable if the
framerate doesn't normally change much.
3.  Use reconfig to change the maxrate/bufsize as necessary if the
framerate changes.  Suitable if the framerate changes permanently or
for long periods of time.

> Also -- do I need to set the i_dts for the picture to account for the
> variable frame rate?

As listed in the documentation, i_dts is set by the encoder.  The user
sets i_pts.  However, if b_vfr_input = 0, x264 ignores the PTS.

Dark Shikari


More information about the x264-devel mailing list