Overview
Every media application needs derivatives: a poster frame for the player, a strip of thumbnails for scrubbing, and often a low-resolution proxy for browsing. Generating them is straightforward until you meet real user media, at which point you discover black first frames, files that resist seeking, and variable frame rates that make timestamps unreliable. This guide covers building a derivative pipeline that survives that.
What You Need
- A processing toolchain, pinned in a container
- A job queue, since derivative generation should not block anything
- Storage for derivatives, with a policy on regenerating rather than backing up
- A deterministic naming scheme linking derivatives to their source
- Test media including awkward cases, black openings, VFR, rotated, very short
- A decision about which derivatives are generated eagerly and which on demand
Steps
Do not take the first frame as your poster
Many videos begin on black, on a fade, or on a slate. A naive first-frame poster produces a library of black rectangles. Sample several frames from across the file and choose one, scoring candidates on brightness and variance so you reject flat and near-black frames automatically.
Generate the scrubbing strip as a sprite sheet
Preview-on-hover works by showing a thumbnail for the position under the cursor. Rather than fetching hundreds of small images, generate one sprite sheet containing thumbnails at a fixed interval plus a metadata file describing the grid. One request rather than hundreds, which matters considerably on a long video.
Handle files that resist seeking
Seeking to arbitrary timestamps is fast in well-formed files and slow or inaccurate in others: files without a proper index, streams with sparse keyframes, or variable frame rate media. For those, sequential decoding while emitting frames at intervals is slower but reliable. Detect and fall back rather than producing wrong thumbnails.
Make derivatives deterministic and regenerable
Derive output paths from the source identifier and the generation parameters, so the same input always produces the same derivative path. This makes the job idempotent, makes retries safe, and means derivatives can be deleted freely and regenerated rather than backed up, which is a substantial storage saving.
Decide what is eager and what is on demand
Poster frames are needed immediately and should be generated at ingest. Full scrubbing strips for a large archive may never be viewed, and generating them for everything is wasted compute. Generating on first request and caching is frequently the better trade for anything beyond the poster.
Version your derivative generation
Record which version of the pipeline produced each derivative. When you change thumbnail dimensions or improve frame selection, that field tells you what needs regenerating rather than forcing a full rebuild of the archive.
Pro Tips
- Score candidate frames and reject near-black or flat ones. It is a few lines and it fixes the most visible defect.
- Sprite sheets beat hundreds of individual thumbnail requests for scrubbing previews.
- Derivatives should be cheap to delete. If regenerating is painful, the pipeline needs fixing.
- Test with a video that opens on ten seconds of black. It is extremely common and breaks naive implementations.
- Generate proxies at ingest if editors will browse the archive. It is the largest storage lever available.
Knowledge Base
What You'll Learn
Derivative generation is simple in principle and breaks on real media. Below: why choosing a frame is harder than it looks, and why derivatives should be regenerable rather than precious.
Why Choosing a Poster Frame Is Harder Than It Looks
Taking a frame from a video sounds trivial and produces poor results at scale, for reasons that only appear across a large library.
Openings are frequently unrepresentative. Videos begin on black, on fades, on slates, on countdown leaders, or on a title card. The first frame is therefore among the worst candidates available.
A fixed offset is not much better. Taking a frame from ten seconds in fails on anything shorter, and on longer videos frequently lands mid-transition or on a cutaway.
The approach that works is sampling and scoring: extract candidate frames from across the duration, then score them on measurable properties, mean brightness to reject black and blown frames, variance or edge density to reject flat ones, and sometimes face detection where a person is likely to be the subject. Choose the best-scoring candidate.
This is not sophisticated and it is dramatically better than any fixed rule. It is the difference between a library that looks curated and one full of black rectangles, and it costs a few extra seconds per asset at ingest.
Derivatives Should Be Regenerable, Not Precious
The architectural principle that makes derivative pipelines maintainable is that derivatives are disposable.
If every derivative can be regenerated deterministically from its source plus recorded parameters, several things become easy. They do not need backing up, which is a meaningful storage saving across a large archive. They can be deleted when storage is tight. A change to thumbnail dimensions or preview quality becomes a regeneration job rather than a migration. And a corrupted derivative is a re-run rather than an incident.
Achieving this requires two disciplines. Deterministic paths derived from the source identifier and parameters, so the same inputs always produce the same location, which also makes jobs idempotent and retries safe. And recorded generation parameters and pipeline version, so you know exactly what produced each derivative and what needs regenerating.
The failure mode to avoid is derivatives that were generated once by a process nobody recorded, cannot be reproduced, and therefore have to be backed up and preserved like masters, which is exactly the storage cost you were trying to avoid.
Where This Fits
This guide covers one specific part of building media applications. The wider picture, why media workloads break ordinary web architecture, and the upload, job, and toolchain patterns that handle them, is in Building Media Applications: A Developer Primer, which frames the discipline as a whole and links out to the detailed guides underneath it, including this one. If you are starting from scratch rather than solving a specific problem, read that first and come back here.
FAQ
Q: How do I stop poster frames coming out black?
A: Sample several candidate frames from across the video and score them, mean brightness to reject black and blown frames, variance or edge density to reject flat ones, then pick the best. Taking the first frame fails constantly because videos routinely open on black, fades, or slates.
Q: What is the best way to build scrubbing previews?
A: Generate a sprite sheet containing thumbnails at fixed intervals plus a small metadata file describing the grid, rather than hundreds of individual images. One request instead of hundreds makes a substantial difference on long videos and on slow connections.
Q: Should I generate all derivatives at ingest?
A: Poster frames yes, since they are needed immediately. Full scrubbing strips and proxies for a large archive may never be viewed, so generating on first request and caching is frequently the better trade. Proxies are the exception if editors browse the archive, since they are the biggest storage lever available.
Q: Do I need to back up my derivatives?
A: Not if they are regenerable. Derive output paths deterministically from the source and generation parameters, record the pipeline version, and derivatives become disposable, deletable when storage is tight and rebuildable on demand. Backing up derivatives is a sign the pipeline is not reproducible.
Translate this page
- Español
- 简体中文
- हिन्दी
- العربية
- Português
- Français
- Deutsch
- 日本語
- Русский
- Bahasa Indonesia
- 한국어
- Italiano
- Türkçe
- Tiếng Việt
- Polski
- Nederlands
Machine translation provided by Google Translate, on Google’s servers. We do not check these translations and they will get technical terms wrong. The English page is the authoritative one. Following a link sends this page’s address to Google. Your browser may also offer to translate this page itself, which keeps the request on your device.