Tool

Batch VMAF Script Builder

Paste the file names from your originals folder and your encodes folder, and this tool pairs them automatically and builds a script that measures VMAF for every file and collects the results into a single CSV. Instead of installing a dedicated VMAF GUI, you leave the repetitive work to the FFmpeg you already use. The files are never read or uploaded; only the names go into the script.

1. Environment to run in


2. Paste file names (one per line)

Select all the files in a folder and copy their names, or print just the names in PowerShell with something like (Get-ChildItem -Name) -join "`n" and paste them here. If a path is attached, only the file name is used. The files themselves are never read or uploaded.

4 pairs · 3 originals · 5 encoded files

EncodedOriginal
clip01_x264_crf23.mkvclip01.mp4
clip01_x265_crf26.mkvclip01.mp4
clip02_x264_crf23.mkvclip02.mp4
clip10_x265_crf26.mkvclip10.mp4

Encoded files with no match (1): extra_test.mp4 — left out of the script.


3. Folders


4. Measurement options

You don't enter resolution or fps. The script reads them from each file with ffprobe; if an encoded file's resolution differs from the original it is scaled to the original's size, and if its fps differs it is matched to the original's fps.


5. Script

vmaf-batch.ps1 · 4 to measure
# Batch VMAF measurement — script generated by Codec Lab's tool
# Run:  powershell -ExecutionPolicy Bypass -File .\vmaf-batch.ps1
# Requires: ffmpeg (with libvmaf) and ffprobe on PATH
$ErrorActionPreference = 'Stop'
$RefDir  = 'D:\originals'
$DistDir = 'D:\encodes'
$OutDir  = 'D:\vmaf-out'
$ModelOpt = 'model=version=vmaf_v0.6.1'
$Threads = 4
$Subsample = 1

# Pair list (dist = encoded file, ref = original)
$Pairs = @'
dist,ref
"clip01_x264_crf23.mkv","clip01.mp4"
"clip01_x265_crf26.mkv","clip01.mp4"
"clip02_x264_crf23.mkv","clip02.mp4"
"clip10_x265_crf26.mkv","clip10.mp4"
'@ | ConvertFrom-Csv

New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
$RefDir  = (Resolve-Path -LiteralPath $RefDir).Path
$DistDir = (Resolve-Path -LiteralPath $DistDir).Path
$OutDir  = (Resolve-Path -LiteralPath $OutDir).Path

function Get-Num([string]$r) {
  $p = $r -split '/'
  if ($p.Count -eq 2 -and [double]$p[1] -ne 0) { return [double]$p[0] / [double]$p[1] }
  return [double]$p[0]
}
function Get-Info([string]$f) {
  $o = (& ffprobe -v error -select_streams v:0 -show_entries stream=width,height,avg_frame_rate -of csv=p=0 $f | Select-Object -First 1)
  $a = $o -split ','
  return @{ W = [int]$a[0]; H = [int]$a[1]; Fps = $a[2] }
}

