My use-case is just one thumbnail from a video, just a single file to use as a
<video> tag poster. So, what would be a fast way to make this?
ffmpeg, you can do this:
ffmpeg -ss 123 -y -i video.mp4 -r 1 -updatefirst 1 -frames 1 poster.jpg
That will give you the frame near second
123 of the
video.mp4 saved as
The problem, as you can see, is that we need to know which second is right.
In order to keep our dependencies low, we'll use ffmpeg itself for this:
# Get the time as h:m:s (non-padded)
l=$(ffmpeg -i video.mp4 2>&1 | grep Duration: | sed -r 's/\..*//;s/.*: //;s/0([0-9])/\1/g')
# Convert that into seconds
s=$((($(cut -f1 -d: <<< $l) * 60 + $(cut -f2 -d: <<< $l)) * 60 + $(cut -f3 -d: <<< $l)))
# Get frame at 25% as the thumbnail
ffmpeg -ss $((s / 4)) -y -i video.mp4 -r 1 -updatefirst 1 -frames 1 poster.jpg
25% of the video seems like a common choice, but you can make it 33% or 50% too.
Here's a script that does this.