brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: put ffmpeg -ss before -i to jump to a time and grab one frame

Ffmpeg
~/tips/tip-ffmpeg-ss-before-input-thumbnail

ffmpeg -ss 00:01:30 -i input.mp4 -frames:v 1 thumbnail.png

Seeks to a timestamp before reading the file, then saves a single frame as an image.

To make a thumbnail from a long video I do not want ffmpeg to decode the first hour. Where you place -ss on the command line decides how it seeks.

The ffmpeg docs say that, used as an input option before -i, -ss seeks in the input file to the position you give. A single frame at one minute thirty then looks like this:

ffmpeg -ss 00:01:30 -i input.mp4 -frames:v 1 thumbnail.png

-frames:v 1 stops writing after one video frame. The docs list -vframes as an obsolete alias of it and recommend the first form. The result is one image file at that moment of the video.

The position matters more than the option name. Put -ss after the input, before the output name, and ffmpeg decodes but discards everything until the timestamp is reached. That is correct but slow for a long file. Before -i, it seeks first.

The docs mention that exact seeking is not always possible, so ffmpeg goes to the closest seek point before the position. When you transcode, which is the case for a PNG, it decodes the stretch between that seek point and your position and discards it. So the frame you get is the one you asked for.

Stream copy behaves differently. With -c copy or -noaccurate_seek that extra stretch is kept instead of discarded, so a cut can start a little earlier than you typed. For a thumbnail that does not matter. For a clip you want to copy without re-encoding, check the start of the output.

Also remember that ffmpeg applies options to the next file you name, so an option placed on the wrong side of -i works on the other file, or on nothing.

Further reading: ffmpeg Documentation: main options

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link