Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for maximum bitrate #118

Open
DesertCookie opened this issue Feb 23, 2023 · 9 comments
Open

Add option for maximum bitrate #118

DesertCookie opened this issue Feb 23, 2023 · 9 comments

Comments

@DesertCookie
Copy link

Some codecs, such as VP9 support specifying a maximum bitrate. This can be very helpful when converting for streaming or when converting a file to another format, wanting to make sure its datarate doesn't exceed the source's datarate.

For VP9, for example, you'd do: -b:v 100000k to limit the bitrate to 100Mb/s.

@paulpacifico
Copy link
Owner

I maybe didn't understand, but why not setting the video bitrate to 100000 from Shutter to get this exact same command line?

@DesertCookie
Copy link
Author

DesertCookie commented Mar 3, 2023

Because in Shutter Encoder you can only set CRF- or bitrate-based encoding. My content usually sits around 25-50Mb/s with VP9 CRF10 but it will occasionally jump as high as 200Mb/s on complex scenes. Since my source clips only are 100Mb/s I don't want to end up with a larger file than I starter with, thus the need for the maximum bitrate option.

Edit: Or just a field to add custom FFmpeg options such as in HandBrake. This way you'd expose the full might of FFmpeg without overloading the GUI.

@BuyMyMojo
Copy link
Contributor

When encoding VBR having -b:v 100000k just sets the average bitrate but say if you're trying to reach a very specific file size you might want to also add -maxrate 100000k which will stop it from having a bitrate over that.

For a quick test;
I encoded a 35 minute video and got these two file sizes

  • -b:v 6000k = 1603.65MB
  • -b:v 6000k -maxrate 6000k -bufsize 6000k = 1295.55MB
    (these where libsx264's veryfast preset for speed so it is a slightly larger difference than there would be at slower presets)

bufsize in this case is how much data to encode before double checking if it should just the way it encodes to stick to the set maxrate and is required when using maxrate. commonly set to the same maxrate or double.

having both as an option under advanced settings would be nice wherever there is a VBR encoding mode, it applies to software and hardware encoding too.

As far as I know h264/5, vp8/9 and av1 all support this form of encoding.

this is also a dupe of #109

@paulpacifico
Copy link
Owner

This will be a part of the next release (v17.2) but I did not get it to work with vp8/9 and av1.

@BuyMyMojo
Copy link
Contributor

BuyMyMojo commented May 31, 2023

maxrate does seem like it works with vp9 but it might need minrate with it too, as a form of Constrained Quality.

same with AV1 after a quick look.

it also mentions for using CRF with specifically vp9 you should also use -b:v 0 which I don't know is the case in the code, I'm not sure if this line's use of FunctionUtils.setVideoBitrate() returns 0 here, I'm just not familiar with the code base enough.

@paulpacifico
Copy link
Owner

I've just tested using -crf 18 & -b:v 0 & -maxrate 500k and get this error: Rate control parameters set without a bitrate
Without -crf the -maxrate option is not working...

@BuyMyMojo
Copy link
Contributor

I think the valid usages of those two are either -crf 18 -b:v 0 or -minrate 400k -b:v 500k -maxrate 600k
I just don't think you can max rate crf in VP9. sorry for the confusion there.

@paulpacifico
Copy link
Owner

Oh ok no problem, I'm also experimenting but I can't get -minrate and -maxrate working I don't understand how to make it a constant bitrate...

@BuyMyMojo
Copy link
Contributor

CBR is never truly constant, Using -minrate 6000k -b:v 6000k -maxrate 6000k -bufsize 6000k is as close as it can get but it wont stay at a true 6000k, I'm pretty sure this is a limitation of the codecs and how they account for future frames since two pass encoding was made to directly help with this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants