How do I do a Variable Bitrate Encode with a Maximum Bitrate?

HandBrake for Windows support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
User51
Posts: 5
Joined: Wed Jan 17, 2018 5:03 am

How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by User51 »

Description of problem or question
Hello HandBrake users :) I'm trying to figure out how to do a variable bitrate encode that has a maximum bitrate I don't want to go over. I want HandBrake to analyze the scene and use anywhere from 0 kbps up to a maximum of 3000 kbps depending on what the scene can use.

I've read guides online, looked at the online manual and did a forum search, but I don't feel I found out how to do it -- at least not in a way I completely understand. The bitrate option in Handbrake allows me to enter the average bitrate, but I'm not sure if that's how you do it as I don't want to apply an average bitrate to the entire encode.

I've tried using the VBV-MAXRATE and VBV-BUFSIZE in the Extra Options at the bottom of the Video tab, but again, I'm not sure if it's doing what I want it to do as stated above.

Thank you for your time and patience :)

Steps to reproduce the problem (If Applicable)


HandBrake version (e.g., 1.0.0)
1.0.7

Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.3 High Sierra, Windows 10 Creators Update)
Windows 10 64-Bit with the latest updates

Error message text or screenshot (If Applicable)

Provide a URL from any image hosting site.

HandBrake Activity Log ***required*** (see How-to get an activity log)

Use any pastebin website and provide the URL it generates
- or -

Code: Select all

Paste log text between these markers.
[code][/i]
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by mduell »

The vbv options will let you do this. Use a quality (RF) target, and set the max bitrate over whatever your averaging/buffering period is with vbv.
User51
Posts: 5
Joined: Wed Jan 17, 2018 5:03 am

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by User51 »

mduell wrote: Wed Jan 17, 2018 11:26 pm The vbv options will let you do this. Use a quality (RF) target, and set the max bitrate over whatever your averaging/buffering period is with vbv.
Hi mduell :)

Oh, okay :) Does it matter what RF target I use?


Edit 1: I thought I understood what you were saying in my initial response above, but I believe I misunderstood. What would help me understand more is if I give you another example where '0' kbps isn't in the equation.

If I'm encoding a video and I want the average/minimum bitrate to be 1500 kbps and the maximum bitrate to never go over 3000 kbps; I'd do a test encode and set the RF to 24 -- lets say, and depending on the video, see what average bitrate that gives me. Once I find the RF number that gives me the ~1500 kbps average/minimum bitrate I want for that video, I can add VBV-MAXRATE=3000 and VBV-BUFSIZE=6000 to the Extra Options and that should give me my desired result, correct?

If I'm understanding it correctly now, is there a quicker way to know what an RF value will yield -- average bitrate-wise, in different videos? I know that it depends on the content of each video; so an RF value of 24 will yield a higher bitrate in a "grainier" video to maintain the fine details compared to a video that doesn't have as much grain etc.

I've heard too that VBV-BUFSIZE should be equal or double that of the VBV-MAXRATE. Is that correct? I've heard the VBV-BUFSIZE depends on the individual device you're playing the file on, but I'll only be playing the videos via a computer, the VLC Android app and possibly a Chromecast.

Again. Thank you for your time and patience mduell and any others that decide to put their two cents in :)
mduell
Veteran User
Posts: 8187
Joined: Sat Apr 21, 2007 8:54 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by mduell »

As usual, choose a reasonable RF for your content, resolution, and personal preferences.

I don't know why you want to target a particular average bitrate, but it's probably a bad idea. Try RF values until you get the quality you want across a range of videos. Some videos will be higher bitrate, some will be lower.

The ratio of vbv-bufsize to vbv-maxrate is however many seconds of video your device needs to buffer. For some hardware applications it's a well defined number by the playback chip. For network constraints it just depends on how much buffering your playback software is doing. 2 seconds is a reasonable number, but in no way definitive. It could be 1x for a 1 second buffer, or 10x for a 10 second buffer.
User51
Posts: 5
Joined: Wed Jan 17, 2018 5:03 am

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by User51 »

mduell wrote: Fri Jan 19, 2018 12:33 am As usual, choose a reasonable RF for your content, resolution, and personal preferences.

I don't know why you want to target a particular average bitrate, but it's probably a bad idea. Try RF values until you get the quality you want across a range of videos. Some videos will be higher bitrate, some will be lower.

The ratio of vbv-bufsize to vbv-maxrate is however many seconds of video your device needs to buffer. For some hardware applications it's a well defined number by the playback chip. For network constraints it just depends on how much buffering your playback software is doing. 2 seconds is a reasonable number, but in no way definitive. It could be 1x for a 1 second buffer, or 10x for a 10 second buffer.
Hello again mduell :)

This whole situation came about when I wanted to see how much quality I could retain/make the video look its best for me, when limiting the bitrate/filesize (I was curious).

