alexheretic / ab-av1

AV1 re-encoding using ffmpeg, svt-av1 & vmaf.
MIT License
445 stars 29 forks source link

Feature request: add max bitrate in addition to --max-encoded-percent #199

Open radonm opened 6 months ago

radonm commented 6 months ago

Would it be possible to add an option like --max-bitrate to be used instead of --max-encoded-percent ? I've found a limit on what's remotely streamable without buffering so my constraint is actually max bitrate (probably not only mine) and I have to convert that manually to --max-encoded-percent.

n00mkrad commented 5 months ago

+1 from me.

For now the workaround would be to do the maths (e.g. a script that reads the input video bitrate and divides it by the desired bitrate to get the percentage).

For reference, if anyone needs the command, this is how to reliably (read: not using metadata) get video bitrate:

ffmpeg -loglevel error -stats -i INPUT -map 0:v:0 -c copy -f matroska NUL

This will demux the video stream and print the stats including bitrate. Linux users should replace NUL with /dev/null.

alexheretic commented 5 months ago

ab-av1 is focused on crf style single pass encoding. The encoder may support setting a max bitrate but exactly how it works may vary.

The default svt-av1 encoder does seem to support this so you can try using, e.g. --enc maxrate=10000k.

radonm commented 5 months ago

I guess I didn't describe it so well. Yes it would be single pass crf encoding but instead of giving --max-encoded-percent one could give average target bitrate for the converted file and the program internally calculates --max-encoded percent as average-target-bitrate / average-source-bitrate .

n00mkrad commented 5 months ago

ab-av1 is focused on crf style single pass encoding. The encoder may support setting a max bitrate but exactly how it works may vary.

The default svt-av1 encoder does seem to support this so you can try using, e.g. --enc maxrate=10000k.

Well ab-av1 already supports bitrate estimation, so all it needs is an option to target that bitrate instead of VMAF.

alexheretic commented 5 months ago

Ok if it's just about entering a bitrate version of --max-encoded-percent, ie --max-encoded-bitrate for the crf-search then the problem is simply measuring the bitrate of the encoded samples in a reliable way. This will have the same problem as max-encoded-percent, in that it is a prediction of the size/bitrate based on the samples and this can be a bit worse than the prediction of quality based on samples.

We already do an ffprobe of the encoded samples, which returns a bitrate. So we can use that and fail if it is missing.

This could also be confused with an encoder max bitrate, as I did. But that can probably be solved with good docs on the new argument.

radonm commented 5 months ago

Ok if it's just about entering a bitrate version of --max-encoded-percent, ie --max-encoded-bitrate for the crf-search then the problem is simply measuring the bitrate of the encoded samples in a reliable way. This will have the same problem as max-encoded-percent, in that it is a prediction of the size/bitrate based on the samples and this can be a bit worse than the prediction of quality based on samples.

We already do an ffprobe of the encoded samples, which returns a bitrate. So we can use that and fail if it is missing.

This could also be confused with an encoder max bitrate, as I did. But that can probably be solved with good docs on the new argument.

Yes, this is what I meant - bitrate version of --max-encoded-percent for crf-search.