Diary Of An x264 Developer

02/15/2010 (9:02 pm)

x264: now with adaptive streaming support

Filed under: ratecontrol,streaming,x264 ::

You’re running a video chat program on a relatively weak upstream connection.  Someone else opens a video chat program on the same connection and your available bandwidth immediately drops.  What do you do?

You’re running a streaming video server that sends live video to an iPhone.  The client moves into an area of weaker reception and the stream begins to break up.  What do you do?

You’re running a streaming video server and it has currently maxed out your connection with the current viewers, but you want another person to be able to connect.   You’d rather not restart the whole server though.  What do you do?

Well, before, you didn’t have any options.  But now you do…

x264_param_t p;
x264_encoder_parameters( handle, &p );
p.rc.i_vbv_buffer_size /= 2;
p.rc.i_vbv_max_bitrate /= 2;
x264_encoder_reconfig( handle, &p );

Bam, the max bitrate of the stream was just reduced by half, applicable instantly.  You can also change the CRF when in CRF mode, adjust maxrate/bufsize arbitrarily, and change the bitrate in CBR mode.  The only restriction is that you can’t change the mode itself and you can’t change the bitrate in ABR mode.

Cool beans, eh?  Thanks to SayMama video calling for sponsoring this feature.

13 Responses to “x264: now with adaptive streaming support”

  1. bgmarete Says:

    This is really nice Dark Shikari! Just as I was in the middle of whipping up an application using the recent error resilience features of x264 in a real world live (Television) streaming application, now I need to look at how I can use this new feature!

    In my current app, I am using RTP. What do you think of using RTCP Receiver Reports to detect the presence and rate of packet loss in order to then figure out the vbv-* parameter adaptations? My only worry is that these reports (due to the rate-limiting nature of RTCP) may be out-of-date by the time they give me sufficient information.

    In any case, thanks. x264 is fast becoming the encoder without compare.

  2. Zipped Power Says:

    You can use RFC 4585 which is the early feedback profile for RTP. In that case, RTCP reports will make sense to adapt to congestion.

  3. nick Says:

    Is bitstream hrd conformant after changing bitrate like this? Or it doesn’t matter in such use case?

  4. Dark Shikari Says:

    @nick

    This is actually a very good question. Currently HRD support isn’t in trunk yet, but when it will be, we do plan to support it in bitrate-changing mode. Here’s how:

    1) Send a new SPS containing the new buffer information.
    2) If the ratecontrol reconfiguration results in bits being thrown away due to being larger than the buffer, we will insert filler bits accordingly.

    Of course this won’t be bothered with outside of HRD mode.

  5. bgmarete Says:

    @Zipped. Looked at it. Just what I need. Thanks! Does not seem to be implemented in any open library yet, so will try and implement it on Live555.

  6. brendan Says:

    I actually came across this code yesterday while snooping through the x264 source trying to track down a seg fault (was my bad btw, not x264s). Haven’t had a chance to try it out yet but looks incredibly useful. I’m just a bit confused about what exactly isn’t supported in ABR mode. You say that you can’t change the bitrate in ABR mode but does that mean changes to p.rc.i_bitrate or p.rc.i_vbv_max_bitrate aren’t supported?

  7. kierank Says:

    @brendan

    The former.

  8. creamyhorror Says:

    I can’t wait to use the first (?) x264-based videochat application.

  9. brendan Says:

    @kierank

    Thanks, that’s what I thought.

  10. dpury Says:

    What are your thoughts on x264 and SVC encoding?

  11. Håkon K. Olafsen Says:

    I’m just wondering if it would be possible to double the bit rate too? Or maybe make it a 3rd or a fraction (2/3 e.g.) of the original? Or is it only possible to halve the stream?

  12. Babil Says:

    @Hakon: it should be possible to change the encoding bit-rate either ways (both high and low). That’s what “x264_encoder_reconfig()” does based on values you set in:
    - ‘p.rc.i_vbv_buffer_size’ and
    - ‘p.rc.i_vbv_max_bitrate.’

  13. Denis Says:

    Where is SayMama now ?

Leave a Reply