(FFmpeg) How to extract screenshots from multiple parts of a video (one-liner)?

This question was asked on the FFmpeg Discord. For some reason the person pinged me to answer it so I took a stab at it. Here was the request:

@jdriselvato Hey, I’ve got a question if something is even possible. I want to do. but for multiple seek times and output names (those I guess can be generated from timestamp) with a single pass. Is this possible at all? There is no interval, just “random” times from the video where I want to extract a screenshot

Mr. n

So to clarify, the user was having issues understanding how to chain multiple seeking (-ss) with one input to get random frames from the video. This is possible in a couple of ways. First you must have an understanding how -ss works. It has to be set before the input. What happens here is the input is seeking to a new timestamp for a start location for playback. (for example, the video is 60 seconds long -ss 00:00:10 would jump the start point of the video at the 10-second mark making the video only 50 seconds long in total).

So using that logic, if we set the seeking on the input to get a screenshot out and then applied another seeking with a map the results are going to get tricky, for example:

$ ffmpeg -ss 00:00:05 -i input.mp4 -frames:v 1 frame_1.png -map 0:v -ss 00:00:10 -frames:v 1 frame_2.png

Here the input is 60 seconds long we automatically start the video at 5 seconds to get the first screenshot but then another 10 seconds is seeded to get a screenshot at the 15th second of the original input. This technically works but you have to do math against the input starting at 5 seconds.

but we are heading in the right direction. the use of -map is what we want to focus on. In this example, we do not do anything to the input but specifically apply seeking to the same map multiple times to get screenshots are specific locations, for example:

ffmpeg -i input.mp4 -map 0:v -ss 00:00:05 -frames:v 1 frame_1.png -map 0:v -ss 00:00:10 -frames:v 1 frame_2.png

This answer was satisfactory and exactly what he wanted to learn. Not bad for waking up only an hour ago.

Here’s an example Mr. N used to manually get this working before working with me to get the above code:

ffmpeg -hide_banner -v quiet -stats -ss 00:45 -i input -ss 00:50 -copyts -vframes 1 output & ffmpeg -hide_banner -v quiet -stats -ss 01:45 -i input -ss 01:50 -copyts -vframes 1 output

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon