Pretty much what the title says: I have a couple of video files and would like to extract one second intervals every sixty seconds or so, i.e. extract the clips

00:59 - 01:00 01:59 - 02:00 etc.

Then I would like to join all of these individual clips.

Is there an easy way to do this?

1 Answer 1


ffmpeg, a command-line tool, can do this in one command.

Update: New template, first below, is easier to manipulate (and understand)

This is a generalized command template:

ffmpeg -i input -filter_complex "[0:v]select='gte(mod((t\-FS),I),0)*lt(mod((t\-FS),I),D)', setpts=N/TB/FRAME_RATE[v];  [0:a]aselect='gte(mod((t\-FS),I),0)*lt(mod((t\-FS),I),D)', asetpts=N/SR/TB[a]" -c:v libx264 -crf 23 -map "[v]" -map "[a]" -fflags +genpts output.mp4

Alternate method:

ffmpeg -i input.mp4 -filter_complex "[0:v]select=isinf(t\/(mod(D*trunc(1+(t/D))\,Interval))),setpts=N/TB/FRAME_RATE[v];[0:a]aselect=isinf(t\/(mod(D*trunc(1+(t/D))\,Interval))),asetpts=N/SR/TB[a]" -c:v libx264 -crf 23 -map "[v]" -map "[a]" -fflags +genpts output.mp4

This is the first command formatted for full visibility

ffmpeg -i input -filter_complex \
"[0:v]select='gte(mod((t\-FS),I),0)*lt(mod((t\-FS),I),D)', \
setpts=N/TB/FRAME_RATE[v]; \
[0:a]aselect='gte(mod((t\-FS),I),0)*lt(mod((t\-FS),I),D)', \
asetpts=N/SR/TB[a]" \
-c:v libx264 -crf 23 -map "[v]" -map "[a]" -fflags +genpts output.mp4

Basically, replace input with your source video filename, output.mp4 with your intended output name.

Replace D with duration of segment, I for gap between the start of two segments and FS with start time of first segment . So, for 3-second segments every 45 seconds, starting at 36 seconds, from a file called fullfile.mp4, the command will be

ffmpeg -i fullfile.mp4 -filter_complex \
"[0:v]select='gte(mod((t\-36),45),0)*lt(mod((t\-36),45),3)', \
setpts=N/TB/FRAME_RATE[v]; \
[0:a]aselect='gte(mod((t\-36),45),0)*lt(mod((t\-36),45),3)', \
asetpts=N/SR/TB[a]" \
-c:v libx264 -crf 23 -map "[v]" -map "[a]" -fflags +genpts output.mp4

These segments will be extracts from seconds 36 to 39, 81 to 84..etc

Download ffmpeg for Windows (32-bit static build) from here.

  • The joining part is easy compared to this. Just link to a concat question. Perhaps you should mention for OP that this method of cutting involves re-encoding. You could use -ss with -c copy to get slightly less accurate clips (depending on source codec) and avoid encoding.
    – jiggunjer
    Dec 19, 2015 at 19:02
  • In case, it's not clear, both commands both extract and join the segments into one clip. How will ss allow selection of all segments in one go?
    – Gyan
    Dec 19, 2015 at 19:11
  • I was thinking some kind of script, not all in one go. Also OP mentions he has several inputs, so he will probably need to run your command for each input and concat the results.
    – jiggunjer
    Dec 19, 2015 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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