paulpacifico / shutter-encoder

A professional video compression tool accessible to all, mostly based on FFmpeg.
https://www.shutterencoder.com
GNU General Public License v3.0
936 stars 59 forks source link

Add option for maximum bitrate #118

Open DesertCookie opened 1 year ago

DesertCookie commented 1 year ago

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 commented 1 year ago

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

DesertCookie commented 1 year ago

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 commented 1 year ago

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

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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