0

I get a screenshot from a remote video file using ffmpeg with a command like ffmpeg -ss $TIME -i $URL -frames:v 1 -filter:v $FILTER file.jpg (-ss comes before -i for fast seeking https://trac.ffmpeg.org/wiki/Seeking). $FILTER is how I want to transform the screenshot, like cropping/resizing. In this case it's "crop=iw-5:ih-5, scale=100:100:force_original_aspect_ratio=increase, crop=100:100")

If I want to get 3 screenshots, at 3 seconds, 5 seconds, and 14 seconds, I need to run this command 3 separate times, passing 3, 5, and 14 as $TIME. But is it possible to run the command once but have it output multiple screenshot files for the different times?

And would ffmpeg do that in a way where it would make the round-trip remote request just 1 time instead of 3? In that case it would be more efficient. If not, then maybe it's better to make the 3 requests separately since I could do it in parallel.

1 Answer 1

3

For screenshots at equal intervals see the wiki.

For specific timestamps you can do it in one pass using the select filter:

ffmpeg -i <input> -filter:v "select='0-eq(t,3)-eq(t,5)-eq(t,14)',<other filters>" -vsync vfr file%01d.png

where t is the presentation timestamp in seconds.

You could also search for I-frames in specific intervals using between and pict_type PICT_TYPE_I.

6
  • 1
    Maybe, add input -t 15 to avoid filtering the whole file.
    – Gyan
    Commented Nov 9, 2017 at 10:58
  • @aergistal So I don't actually use the letter t in the command? What is meant by presentation timestamp?
    – user779159
    Commented Nov 9, 2017 at 11:05
  • 2
    @Mulvya 15 is because the last screenshot is at 14? Let's say the video is 2000 seconds and the last screenshot I need is at 1995, then I would be filtering the whole file anyway? Is there a way to do it where it just gets the part of the file you want, as it does in the command in my original question (but for many screenshots rather than just one).
    – user779159
    Commented Nov 9, 2017 at 11:07
  • @user779159 there's a link to the filter documentation in case you've missed it
    – aergistal
    Commented Nov 9, 2017 at 11:11
  • @aergistal I see it says The PTS (Presentation TimeStamp) of the output audio frame, expressed in TB units. but I don't know what that means.
    – user779159
    Commented Nov 9, 2017 at 13:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.