Try it yourself, from the basic command through measuring several models at once to pulling the average, 5th percentile, and minimum out of the per-frame log.
In Chapter 10 you got a taste of the one-line VMAF command. Here we extend it into a form that takes care of the measurement conditions. First, check whether your ffmpeg includes libvmaf.
ffmpeg -hide_banner -filters | grep libvmaf
ffmpeg -hide_banner -h filter=libvmafIn the libvmaf filter, the first input is the one under test (distorted) and the second is the original (reference). The examples in the FFmpeg documentation use this order too. Swapping them can change the score, so always write -i result -i original.
ffmpeg -i encoded.mkv -i reference.y4m -lavfi \
"[0:v]setpts=PTS-STARTPTS[d];[1:v]setpts=PTS-STARTPTS[r];[d][r]libvmaf=log_fmt=json:log_path=vmaf.json:n_threads=4" \
-f null -
# Near the last line it prints 'VMAF score: ...',
# and vmaf.json stores the per-frame scores and a summary (pooled_metrics).ffmpeg -i encoded_720p.mkv -i reference_1080p.y4m -lavfi \
"[0:v]scale=1920:1080:flags=bicubic,setpts=PTS-STARTPTS[d];[1:v]setpts=PTS-STARTPTS[r];[d][r]libvmaf=log_fmt=json:log_path=vmaf.json:n_threads=4" \
-f null -ffmpeg -i encoded.mkv -i reference.y4m -lavfi \
'[0:v]setpts=PTS-STARTPTS[d];[1:v]setpts=PTS-STARTPTS[r];[d][r]libvmaf=model=version=vmaf_v0.6.1\\:name=vmaf|version=vmaf_v0.6.1neg\\:name=vmaf_neg:log_fmt=json:log_path=vmaf.json:n_threads=4' \
-f null -
# The above assumes a shell like bash, where backslashes inside single quotes are passed through as-is.
# Separate the models with |, and separate each model's options with \\: (the style used in the FFmpeg docs).
# For the 4K model or phone mode, change only the version/enable_transform value and specify it the same way.
# (Option syntax can vary by version, so check with ffmpeg -h filter=libvmaf)Windows paths like C:\... are prone to errors inside a filter string, because the colon (:) collides with the option separator. The simplest fix is to write log_path as a path relative to the working folder (vmaf.json).
The three numbers from lesson 3 can be computed straight from the per-frame scores in the JSON. The Python below is a minimal example that uses only the standard library. It takes the 5th percentile the simple way: sort from lowest and pick the value at the 5% position (the value can differ slightly depending on how you compute quantiles).
import json
d = json.load(open("vmaf.json"))
scores = sorted(f["metrics"]["vmaf"] for f in d["frames"])
n = len(scores)
print("frames :", n)
print("average :", sum(scores) / n)
print("5th pct :", scores[int(n * 0.05)])
print("minimum :", scores[0])
# If you measured two models together with names like vmaf_neg,
# change the key ("vmaf", "vmaf_neg") and pull them out the same way.The items this site's measurement articles always include are also the minimum list for a reproducible record: the FFmpeg version, the model used, the input format (resolution, fps, pix_fmt), how many frames were used, the exact command, and the clip source and license. If you keep only the numbers and drop these, you can't compare again later. To put together the encoding options, you can use the FFmpeg command builder.
The VMAF computation library. If it is built into ffmpeg, you use it as the libvmaf filter.
The part of the libvmaf JSON log that summarizes the per-frame scores (the average, and so on).
A filter option that sets how many threads libvmaf uses for the computation.
Which is the correct input order for the libvmaf filter?