Video Covers and Thumbnails
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Baseline date: 2026-10-07. A video needs at least one still image: the poster shown before playback starts, a cover in lists and grids, and often a strip of sprites for hover previews. All three come from frames of the video, produced once, by a worker, after the upload. They are then handled as images, see image formats and responsive variants.
Extracting one frame
The FFmpeg commands on this page were run against FFmpeg 9.0.2 (the linuxserver/ffmpeg Docker image), and the Node.js code
against Node.js 24 with sharp 0.35 and blurhash 2.0.5.
# Fast and accurate: -ss before -i seeks to the previous keyframe, then decodes to the exact time.
ffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 -q:v 2 cover.jpg
# Slow: -ss after -i decodes and discards everything before the time. Rarely needed.
ffmpeg -i input.mp4 -ss 00:00:05 -frames:v 1 -q:v 2 cover.jpg
-
-ssbefore-iis an input option. FFmpeg seeks to the nearest keyframe before the time and then decodes to the exact point, which is fast and accurate in current FFmpeg versions. Placing-ssafter-idecodes everything before the time and discards it. -
-frames:v 1stops after one video frame. -
-q:v 2sets JPEG quality (lower is better, 2 to 5 is the useful range). For WebP or AVIF output, give the encoder’s own quality options instead. -
Apply the rotation: FFmpeg autorotates by default when it re-encodes using the display matrix of the stream, and you can force the issue with
-autorotateor check with ffprobe (-show_entries stream_side_data=rotation). Phones record landscape pixels and flag the video as rotated, so a cover that ignores this one is sideways.-noautorotateturns the behaviour off, which is only useful to reproduce the problem. -
Scale in the same command (
-vf scale=720:-2) rather than producing a full-size frame and resizing it later.
References: FFmpeg main options and the FFmpeg seeking guide.
Choosing a representative frame
A frame at a fixed time is often black (fade-in), blurry (motion) or a title card. Options, from cheapest to best:
-
Fixed fraction of the duration. Take the frame at 10 percent of the video. Cheap, and avoids intros.
-
The thumbnail filter. The
thumbnailfilter looks at a batch of consecutive frames (100 by default) and picks the one that is the most typical, which means the closest to the batch’s colour histogram average. It avoids black frames and transitions most of the time.ffmpeg -ss 00:00:03 -i input.mp4 -vf "thumbnail=n=300,scale=720:-2" -frames:v 1 cover.jpg -
Scene detection. The
selectfilter can pick frames where the content changes, using thescenescore:ffmpeg -i input.mp4 -vf "select=gt(scene\,0.4),scale=480:-2" -fps_mode vfr scene_%03d.jpgThe backslash escapes the comma inside the filter expression. Scene frames are a good source of candidate covers.
-
Let the user choose. Extract eight to twelve candidates, show them in the uploader, and store the choice. A user-chosen frame beats any heuristic for editorial content.
-
Analysis. Score candidates for sharpness (variance of the Laplacian), faces and brightness in the worker, or use a managed analysis service such as Azure AI Video Indexer or a vision model.
Remember to skip frames at the very end of the video and to fall back to a fixed time when a clip is shorter than the
thumbnail batch.
Sprite sheets for scrubbing previews
A sprite sheet is one image holding a grid of small frames sampled at regular intervals. A player shows the right tile when the user hovers or drags on the progress bar, with one request for the whole strip.
# One frame every 10 seconds, 160 px wide, laid out as a grid of 10 columns by 10 rows.
ffmpeg -i input.mp4 -vf "fps=1/10,scale=160:-2,tile=10x10" -frames:v 1 sprites.jpg
Use a second small file, usually a WebVTT track with #xywh= fragments (the format Video.js and Shaka Player
thumbnails plugins expect), to map time ranges to tiles. Cap the number of tiles, and split into several sheets for
very long videos.
Some services produce sprite sheets for you, for example the Google Cloud Transcoder API (see the Google Cloud page).
BlurHash on the cover
Treat the chosen cover like an uploaded image: downscale it to about 64 pixels, compute the BlurHash and store it next to the cover metadata, see BlurHash. The frontend shows the blurred cover in the video card and as the poster while the poster image loads, see video playback on the web.
Worked example: a cover for the Bookshelf trailer
The running example is the trailer of the Bookshelf platform, a 20 second 1080p clip with a hard scene cut at 10 seconds (the synthetic clip described in encoding fundamentals). The cover worker has to produce a poster, a BlurHash for it and a scrubbing strip, with no human in the loop unless the uploader wants one:
Extracting the candidates is one FFmpeg command. Sampling in the middle of each slot keeps the first frame, which is often a
fade from black, out of the set, and fps=1/<slot> yields one frame per slot:
# 8 candidates from a 20 s video: slot = 2.5 s, first sample at 1.25 s, 480 px wide
ffmpeg -ss 1.25 -i trailer.mp4 -vf "fps=1/2.5,scale=480:-2" -frames:v 8 cands/cand_%02d.jpg
Scoring is a few lines with sharp. Sharpness is the variance of the Laplacian response of the grey image (the classic
focus measure), and brightness is the mean grey level. The offset: 128 in the kernel keeps negative responses, because an
8 bit result would otherwise clip them to zero and halve the signal:
import sharp from 'sharp';
const LAPLACIAN = { width: 3, height: 3, kernel: [0, 1, 0, 1, -4, 1, 0, 1, 0], scale: 1, offset: 128 };
export async function score(file) {
const grey = sharp(file).greyscale();
const { channels: [tone] } = await grey.clone().stats();
const { channels: [edges] } = await grey.clone().convolve(LAPLACIAN).stats();
return { brightness: tone.mean, sharpness: edges.stdev ** 2 };
}
export async function pickCover(candidates) { // [{ file, time }]
const scored = [];
for (const c of candidates) scored.push({ ...c, ...(await score(c.file)) });
const usable = scored.filter((c) => c.brightness > 30 && c.brightness < 225); // not black, not blown out
return (usable.length ? usable : scored).reduce((a, b) => (b.sharpness > a.sharpness ? b : a));
}
On the trailer the eight candidates print:
t=1.25 brightness=124.9 sharpness=14960.2
t=3.75 brightness=124.3 sharpness=15126.2
t=6.25 brightness=128.9 sharpness=13225.0
t=8.75 brightness=124.5 sharpness=15149.5
t=11.25 brightness=165.1 sharpness=7383.4
t=13.75 brightness=119.1 sharpness=7386.0
t=16.25 brightness=91.0 sharpness=6204.8
t=18.75 brightness=71.5 sharpness=6583.7
and the worker picks the frame at 8.75 seconds. The test pattern of the first half is full of edges and the fractal of the
second half is smooth, so the first half wins, which shows what the measure does and does not mean: it ranks candidates of
one video against each other and favours busy frames. It does not know what is a good composition, which is why the
candidate frames are also what an uploader gets to choose from. Compare sharpness only between frames of the same size, and
treat it as a tie-breaker after the brightness filter, not as the decision. The BlurHash of the picked frame (computed with
the function of the Node.js page, 64 pixel copy, 4 by 3 components) was LXKn#e|,jX_gxbX3W-rxj[WCbZjb.
What the other extraction methods returned
On the same trailer, every command of the sections above ran as written, and returned:
| Command | Result |
|---|---|
|
Two byte-identical 1920 by 1080 JPEG files. The placement changes how FFmpeg gets there (seek and decode, or decode and discard), not the frame it returns, so the fast form is the right default. |
|
One 720 by 406 JPEG. The height is 406 because |
|
Exactly one frame, 480 by 270, and its timestamp is 10 seconds: the scene cut. On footage with many cuts this yields many candidates, so cap the count. |
|
Succeeds and picks among the frames that exist, so no special case is needed for the end of a clip. |
Sprite sheets in detail
The tile filter fills a grid row by row, so the frame with index sits at:
where is the number of columns and by is the size of one tile. The sheet always has the full
grid size: fps=1/10,scale=160:-2,tile=10x10 on the 20 second trailer holds two frames and still wrote a 1600 by 900 image,
the unused tiles are padding. Compute the grid from the duration instead of fixing it, so a short clip does not ship a
mostly empty sheet:
# one frame every 2 s from a 20 s video is 10 frames: a 5 by 2 grid, and the sheet is 800 by 180
ffmpeg -i trailer.mp4 -vf "fps=1/2,scale=160:-2,tile=5x2" -frames:v 1 sprites.jpg
The WebVTT file that maps time to tile is generated from the same numbers. The function below is the one used for the trailer, and the three first cues it wrote are shown after it (the tile is 160 by 90 pixels):
export function spriteVtt(url, total, interval, columns, tileW, tileH) {
const stamp = (s) => new Date(s * 1000).toISOString().slice(11, 23); // HH:MM:SS.mmm
const cues = ['WEBVTT', ''];
for (let i = 0, t = 0; t < total; i++, t += interval) {
const x = (i % columns) * tileW, y = Math.floor(i / columns) * tileH;
cues.push(`${stamp(t)} --> ${stamp(Math.min(t + interval, total))}`, `${url}#xywh=${x},${y},${tileW},${tileH}`, '');
}
return cues.join('\n');
}
// spriteVtt('sprites.jpg', 20, 2, 5, 160, 90)
WEBVTT
00:00:00.000 --> 00:00:02.000
sprites.jpg#xywh=0,0,160,90
00:00:02.000 --> 00:00:04.000
sprites.jpg#xywh=160,0,160,90
00:00:04.000 --> 00:00:06.000
sprites.jpg#xywh=320,0,160,90
The cue for second 7 is the fourth one, xywh=480,0,160,90, which is why the player needs one request for the sheet and
no request per hover. A JPEG side is limited to 65535 pixels and a large sheet costs memory and decode time on the device, so a long video
needs several sheets. At one tile per 10 seconds, a 10 by 10 sheet covers about 17 minutes. Start a new sheet after that, with
the cue URL naming the sheet it belongs to.
Rotation, measured
A phone holds the camera upright and records landscape pixels, so rotated video is the norm. The container stores the rotation
as display matrix side data and the decoder is expected to apply it. To see the effect, the trailer was remuxed with a
display rotation of 90 degrees (ffmpeg -display_rotation 90 -i trailer.mp4 -c copy rotated.mp4, an input option) and the
frame at 1 second extracted three ways:
| Command | Size | Meaning |
|---|---|---|
|
1920 by 1080, rotation 90 |
The pixels are landscape and a flag says to turn them. |
|
1080 by 1920 |
The rotation was applied, which is what you want. |
|
1920 by 1080 |
The raw pixels: a sideways cover. |
|
720 by 1280 |
The filters run after the rotation, so |
Two consequences: apply size limits to the upright dimensions (read them from ffprobe and swap width and height when the rotation is 90 or 270), and never re-apply the rotation in your own code after FFmpeg has done it.
The same operations in managed cloud services
| Service | How to get covers and thumbnails |
|---|---|
AWS Elemental MediaConvert |
Add a frame capture output to the job. It writes JPEG frames at a chosen rate or count. See frame capture and thumbnails. |
Google Cloud Transcoder API |
Add a sprite sheet or a set of frames to the job configuration. See the Google Cloud page. |
Azure |
Media Services is retired. Run FFmpeg in a Container Apps job, or analyse with Video Indexer. See the Azure page. |
Related pages
-
Node.js and Rust Image and Video Libraries for the sharp and BlurHash code used above
-
Video Playback and Streaming in the Browser for the poster and the player that shows the sprite strip
-
Media Optimization for the web and Media Optimization in apps