0

I have a folder with videos files and need to extract 2+ frames from each of these, using a bash script on Linux. Currently I am doing this for each video file in a loop:

ffmpeg -nostdin -loglevel fatal -ss 15 -i "${filename}" -frames:v 1 "${out1}"
ffmpeg -nostdin -loglevel fatal -sseof -15 -i "${filename}" -frames:v 1 "${out2}"

This extracts a frame 15s in and another frame 15s from the end. For N video files I need 2N ffmpeg calls. I experimented with -vf select, as was asked here, but this was much slower, especially with the requirement to select frames from the beginning and from the end. Also, I am already using GNU parallel which makes a big difference.

Performance is actually not too bad. But my question is, can this be improved further? I am hoping for a way to

  • to extract both frames in one ffmpeg call (faster than two separate calls), or
  • to feed ffmpeg more than one file per call (to reduce process startup overhead)
Werner Lehmann
  • 911
  • 1
  • 8
  • 14

1 Answers1

2

You can ingest the same input multiple times, as well as multiple inputs in the same command.

Basic command structure is

ffmpeg -nostdin -loglevel fatal
       -ss 15     -i "${filename}"
       -sseof -15 -i "${filename}"
       -ss 15     -i "${filename2}"
       -sseof -15 -i "${filename2}"
       -map 0:v:0 -frames:v 1 "${file1-head}"
       -map 1:v:0 -frames:v 1 "${file1-tail}"
       -map 2:v:0 -frames:v 1 "${file2-head}"
       -map 3:v:0 -frames:v 1 "${file2-tail}"
...

I doubt this will lead to a large improvement for a small set of files.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • 1
    Exactly what I was looking for, thanks. Takes 1/3 less time for 1000 video files if I process 15 files per ffmpeg call. This is of course just for my script, using GNU parallel on an 8-core machine and including some constant time required for additional processing, so it is not a general benchmark. But the speedup is significant. – Werner Lehmann May 11 '19 at 11:17