So I tried two things starting out; I created an 1GB Preset where the total bitrate (video & audio) would equal 1GB in filesize per 1.5 hours of video. Then I created a 2GB Preset which did the same.

I was pretty happy with both results and they looked good viewing close up on a computer monitor and of course even "better" when viewing in a living room on an 50" HDTV because of the distance and/or the whole "Retina" concept.

I then asked myself if there was a way I could improve on this by creating a "hybrid preset" between the two.

I did a test on a Blu-ray source that had more-than-your-average-grain and found the 1GB Preset yielded more blocky artifacts in certain scenes (of course) throughout the movie, but the 2GB Preset version was great/much better in those scenes.

I didn't know if I was understanding/doing things correctly on my own; I've found many guides of course and read and tested a lot too, but I still wasn't sure if I was interpreting what I was reading correctly or if I was misunderstanding how it worked. So this led me to posting in the HandBrake forums :)

I was doing 2-Pass encodes with an Average Bitrate for both presets and thought that if I can create more of a VBR encode instead of an ABR encode, I can get better quality in the 'grainer' scenes and still have smaller files than the 2GB preset was churning out (possibly).

So if I instructed HandBrake to not use an ABR, but a VBR instead and limit the maximum bitrate so the files don't go over the 2GB preset, those scenes which were more blocky because of the lower bitrate of the 1GB preset ABR, would have a higher bitrate in those scenes if I used a VBR method with a maximum bitrate to limit the filesize and match the 2GB preset quality.

Having said all this though, I could use the 2GB preset and be done with it, but again, the reason why I'm doing this is because I'm curious and to see if I can create a hybrid preset between the two presets that will yield roughly the same quality as the 2GB preset does, but with filesizes in-between the 1GB & 2GB presets.

I'm not sure how clear this post is or if I'm explaining myself well enough for people to understand, but yeah, this is what my thought process was through this little adventure :)

Again. Thank you for your time, input and helping me understand things mduell :)
rollin_eng
Veteran User
Posts: 4840
Joined: Wed May 04, 2011 11:06 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by rollin_eng »

If you want a certain quality then use CRF encoding and don’t worry about size.

If you want a certain size use 2 pass ABR and don’t worry about quality.

Trying to do some kind of hybrid will probably not work as you expect i.e. if you cap your bitrate then the encoder may not be able to achieve the quality you selected.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by JohnAStebbins »

This whole situation came about when I wanted to see how much quality I could retain/make the video look its best for me, when limiting the bitrate/filesize
There are only a few reasons anyone should use vbv settings.
  • You are streaming over a network with known limited bandwidth
  • Your playback device has known limited playback capabilities
  • You are recording to a physical medium with known limited capacity (e.g. USB stick)
Your use case doesn't really fit. You will not see much savings in filesize until you restrict vbv-maxrate to the point that quality differences become pretty obvious. So the vbv settings are not really useful here and you might as well stick with regular ABR encoding if filesize is the most important factor for you.

Only the second in that list has any requirement on vbv-bufsize. What you set vbv-bufsize to depends on the capabilities of the playback device. Many players don't have a hard limit and dynamically buffer until the system runs out of memory. If the playback device has no specific buffering limitations, than you can set vbv-bufsize to pretty much anything you want.

vbv-maxrate defines the maximum average bitrate that will be encoded. The average is computed over the duration of the data that fits in vbv-bufsize. I.e. there can be instantaneous bitrates above vbv-maxrate, but over the duration of what fits in vbv-bufsize the bitrate will not exceed vbv-maxrate.
Deleted User 11865

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by Deleted User 11865 »

Well, technically you need to use VBV if you want your stream to be fully compliant with the spec, but setting your H.264 level to anything other than "auto" already takes care of that aspect.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by JohnAStebbins »

I left out one twist on use case 3 from the list above that may actually apply to you. You have a collection of videos that is mostly low complexity (i.e. it is easily encoded to high quality with low bitrate), but you have a few videos that are high complexity and you want all videos in the collection to be encoded with the same preset to a size that will fit into a know limited capacity (e.g. < 4G).

I could understand wanting to use vbv under these circumstances.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by JohnAStebbins »

Rodeo wrote: Fri Jan 19, 2018 4:13 pm Well, technically you need to use VBV if you want your stream to be fully compliant with the spec, but setting your H.264 level to anything other than "auto" already takes care of that aspect.
That falls under use case 2 in my list. "Known limited capabilities".
User51
Posts: 5
Joined: Wed Jan 17, 2018 5:03 am

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by User51 »

rollin_eng wrote: Fri Jan 19, 2018 3:19 pm If you want a certain quality then use CRF encoding and don’t worry about size.

If you want a certain size use 2 pass ABR and don’t worry about quality.

Trying to do some kind of hybrid will probably not work as you expect i.e. if you cap your bitrate then the encoder may not be able to achieve the quality you selected.
Hi rollin_eng :)