$rows = New-Object System.Collections.Generic.List[object]
$n = 0
foreach ($p in $Pairs) {
  $n++
  $dist = Join-Path $DistDir $p.dist
  $ref  = Join-Path $RefDir $p.ref
  $log  = ('vmaf_{0:000}.json' -f $n)
  $row = [ordered]@{ dist = $p.dist; ref = $p.ref; status = ''; vmaf_mean = ''; vmaf_harmonic_mean = ''; vmaf_min = ''; psnr_y_mean = ''; size_MB = ''; kbps = ''; scaled = ''; log = $log }
  if (-not (Test-Path -LiteralPath $dist) -or -not (Test-Path -LiteralPath $ref)) {
    $row.status = 'missing file'; $rows.Add([pscustomobject]$row); Write-Warning ('File not found: ' + $p.dist + ' / ' + $p.ref); continue
  }
  try {
    $d = Get-Info $dist; $r = Get-Info $ref
    $dChain = @()
    if ($d.W -ne $r.W -or $d.H -ne $r.H) { $dChain += ('scale={0}:{1}:flags=bicubic' -f $r.W, $r.H); $row.scaled = ('{0}x{1}->{2}x{3}' -f $d.W, $d.H, $r.W, $r.H) }
    if ([math]::Abs((Get-Num $d.Fps) - (Get-Num $r.Fps)) -gt 0.01) { $dChain += ('fps=' + $r.Fps) }
    $dChain += 'format=yuv420p'
    $dChain += 'setpts=PTS-STARTPTS'
    $rChain = @()
    $rChain += 'format=yuv420p'
    $rChain += 'setpts=PTS-STARTPTS'
    $opts = @($ModelOpt)
    if ($Threads -gt 0) { $opts += ('n_threads=' + $Threads) }
    if ($Subsample -gt 1) { $opts += ('n_subsample=' + $Subsample) }
    $opts += 'log_fmt=json'
    $opts += ('log_path=' + $log)
    $filter = '[0:v]' + ($dChain -join ',') + '[dist];[1:v]' + ($rChain -join ',') + '[ref];[dist][ref]libvmaf=' + ($opts -join ':')

    # Run from the output folder so the log path can be relative (avoids escaping the drive-letter colon)
    Push-Location $OutDir
    try { & ffmpeg -hide_banner -loglevel error -y -i $dist -i $ref -lavfi $filter -f null - } finally { Pop-Location }
    if ($LASTEXITCODE -ne 0) { throw ('ffmpeg exit code ' + $LASTEXITCODE) }

    $j = Get-Content -LiteralPath (Join-Path $OutDir $log) -Raw | ConvertFrom-Json
    $m = ($j.pooled_metrics.PSObject.Properties | Where-Object { $_.Name -like 'vmaf*' } | Select-Object -First 1).Value
    $row.vmaf_mean = [math]::Round([double]$m.mean, 3)
    $row.vmaf_harmonic_mean = [math]::Round([double]$m.harmonic_mean, 3)
    $row.vmaf_min = [math]::Round([double]$m.min, 3)
    $bytes = (Get-Item -LiteralPath $dist).Length
    $dur = [double](& ffprobe -v error -show_entries format=duration -of csv=p=0 $dist | Select-Object -First 1)
    $row.size_MB = [math]::Round($bytes / 1MB, 2)
    if ($dur -gt 0) { $row.kbps = [math]::Round($bytes * 8 / $dur / 1000, 0) }
    $row.status = 'ok'
  } catch {
    $row.status = 'error: ' + $_.Exception.Message
    Write-Warning ($p.dist + ' measurement failed: ' + $_.Exception.Message)
  }
  $rows.Add([pscustomobject]$row)
  Write-Host ('[{0}/{1}] {2}  {3}  VMAF={4}' -f $n, @($Pairs).Count, $p.dist, $row.status, $row.vmaf_mean)
}

$csv = Join-Path $OutDir 'vmaf-summary.csv'
$rows | Export-Csv -LiteralPath $csv -NoTypeInformation -Encoding UTF8
Write-Host ('Summary CSV: ' + $csv)

In PowerShell, run the saved file with powershell -ExecutionPolicy Bypass -File .\vmaf-batch.ps1. When it finishes, the results folder contains a JSON log for each file and vmaf-summary.csv.

Why a script instead of a GUI?

Search for “vmaf gui” and you get small GitHub projects and commercial tools. Many of those programs are known to call FFmpeg's libvmaf filter under the hood. When you have dozens of files encoded at different CRF values, what you actually need is not a window but three things: pairing, repeated runs, and collecting results. This tool turns those three things into one script. There is nothing new to install, you can open and read the script, and changing an option and rerunning it is easy.

How to use it

  1. Paste the original file names and the encoded file names, one per line. The values you see at first are examples.
  2. Check the pair table. Encoded files with no match appear in red and are left out of the script.
  3. Set the three folders (originals, encodes, results) and the options.
  4. Save and run the script. Try it first on two or three files in a small folder, and once the results look right, run the whole set.

Pairing rules

  • Encoded name starts with the original name (default): the encoded file matches if its name without the extension equals the original name, or continues right after it with a separator such as _, -, . or a space. clip01.mp4 ↔ clip01_x264_crf23.mkv is an example. When there are two candidates, the longer original name wins, so even if clip1 and clip10 both exist, clip10_x265.mkv is attached to clip10.
  • Only when the names are identical: a pair is made only when the names without the extension are exactly the same. Use this when the originals and the encodes are in different folders under the same names.
  • Matching is case-insensitive. One original with several encodes attached (for example a CRF comparison) is normal.

