A native macOS app that scans a folder of videos, decides which are worth re-encoding, and compresses those on the Apple Silicon Media Engine — never below a measured perceptual quality threshold.
macOS 26.0+ (Tahoe). Apple Silicon.
This library compresses — and an earlier version of this file said, at length, that it could not. That claim was wrong, and it was wrong because of a bug in the quality measurement, not a fact about the videos.
The "VMAF mean" the whole project gated on was computed with vmaf_score_pooled(..., 0, 0), which pools picture interval [0,0] — the first frame only, not the video. A lecture's title slide scores high, so the number looked plausible and tracked quality loosely enough to never look broken. Measured on a real 63-minute lecture, that "mean" read 95.42 while the true average of all 3,013 sampled frames was 96.64. The full autopsy is docs/03-calibration.md, Sweep 7.
With a correct mean, the corpus — 6,113 course videos, 363 GB, median 0.0122 bits/pixel — clears the strictest gate (VMAF 95 mean / 93 p5) while getting smaller. On the representative file, at the same near-transparent quality bar:
| quality | size | true VMAF mean / p5 | clears 95/93 |
|---|---|---|---|
| 0.55 | −22.7% | 96.08 / 95.08 | yes |
| 0.60 | −15.4% | 96.64 / 95.70 | yes |
| 0.65 | −1.9% | 97.42 / 96.73 | yes |
Every row is smaller and every row is visually near-transparent. The encoder finds the lowest quality that still clears your gate, per file — adaptive, so it starts aggressive (0.55 at Transparent), accepts the first pass, and only steps up for a file that needs more bits to stay above the bar. Measured, the default gate now compresses the representative file −21.6% in a single encode, where a fixed conservative default managed 1.9%. Extrapolated across the library, that is roughly 80 GB at a quality bar the brief calls transparent.
Honest caveat, larger than before: the earlier "cannot compress" finding also rested on this bug, and the camera-content sweeps that produced it have not been re-measured with the fixed scorer. And VMAF is least reliable on screen-recorded text — exactly this corpus — so whether −22.7% at a true VMAF of 96 is visually transparent is a question only your eyes settle. See docs/03-calibration.md, Sweep 7 and caveat 1.
- Scan a folder recursively. Probe every video. Report bits-per-pixel per file.
- Re-encode only files that can actually get smaller at your quality bar.
- Verify every output before accepting it — decode, duration, tracks, rotation, colour, VMAF, and smaller than the input.
- Show live per-file status, progress, ETA, and before → after sizes.
These are guardrails, not preferences. Each is enforced by construction, not discipline.
- Never modifies, moves, or deletes a source file. There is no flag for it. The engine has no write path to the source. Deletion is your job, manually, after you verify.
- Never writes into the source tree. It refuses to start if the destination is inside the source.
- Never leaves a partial file that looks complete. Encode → temp →
F_FULLFSYNC→rename(2). - Never accepts an output it could not verify. Failed verification deletes the temp and marks the file failed. There is no accept-with-warning.
- Never silently skips. Every file is
completed,skipped-with-reason, orfailed-with-reason. The status type makes "unaccounted" unrepresentable. - Never re-encodes a Live Photo, spatial video, Dolby Vision, or ProRes file by default — each would destroy something unrecoverable, and each says so in the UI.
- Never ships a flattering default. The gate is VMAF 95/93. Lower bars exist, are labelled, and are opt-in.
An output is accepted only if all of these hold:
| Check | Threshold |
|---|---|
| Decodes end to end | must |
| Duration | within ±100 ms of source |
| Track count | equal to source |
Rotation (preferredTransform) |
equal to source |
| Colour / HDR metadata | present and equal, if the source had it |
| Codec tag | hvc1 (not hev1 — QuickTime and Photos refuse hev1) |
| VMAF mean | ≥ 95 |
| VMAF 5th percentile | ≥ 93 |
| Output size | strictly smaller than input, else skipped: no-gain |
Both VMAF statistics are required, and which one saves you depends on the content — measured, in both directions:
| corpus | mean | p5 | which binds |
|---|---|---|---|
Camera content (~/Desktop/Courses) |
95.06 | 92.87 | p5 — the mean hides brief catastrophic frames |
Screen recordings (~/Downloads/Course-Lectures, Q=0.55) |
94.63 | 95.08 | the mean — the p5 is 0.45 higher |
On camera content the mean hides brief catastrophic frames, and gating on it alone would have shipped an 18% "saving" with the worst 5% of frames below the bar. On screen-recorded lecture slides the distribution is left-skewed instead: over 95% of frames are near-static text scoring high, while a few slide transitions crater and drag the mean below the 5th percentile. There, a p5-only gate would have passed a file whose mean was under the bar.
Neither statistic is the safe one to pick. That is the argument for requiring both. See docs/03-calibration.md, Sweep 5.
VMAF is scored against the decoded source, in-process, via a vendored libvmaf v3.0.0 (vmaf_v0.6.1 for ≤1080p, vmaf_4k_v0.6.1 above). Files over 2 minutes are sampled to a ~3,000-frame budget; the stride is reported.
Honest caveat: VMAF is trained on camera content. On screen recordings of text and code its 5th percentile is least reliable, and it may be pessimistic. See docs/03-calibration.md, caveat 1.
swift build -c release
# What's actually worth encoding? Probes only — no encoding, no writes.
.build/release/vtcompress analyze ~/Movies/Tutorials
# One file, in detail
.build/release/vtcompress probe some-video.mp4
# Machine + VideoToolbox capabilities
.build/release/vtcompress recon
# Encode. Destination must be outside the source.
.build/release/vtcompress run ~/Movies/Tutorials /Volumes/Scratch/outOptions: --quality <0..1> · --gate transparent|high|balanced · --bpp-floor <f> · --engines <n> · --allow-prores
The app target is VTCompressApp. Sign to Run Locally; no Developer ID needed.
Do not take the app's word for any of it.
# 1. Zero source files modified — the guarantee that matters most.
find ~/Movies/Tutorials -type f -name '*.mp4' -exec shasum -a 256 {} \; | sort > pre.sha
.build/release/vtcompress run ~/Movies/Tutorials /Volumes/Scratch/out
find ~/Movies/Tutorials -type f -name '*.mp4' -exec shasum -a 256 {} \; | sort > post.sha
diff pre.sha post.sha && echo "sources untouched"
# 2. Every file accounted for, with its reason.
sqlite3 /Volumes/Scratch/out/.vtcompress/manifest.db \
"SELECT status, COUNT(*) FROM files GROUP BY status;"
sqlite3 /Volumes/Scratch/out/.vtcompress/manifest.db \
"SELECT reason, COUNT(*) FROM files WHERE status!='completed' GROUP BY reason;"
# 3. Every output's real VMAF, as recorded.
sqlite3 /Volumes/Scratch/out/.vtcompress/manifest.db \
"SELECT src_path, vmaf_mean, vmaf_p5, bytes_in, bytes_out FROM files WHERE status='completed';"
# 4. Outputs play in QuickTime and Photos, and are tagged hvc1.
open /Volumes/Scratch/out/some/file.mp4
# 5. No orphaned temp files.
find /Volumes/Scratch/out -name '*.tmp-*'The manifest is plain SQLite. Nothing is hidden from you.
Quit or force-quit mid-run, relaunch, and it continues — losing at most one in-flight file. Rows left encoding are marked interrupted and requeued; orphaned temp files are swept.
The manifest keys on (device, inode, size, mtime_ns), not path, so moving a file doesn't cause a re-encode and editing one doesn't cause a wrong skip. Rows also record a hash of the encode parameters: change the quality gate and previously-done files correctly become eligible again rather than being silently treated as complete.
Sources/
VTCompressKit/ engine — headless, testable, no AppKit
VTCompressApp/ SwiftUI, macOS 26, Liquid Glass on chrome only
vtcompress/ CLI over the same kit
VMAFShim/ C shim over libvmaf's picture API
CVMAF/ module map for the vendored headers
Vendor/vmaf/ libvmaf v3.0.0, static, + models
Tools/ snapshot-check.sh (state coverage) + glass-harness.sh (glass fidelity)
docs/ every default, with the number behind it
docs/00-recon.md |
The machine, the real VideoToolbox capabilities, the corpus, the bpp histogram |
docs/03-calibration.md |
The quality sweep. The document that decided this project. |
docs/ARCHITECTURE.md |
Structure, the corrected skip gate, where each guardrail lives |
docs/DECISIONS.md |
Every decision I made for you, with its alternative and why it lost |
docs/BUILD-LOG.md |
The whole build, including the bugs and the dead ends |
docs/04-concurrency.md |
The measured concurrency curve. The Media Engine is one block. |
docs/ROADMAP.md |
Where it is, what's left, what's known-broken |
The Media Engine pool defaults to 2 — measured, at the knee, not guessed
(docs/04-concurrency.md). On M1 Pro the curve is flat:
| N | aggregate fps | speedup |
|---|---|---|
| 1 | 217.9 | 1.00× |
| 2 | 223.0 | 1.02× |
| 4 | 221.3 | 1.02× |
| 8 | 213.3 | 0.98× |
Eight concurrent encodes are 2% slower than one at a time. The Media Engine is a
fixed-function block, not a thread pool; extra sessions queue rather than parallelise.
Re-measure on your own machine with vtcompress bench <folder> — an M1 Max has two encode
engines and should look different.
Tools/snapshot-check.sh out/ # renders 27 states, fails on blanks — then LOOK at out/
Tools/glass-harness.sh glass/ # glass fidelity; needs a real desktop sessionsnapshot-check.sh renders every state (empty, scanning, encoding, mixed, all-skipped,
failed, complete, 10,000 rows, one row, longest-filename, light/dark, accent colours, RTL)
and fails if any came out blank or if the states stop differing from each other — the
exact way the first version of this harness lied. Passing it is not the same as it looking
right; open the PNGs.
-
Glass fidelity is unverified — and the harness that was supposed to verify it was broken. Liquid Glass samples what is behind the window, so an offscreen render cannot show it. That much was right, and it is why the brief specifies two harnesses. Everything after it was wrong. An earlier version of this file said
glass-harness.sh"does it properly but needs a real desktop session." It had in fact already run, in a real session, and produced five PNGs. They were worthless, and worse than worthless:- Its window-ID lookup asked System Events for an AppleScript window id, which is a
different number space from the CGWindowID that
screencapture -lrequires. It could never have worked. - On failure it fell back to
screencapturewith no-l— a grab of the entire display. All five took that path. They captured the desktop, including an Apple Account name, the Accessibility and Screen-Recording permission lists, and an unrelated app's window. They were committed to a public repo. - Not one showed the app over the test wallpaper the harness had just set. The window sat on top of an editor, so the glass sampled that. The busy-vs-flat comparison the harness exists to perform was never actually run.
The fallback is now deleted:
-l <wid>or fail loudly. A capture of the desktop is no longer a code path that exists. The window-ID lookup is still wrong, so the harness currently fails rather than lies — which is the correct order to fix these in, but means glass fidelity remains genuinely unmeasured. - Its window-ID lookup asked System Events for an AppleScript window id, which is a
different number space from the CGWindowID that
-
The toolbar and split-view chrome are unsnapshotted.
NavigationSplitViewand.toolbarare scene-dependent and render blank outside aWindowGroup, so harness 1 renders the composed content instead. SeeDECISIONS.mdD-009. -
Dynamic Type is uncovered on macOS.
dynamicTypeSizeis an iOS concept;.accessibility5and.xSmallrender pixel-identical. macOS scales text system-wide instead. -
MKV/WebM needs ffmpeg installed — optional, and only to repackage. AVFoundation has no Matroska demuxer (measured,
AVError -11828). If ffmpeg is present, the file is stream-copied (-c copy, no re-encode, ~0.8 s for a 190 MB lecture) into a container AVFoundation reads; the pixels VideoToolbox sees are bit-identical to the source. If it is absent, the file is skipped with a reason that says so and how to fix it. Nothing links against ffmpeg and it never encodes — exactly what the brief specified.DECISIONS.mdD-003 previously claimed this was an unresolvable contradiction in the brief; it was a misreading, and it is retracted. -
No AV1 encoder exists on this SoC. Measured, not assumed.
-
A mirrored output tree needs a destination volume with room. 363 GB does not fit in the 29 GB free on this machine.
-
No XPC helper yet. A malformed file that crashes VideoToolbox currently takes the app with it. The helper is the right call and is designed in
ARCHITECTURE.md; it is not built. -
No software fallback tier. Measured (
docs/03-calibration.md): x265 does not clear the gate either, so it would add a second encode path and 10–30× wall time to returnskipped: no-gainmore slowly. SeeDECISIONS.mdD-007.