Take Screenshot from Video with FFmpeg

How to capture a frame from a selected timestamp of a video by using FFmpeg

Consider following case. You have a video file that you want to show a screenshot on a web page. But you don’t want to do it manually. Instead, you already have the exact time stamp of the video you want to take the screenshot.

It’s very simple to do that with FFmpeg. The following is the syntax to do that.

ffmpeg -i input.mp4 -ss 00:00:01 -vframes 1 output.jpg

Where input.mp4 is the name of video file you want to take a screenshot of and output.jpg is the output image file. You can change the -ss parameter and choose your own timestamp. The format is hh:mm:ss where hh is the hour, mm is the minute, and ss is the second part of the timestamp.

In the example above, I choose the timestamp at 1 second after video start.

Take screenshots from multiple videos

You probably have multiple videos at home. You actually can take screenshot in batch mode. The following command can be used to take screenshot from multiple videos.

find . -name "*.mp4" -exec \
  ffmpeg -i {} -ss 00:00:01 -vframes 1 {}_screenshot.jpg \;

Simplify using Bash Function

To make the command easy to remember, you can also create a bash function out of it. The following snippet is the bash function I use at home.

function ffmpeg-screenshot()
{
  ffmpeg -i $1 -ss 00:00:01 -vframes 1 $2
}

With the previous bash function, the command can be simplified like following example.

ffmpeg-screenshot input.mp4 output.jpg

Conclusion

As you can see, FFmpeg is very powerful video manipulation tool. You can do anything with it, the limit is your imagination.

Thank you for reading!

References