<p>ffmpeg, a command-line tool, can do this in one command.</p>

<p><strong>Update</strong>: New template, first below, is easier to manipulate (and understand)</p>

<p>This is a generalized command template:</p>

<pre><code>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
</code></pre>

<p>Alternate method:</p>

<pre><code>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
</code></pre>

<p>This is the first command formatted for full visibility</p>

<pre><code>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
</code></pre>

<p>Basically, replace <code>input</code> with your source video filename, <code>output.mp4</code> with your intended output name.</p>

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

<pre><code>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
</code></pre>

<p>These segments will be extracts from seconds 36 to 39, 81 to 84..etc</p>

<p>Download ffmpeg for Windows (32-bit static build) from <a href="http://ffmpeg.zeranoe.com/builds/" rel="nofollow">here</a>.</p>

CC BY-SA 3.0
2015-12-19T19:02:28.900Z
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
CC BY-SA 3.0
2015-12-19T19:11:03.750Z
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
CC BY-SA 3.0
2015-12-19T19:30:40.743Z
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
CC BY-SA 3.0
2015-12-18T18:24:45.350Z
2015-12-19T05:50:33.857Z
2015-12-19T05:50:33.857Z
Gyan
<p>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 </p>

<p>00:59 - 01:00
01:59 - 02:00
etc.</p>

<p>Then I would like to join all of these individual clips. </p>

<p>Is there an easy way to do this?</p>

<video><editing>
Easy way to take 1s clips from video every 60s and join them all together?
Max
# Easy way to take 1s clips from video every 60s and join them all together?

(Asked by: username_0 on 2015-12-18)

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?

**Tags:** video, editing


---

## 1 answers

### Answer by username_1 on 2015-12-18. Score: 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.

> **Comments:**
> **username_2**: 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.  
> **username_1**: 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?  
> **username_2**: 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.  

---

