mediacodec.dev

Extract a frame as an image

Every video player needs a poster and every article needs a still, and both are one FFmpeg line away: seek, decode one frame, encode one image. The parts worth understanding are the fast seek and JPEG’s odd quality scale.

Moment

-ss

Placed before -i, the seek jumps by the container’s index instead of decoding everything up to the point: grabbing a frame from minute 50 costs the same as one from second 3.

Image format

-q:v

Small and universal. Quality is set with -q:v.

JPEG for photographs of the real world; PNG when the frame carries text, UI or hard edges.

JPEG quality (-q:v)

-q:v
bettersmaller2

q 2: top-quality JPEG, the poster-image setting.

FFmpeg’s JPEG scale runs 2–31 and lower is better, the reverse of what most tools use. 2 is effectively the best JPEG FFmpeg will write.

Your command

ffmpeg -ss 00:00:03 \
  -i input.mp4 -frames:v 1 \
  -q:v 2 \
  thumb.jpg

Worth knowing

-frames:v 1 stops after one video frame; without it FFmpeg would happily write every frame of the file as a numbered image.

The frame you get is the first one at or after the seek point, which lands on or just past a keyframe. For the exact frame at a timestamp, move -ss after -i: slower, frame-accurate.

For a whole strip of thumbnails, swap -frames:v 1 for -vf fps=1: one image per second of video.

Run this on your own file

no FFmpeg · runs in this tab

The command above needs FFmpeg on a machine. The settings it encodes do not: your browser can perform the same operation on a real file, right here, through WebCodecs.

Drop a video or audio file here, or

Files are processed in this tab and never uploaded.

One frame through the decoder, encoded by the canvas: the browser twin of -frames:v 1.

Like the fast seek, the frame comes from the nearest keyframe at or before the moment you asked for.

-q:v 2 is mapped onto the canvas encoder's own quality scale; the two are cousins, not twins.

Waiting on a file.