What the script does

  • It reads the resolution and fps of every file with ffprobe. If an encoded file's resolution differs from the original's, the encoded file is scaled to the original's size, and if the fps differs it is matched to the original fps. Which files were scaled is recorded in the scaled column of the CSV. A score measured after matching can differ from a score measured between files of the same resolution, so measure the files you want to compare in the same way.
  • The input order is the encoded file first, the original second. It follows the same rule and the same filter chain (scale, fps, format, setpts) as the VMAF Command Builder for single commands.
  • It avoids the colon problem in log paths. The script changes into the results folder and then writes the log to a relative path like vmaf_001.json, so no C: escaping is needed. The model defaults to a built-in version name, so it needs no path either. If you specify a model file path yourself, only that path is escaped.
  • CSV columns: dist, ref, status, vmaf_mean, vmaf_harmonic_mean, vmaf_min, psnr_y_mean, size_MB, kbps, scaled, log. If one file fails, the script does not stop; it writes the reason in status and moves on to the next file. The PowerShell version of the CSV is UTF-8 with a BOM, so Excel usually opens even non-ASCII file names correctly.
  • kbps is the encoded file's size divided by its duration, so it is an overall average that includes audio and container overhead. It is not the bitrate of the video stream alone.

Choosing options

  • Model: the default (vmaf_v0.6.1) is known to be calibrated for a 1080p display, and it is the model our lab measurements used. The 4K model assumes a 4K display, so it is a candidate for 3840x2160 video. NEG is known as a model that measures without the score boost that preprocessing such as sharpening can give. For a fuller comparison, see the explanation on the command builder page.
  • n_threads: we won't give you an optimal value. Our lab measurements ran on a 6-core, 12-thread PC and used 4 threads per job only because several jobs ran at once; we did not time VMAF speed per thread count. This script measures files one after another, so try different values yourself within your PC's core count.
  • n_subsample: at 2 or higher, frames are skipped at that interval. This saves time, but the mean and minimum can differ from the full measurement, so it is better to make the final call with 1 (every frame).
  • Pixel format: both videos are converted to the same format. If your original is 10-bit, converting to 8-bit loses information, so choose 10-bit.

How do I read the results?

  • Don't judge by the mean alone. A file whose vmaf_min or vmaf_harmonic_mean is much lower than its mean may have bad moments. A case where a high mean hides bad stretches is in Is Average VMAF 95 Good Enough? (lab measurement).
  • For a suspicious file, load the JSON log from the results folder into the VMAF log viewer to see the per-frame graph.
  • To see what a score level means, along with CRF and bitrate samples that produced similar scores, use the VMAF Score Interpreter.
  • For encodes made from the same original, you can put size_MB and vmaf_mean side by side and ask “at a similar score, which one is smaller?” Don't compare scores across different originals; each original differs in how easy it is to compress.

Limits worth knowing

  • This tool only builds the script; it does not run it. We have not tested the generated script on every FFmpeg version and shell environment. Check it on one or two files first. If an error occurs, look at that file's status column and the PowerShell warning message, and paste the log into the FFmpeg Error Log Explainer.
  • Your FFmpeg needs libvmaf. Check that libvmaf shows up in ffmpeg -filters. If it doesn't, inspect your build with the FFmpeg build checker. The model syntax assumes libvmaf 2.x (FFmpeg 5 or later).
  • The JSON field names assume the libvmaf 2.x output format. The script reads mean, harmonic_mean and min from the first entry in pooled_metrics whose name starts with vmaf. With a log in a different format, those columns come out empty or the file is marked as failed.
  • It depends on file naming. An encoded file whose name does not contain the original's name (for example output (1).mp4) cannot be paired. Rename it or run the list in separate batches. If the pair table shows a wrong pairing, fix the names before using the script.
  • The bash version needs jq. The PowerShell version uses only built-in features. A double quote in a file name can throw the CSV off (Windows file names can't contain one).
  • A high score is no guarantee that nothing looks wrong. For important videos, look for yourself with the quality compare slider. To measure just one file quickly, the VMAF Command Builder is simpler.