Tool

VMAF Command Builder for FFmpeg

Enter the resolution, fps and pixel format of your encoded video and the original, and this tool builds the FFmpeg command that measures VMAF with libvmaf. It writes the input order, the resolution matching and the model path escaping that so often trips people up on Windows, all tailored to your shell (PowerShell, cmd or bash). It never reads or uploads your files; only the names go into the command.

1. Shell to run the command in


2. Files

Type the file name or path as-is. The tool never reads the files; it only puts the names into the command.


3. Properties of the two videos (check with ffprobe or a file info tool)


4. Model and output

n_subsample 1 = every frame, first N seconds 0 = the whole video.


5. Finished command

For PowerShell
ffmpeg -hide_banner `
  -i 'encoded.mp4' `
  -i 'original.mp4' `
  -lavfi '[0:v]format=yuv420p,setpts=PTS-STARTPTS[dist];[1:v]format=yuv420p,setpts=PTS-STARTPTS[ref];[dist][ref]libvmaf=model=version=vmaf_v0.6.1:n_threads=4:log_fmt=json:log_path=vmaf.json' `
  -f null -

Input order: the first -i is the video to compare (the encoded one) and the second -i is the original. Swapping them changes the score.

Both videos are converted to 8-bit (yuv420p) for measuring. If the original is 10-bit, matching to 10-bit loses no information.

n_threads is the number of threads libvmaf uses. Our lab tests used 4 per job on a 6-core, 12-thread PC.

When it finishes, vmaf.json is created. Load it into the VMAF log viewer tool to see per-frame scores.

How the command is put together

The command takes two inputs, reshapes each one with filters, passes them to libvmaf, and saves the result as a JSON log. There is no video to display, so the output is -f null -.

  • Input order: the first -i is the video to compare (the encoded one) and the second is the original. Swapping them changes the score, so check this first.
  • scale: if the two videos have different resolutions, they must be matched. By default this tool scales the encoded video to the original's resolution; if you pick a measurement resolution yourself, both videos are converted to it.
  • fps: if the frame rates differ, an fps filter is added to the encoded video. If frames are off by even one, the comparison itself goes off, so for variable frame rate video, check with the VFR detector first.
  • format: makes both videos use the same pixel format, to prevent 8-bit and 10-bit from getting mixed.
  • setpts: resets both videos' start times to 0 so the frames pair up.

Why the model path fails on Windows

In an FFmpeg filter string, the colon (:) separates options, so using the drive-letter colon in C:/models/... as-is cuts the path off right there. You have to put a backslash before the colon, and because escaping is applied in layers (the filtergraph level and the option level), the number of backslashes grows. The rules this tool uses are below. They were built from the escaping description in the FFmpeg documentation, so please read ‘Limitations’ further down as well.

  • Log path (log_path=): C\\:/work/vmaf.json — two backslashes.
  • Model file path (model=path=): C\\\\:/ffmpeg/model/vmaf_v0.6.1.json — the model= value has one more inner key=value level, so four backslashes.
  • Differences between shells: the characters above must reach FFmpeg unchanged. This tool wraps the whole filter in single quotes for PowerShell and bash, and in double quotes for cmd, so the backslashes aren't altered. If you wrap it in double quotes in bash, two backslashes shrink to one and you have to write twice as many; that hassle is what people mean when they say “the count differs by shell.”
  • The easiest fix: don't use a path at all. If you pick the model by built-in version name, such as model=version=vmaf_v0.6.1, no file path is needed (for libvmaf builds that include the built-in models). And if you keep the log as a relative path like vmaf.json, there is no colon.

If an example you found online shows model_path=...pkl, psnr=1 or ssim=1, that is known to be the libvmaf 1.x syntax. Recent FFmpeg builds use model=version=... or model=path=...json, and feature=name=psnr.

When you get a resolution mismatch or NaN

  • A “resolutions differ” error: if the two inputs don't have the same resolution, libvmaf can't compare them. Enter both resolutions in the tool above and you get a command with scale in it. Scaling the encoded video to the original's size is the common approach.
  • An abnormal score (NaN, or absurdly low): suspect first that the input order is swapped, that the pixel formats differ and the conversion is off, or that the two videos' frame counts or start times don't line up. The commands from this tool are built to match all three. If you still get NaN, the cause may be in the video or the FFmpeg build; paste the log into the FFmpeg error log explainer.
  • An error that the model file can't be read: the escape count is wrong, the file doesn't exist, or the model format doesn't match. Switching to a built-in model name and checking whether it works tells you whether the path was the problem.

How do I use the result?

  • Once vmaf.json is created, load it into the VMAF log viewer to see the per-frame graph, the bottom 1% and the minimum. Judging by a single average can hide the bad moments; that is covered in Is an average VMAF of 95 safe? A lab test.
  • For what a score means, and for CRF and bitrate samples that produced similar scores, see the VMAF score interpreter.
  • If the measurement takes too long, measure only the first N seconds or raise n_subsample to skip frames. The result can then differ from a full measurement, so make the final call with a full run.
  • Turning on PSNR and SSIM output records them in the same run. The video is decoded only once, which beats measuring twice separately.
  • To build the encoding command before measuring, use the FFmpeg command builder.

Which model should I pick?

  • Default (vmaf_v0.6.1): the model our lab tests used. It is known to assume viewing on a 1080p screen.
  • 4K (vmaf_4k_v0.6.1): a model that assumes viewing on a 4K screen. It is a candidate when measuring 3840x2160 video.
  • NEG (vmaf_v0.6.1neg): known to be a model that leaves out the score boost (enhancement gain) from preprocessing such as sharpening. For ordinary encoding comparisons with no preprocessing, many people use the default model.
  • Default + NEG together: records both scores in a single run. In the JSON they are stored separately under the names vmaf and vmaf_neg.

Limitations worth knowing

  • This tool builds the command; it doesn't run it. The escaping rules are based on the explanation in the FFmpeg documentation, and we haven't been able to test every shell, FFmpeg version and build. If you get an error, switch to a built-in model name and a relative path.
  • Your FFmpeg needs libvmaf. Check that libvmaf appears in ffmpeg -filters. If it doesn't, inspect your build with the FFmpeg build checker and switch builds. The model syntax here is for libvmaf 2.x with FFmpeg 5 and later, and may not fit older builds.
  • We don't give an optimal value for n_threads. Our lab tests ran several jobs at once on a 6-core, 12-thread PC and used 4 per job; we did not measure VMAF speed by thread count. The default of 4 follows that setup, so change it to fit your own PC's core count.
  • A score from a scaled comparison differs from one measured at the same resolution. The upscaling or downscaling filter affects the score, so when comparing several videos, keep both the measurement resolution and the method identical.
  • The resolution and fps are taken on trust from what you type. If you enter them wrong, an unnecessary scale gets added or a needed one is left out. Check them with the video file info inspector.
  • A high score doesn't guarantee it looks fine. For important videos, look for yourself with the quality comparison slider.