0

I am using ffmpeg to extract still images from a video. From a given time, for a given duration using the -ss and -t parameters.

ffmpeg -ss 00:10:01 -t 2 -i /Volumes/OO_8/VideoSource.mkv -qscale:v 2 -start_number  /Users/Olivier/Pictures/ScreenCaptures/ViewsOfNature-%4d.jpeg

(I start with the timestamp/duration first so that ffmpeg starts the demux at at that point.)

However, I want to use several starting points (for example, at 00:01:12 in, extract the images for 2 seconds; at 00:11:00 minutes in, extract the images for 4 seconds; etc.) I can do this manually, replacing the timestamp and duration, and moving the output images each time, but ideally I want to input the timestamps and durations all at once, and not overwrite the output images. Is there a way to do this? Perhaps with an external file with the timestamps/durations?

I am new to this, and prefer to do it with ffmpeg only, not use bash.

1 Answer 1

1

I don't see a way to do it with ffmpeg easily. There is a segment muxer but you can't set the duration of segments.

There's nothing stopping you from doing it like this, which I believe is fairly simple. Just create a text file containing a comma-separated list of start points and durations:

$ cat split.txt
00:01:05,5
00:06:10,2
00:08:25,1

And then in Bash:

count=1
while read -r -d ',' start duration; do
  ffmpeg -ss "$start" -i input.mp4 -t "$duration" "$count-output-%04d.jpg"
  (( count++ ))
done < split.txt

This will create output files starting with a unique number (1, 2, 3, …).

3
  • I tried also with 00:01:02.01 (the last being the frame) and that seemed to solve it, but still sometimes a timestamp is refused. Playing around with the values seems to solve (increasing or decreasing) seems to solve it. I suspect it is with ffmpeg not finding such a position in the source file. I have tried random positions so far. Will try with actual positions I need and get back on this.
    – OlivierOO
    Commented May 23, 2015 at 11:20
  • I think it was a format / file reading issue with Bash. The timestamp is HH:MM:SS.msec and that should always work. Note that it's not frames. When it doesn't find a frame at the specified time, it'll take the next one.
    – slhck
    Commented May 23, 2015 at 11:21
  • I now have: 00:01:02.000 1.5 00:10:06.000 2 00:12:01.030 2 00:16:06.050 1 This works. (The 1.5 value for the duration in the last line I tried later, that works too.)
    – OlivierOO
    Commented May 23, 2015 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .