← All projects Focused build Operational
Video recompression under a quality contract
A recompression service that binary-searches encoder quality against SSIMULACRA2, re-measures the full output independently, and refuses to ship below its contract.
Result and scope
I built a video-recompression service that reduced 112 accepted files from 6.87 GB to 2.55 GB (62.9%), with every accepted output passing the recomputed quality contract. Those byte totals exclude the workload’s other 41 skipped files and 9 errors. This is a maintained internal tool, not a customer-scale service or a claim of visually lossless compression.
The decision: verify the output, not just the sample
Short reference windows make searching an encoder’s quality setting affordable, but they can overestimate the quality of the eventual output. I separated the search from acceptance: binary-search a candidate setting, encode the full file, then independently re-measure it. If it misses, retry with a more conservative setting within a bounded budget; never deliver an output that still fails.
That separation changed the result: 39 of the 112 accepted files needed the retry loop. The selected contract was average SSIMULACRA2 of at least 70, with no measured window below 50. For 54 older records, the floor was reconstructed from the service’s then-current constant rather than a per-file field.
Making the process usable
Uploads resume by SHA-256, persisted batches recover after restarts, and originals are replaced only after the downloaded result passes hash validation. Non-beneficial work is skipped, and errors retain machine-readable reasons. The engineering problem extends beyond encoding: an interruption or optimistic estimate must not silently turn into a bad replacement file.
Built with
- Python (stdlib HTTP)
- ffmpeg/ffprobe
- vvenc (VVC)
- SSIMULACRA2
- systemd