Binary search encoding to hit desired VMAF score
This util will encode using ffmpeg and x265 to hit a desired VMAF score using a binary search of CRF values in order to do so. It is a lot slower than something like av1an since this actually does a full encode for each step in the binary search. This will seem wasteful to many people, I'm sure, but I prefer to do it this way. Otherwise I would just use av1an to have it done the way that program does it.
Usage:
BSEncode input.mkv --vmaf 95.5 --preset medium
--vmaf and --preset are optional. If omitted it will use VMAF 97.0 and preset slow.
Requirements:
ffmpeg, which you can download from here. https://www.gyan.dev/ffmpeg/builds/ You can either put ffmpeg.exe in the same folder, or a different one as long as it is in your PATH so it can be found.
At the moment it only encodes with x265, as that's what I usually use. I may or may not add other codecs. For now it is just x265. There are also two other utilities that might be considered related. One called quality-compare, and one called bench-codecs. The purpose of quality-compare is to take an input file and encode several copies with VMAF scores from 89 through 98 so that you can decide which VMAF target you want to use for a given situation. Such as, watching on your big livingroom TV, or watching on your phone or tablet. You can start watching the 89 file, then the 90, etc., until you find one that is sufficient for that use case. Then you can use that target for BSEncode. Then bench-codecs lets you compare presets for a few codecs to see how fast your computer can process and how big the files will be compared to each other.
quality-compare usage:
quality-compare input.mkv
This will give you ten output files like these:
input-VMAF-89-CRFxx.x.mkv input-VMAF-90-CRFxx.x.mkv input-VMAF-91-CRFxx.x.mkv ...
Then you can watch those to determine the target quality you wish to use. Once you have a target quality in mind you can use bench-codecs if you would like to see how long it might take and how big the files might be.
bench-codecs usage:
bench-codecs input.mkv --vmaf 95.5 --x264
or --x265 or --av1 (for SVT-AV1) or --nv264 (for NVENC H.264) or --nv265 (for NVENC H.265)
It will default to VMAF 97.0 and x265 if you omit them. This will output one file for each preset for that particular codec. The filename will contain the codec name, the preset, the CRF/CQ used, the VMAF score, the elapsed time in HH-MM-SS, and the filesize. Example filenames:
input-x265-01-ultrafast-CRF 10.0-VMAF 97.00-ET 00-00-54-size 27.1 MB.mkv input-x265-06-medium-CRF 13.6-VMAF 97.07-ET 00-02-09-size 23.1 MB.mkv