Normally I would pick one or the other depending on what I was looking to do, but I was curious to see if it was something that could be done and if it was worth it. I also enjoy trying to learn too :)

I believe you're right. The whole "hybrid" idea probably wouldn't yield anything really noticeable -- or at least too noticeable, but I was trying to get the best quality I could by not going over the 2GB Preset and possibly making the filesize smaller than what the 2GB Preset yielded :)

From my understanding when doing a 2-Pass ABR encode at 1500 kbps, the bitrate still fluctuates/adjusts up & down somewhat (I don't know by how much -/+). And then if I set the VBV-MAXRATE to 3000 kbps I was thinking it might use more of the bitrate available that it was potentially not using when using ABR.

JohnAStebbins wrote: Fri Jan 19, 2018 4:09 pm
This whole situation came about when I wanted to see how much quality I could retain/make the video look its best for me, when limiting the bitrate/filesize
There are only a few reasons anyone should use vbv settings.
  • You are streaming over a network with known limited bandwidth
  • Your playback device has known limited playback capabilities
  • You are recording to a physical medium with known limited capacity (e.g. USB stick)
Your use case doesn't really fit. You will not see much savings in filesize until you restrict vbv-maxrate to the point that quality differences become pretty obvious. So the vbv settings are not really useful here and you might as well stick with regular ABR encoding if filesize is the most important factor for you.

Only the second in that list has any requirement on vbv-bufsize. What you set vbv-bufsize to depends on the capabilities of the playback device. Many players don't have a hard limit and dynamically buffer until the system runs out of memory. If the playback device has no specific buffering limitations, than you can set vbv-bufsize to pretty much anything you want.

vbv-maxrate defines the maximum average bitrate that will be encoded. The average is computed over the duration of the data that fits in vbv-bufsize. I.e. there can be instantaneous bitrates above vbv-maxrate, but over the duration of what fits in vbv-bufsize the bitrate will not exceed vbv-maxrate.
Hi JohnAStebbins :)

I've seen the VBV settings before and have read online from more than one source what they're supposed to do, but I just couldn't wrap my head around it -- and even with your knowledge about what those settings do, I still don't fully understand it. You typed it nice and clear to me but I don't have the technical know-how when it comes to that aspect of encoding.

Yeah, those use cases don't apply to me -- and normally one or more of them would if someone was using/tinkering with these settings. I wanted to see what the best quality I could get (with my tastes) with the smallest filesizes possible and then when I found two presets I liked, I wanted to see if I could improve them -- even slightly by trying to create something in the middle.

I agree; based on what I've been told by everyone so far and the tests I've done as a result, it's better to just stick with ABR in this case as I'm not sure I'm seeing any difference trying to do the this 'hybrid' idea.

In my head it sounds like it could work, but I'm suffering from a significant lack in knowledge on the subject.

From my understanding, the two VBV settings are applied when a selected Level is picked (4.0 etc.). Is there a way to disabled the VBV settings from being used at all? I thought they were a must and are automatically applied -- unless you meant that there is no reason to manually set them yourself unless you needed to do so because of the use cases above? Should I just set the Level to Auto and let HandBrake pick the Level?

Rodeo wrote: Fri Jan 19, 2018 4:13 pm Well, technically you need to use VBV if you want your stream to be fully compliant with the spec, but setting your H.264 level to anything other than "auto" already takes care of that aspect.
Hi Rodeo :)

Yeah, very true :)

JohnAStebbins wrote: Fri Jan 19, 2018 4:17 pm I left out one twist on use case 3 from the list above that may actually apply to you. You have a collection of videos that is mostly low complexity (i.e. it is easily encoded to high quality with low bitrate), but you have a few videos that are high complexity and you want all videos in the collection to be encoded with the same preset to a size that will fit into a know limited capacity (e.g. < 4G).

I could understand wanting to use vbv under these circumstances.
Yeah. The 1GB Preset was pretty good for low complexity videos and the 2GB Preset was good enough for me for the high complexity ones, so I wanted to see if I could improve the video quality in the 1GB ABR Preset by making another preset that fluctuated/adjusted the bitrate more than what the ABR was doing but still not going over the 3000 kbps ABR maximum and see if the filesize is slightly smaller than the 2GB Preset while possibly improving the quality.

Of course, with those low of bitrates and a high complexity video, chances are a VBR would just max out the 3000 kbps maximum and it'd be just the same as using the 2GB Preset -- but that off-chance it might've yielded a slightly smaller filesize than the 2GB Preset had me intrigued enough to pursue the idea :)
User51
Posts: 5
Joined: Wed Jan 17, 2018 5:03 am

Re: How do I do a Variable Bitrate Encode with a Maximum Bitrate?

Post by User51 »

Thank you all for your invaluable input, suggestions and explanations :)
Post Reply