1

I'm building presets for our users to convert the videos into an appropriate format for our online video repository. Since it's been awhile since I've built something like this from scratch, I've been looking at what others recommend, and notice that a lot of them specifically recommend variable bitrate encoding. For example:

https://support.google.com/youtube/answer/1722171?hl=en

Even with progressive or pseudo-streaming, wouldn't that just introduce pausing and stuttering in playback once you hit a segment with a high bitrate? It just seems odd as a general recommendation when that's likely to create a poor playback experience. Or am I just overestimating the problems since it's been some years since I last looked into it. Do you generally use a variable bitrate for online delivery these days?

  • I think you misunderstand what variable bitrate encoding does. It doesn't introduce stuttering or pausing. – Dr Mayhem Feb 24 '15 at 21:24
  • IDK who downvoted this. It's not a bad question, IMO, just a complete-beginner question. – Peter Cordes Feb 25 '15 at 5:14
  • Oh, also note that your link is for how to make videos to UPLOAD to youtube, for them to transcode before streaming them. That encode once, decode once, with no realtime constraint, use case is completely different from hosting videos for people to stream. For uploading to youtube, you want to use lots of bitrate, and if you have the upload bandwidth, encode time is of similar value to resulting filesize. So you might use x264 --crf 16 --preset fast. – Peter Cordes Feb 25 '15 at 5:16
  • I'm not misunderstanding, nor am I a beginner (built my first streaming video service in 1997 actually). I'll reply to the rest in your answer there but to clarify—the link was just one example of a recommendation I'm seeing everywhere. Based your answers it seems that everyone just assumes the pipes and buffers are big enough to compensate for spikes in bitrates these days. – grovberg Feb 25 '15 at 21:01
3

Players buffer streams. The bigger the buffer size, the longer window the encoder has to use higher bitrates for hard content, and then fewer bits earlier or later on easy content, to achieve similar quality for the whole video.

I'll assume you're going to use h.264 (aka AVC) as a codec, as it's the de-facto standard for streaming video on the Internet. VP8 is not as good quality. VP9 can look better than h.264, but support is limited. HEVC (h.265) is also better than h.264, but again player support is limited. (And hardware decode acceleration won't be widespread for years. This matters, because HEVC is very cpu-intensive to decode, more than AVC.)

The quality comparisons I'm talking about are with the best available encoders for each codec. x264 for AVC, Google's VPx for VP8/VP9, and x265 for HEVC. All with settings cranked up nearly all the way. x265 will start to get into seconds-per-frame instead of frames-per-second for 1080p with settings that slow, though. (x264 orders of magnitude faster, since it's been essentially mature for a couple years now, with few new speedups or quality gains being found.)

All these encoders are free open-source software. It's nice that you don't have to pay anything to get world-class quality codecs these days. :)

A random google hit on x264 vbv for streaming: http://forum.doom9.org/showthread.php?t=147460

An example from x264 --fullhelp:

  Constant bitrate at 1000kbps with a 2 second-buffer:
        x264 --vbv-bufsize 2000 --bitrate 1000 -o <output> <input>

(don't actually use one-pass target-bitrate mode, though. Either 2pass if you have a specific target bitrate, or crf with a target quality.)

edit: recommended usage for streaming, according to the x264 lead developer (Jason Garrett-Glaser), is quality target (CRF) mode with VBV-constrained bitrate. e.g.

x264 --vbv-bufsize 2000 --vbv-maxrate 1000 --crf 22 -preset slower -o <output> <input>

vbv-maxrate is the max speed the buffer can fill at. (i.e. the max network bandwidth). vbv-bufsize is of course the size of the buffer, which allows for non-sustained bitrate peaks higher than vbv-maxrate.

And of course, if you're encoding once to create a file which will be streamed many times, throw as much CPU time at it as you can. Encode time is of little importance compared to getting the most quality per bitrate (rate-distortion tradeoff, aka RD). The encode only happens once, and any bits you can save (while maintaining the same quality) are saved for every download. e.g. Use x264 with --preset veryslow.

  • As you say, players buffer streams. So what happens when the buffer runs out? Why the playback stutters and pauses of course! Take your example quoted above. Imagine that a user gets a solid 1200kbit/sec connection to my service. Imagine that user is watching a stream that requires about 1000kbit/sec for the first five minutes. Great! But now if that file is VBR (note their example isn’t) your file might suddenly require 2500kbit/sec for the next five minutes. Your 2 sec buffer runs out pretty quickly and the viewer can basically no longer watch the video. – grovberg Feb 25 '15 at 21:05
  • The whole point of telling the encoder the buffer size is so it can take that into account for rate-control, to make sure it doesn't underflow the buffer. x264 will always warn you if it couldn't meet your VBV requirements. (e.g. extremely low bitrate for HD, and it couldn't get there even by blurring everything to crap.) – Peter Cordes Feb 25 '15 at 23:44
  • I think what the stuff you've found so far didn't explain is that VBR doesn't have to mean pure quality-target-only VBR. Modern audio and video encoders now support constrained-VBR ratecontrol, where overall and local bitrate limits are obeyed, too. But they're otherwise free to spend bits where needed to get as much quality for the whole clip as possible. You're right that there's an issue here that needs to be accounted for, and --vbv-buffsize is how it's done. – Peter Cordes Feb 26 '15 at 3:36
  • edit: updated my answer after googling again. vbv-maxrate is the buffer-fill rate, not decoder-CPU-limited decode peak. And CRF + VBV is the recommended way to go for online (realtime) or offline encoding of video for streaming. – Peter Cordes Feb 26 '15 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.