<p>Using ffmpeg, a command line tool, you can use</p>

<pre><code>ffmpeg -i in.mp4 -vf select='trunc(mod(t+2,3))',setpts=N/FRAME_RATE/TB -crf 23 out.mp4
</code></pre>

<p>The <code>select</code> filter is used on the video stream. This filter evaluates the supplied expression on each frame and keeps the frame if the expression evaluates to a non-zero value.</p>

<p>The expression used is <code>trunc(mod(t+2,3))</code>. The modulo function returns the remainder of the first operand when divided by the second. The first operand here is the timestamp of the evaluated frame. The truncate function truncates that result to an integer. If it is zero, the frame is discarded, else kept.</p>

<p>e.g. for a 25 fps video</p>

<pre><code>t       t+2      mod(t+2,3)       trunc(mod(t+2,3))    select
0.00    2.00     2.00                    2             KEEP
0.04    2.04     2.04                    2             KEEP
...
0.96    2.96     2.96                    2             KEEP
1.00    3.00     0.00                    0             CUT
1.04    3.04     0.04                    0             CUT
...
1.96    3.96     0.96                    0             CUT
2.00    4.00     1.00                    1             KEEP
...
3.00    5.00     2.00                    2             KEEP
...
4.40    6.40     0.40                    0             CUT
...
</code></pre>

<p>Since you want to 'collapse' the video by removing the night time portions, the <code>setpts</code> filter is added to make all the kept frames continuous i.e. after the frame at 0.96, the next kept frame (2.00) will have the new timestamp of 1.00.</p>

<p>The video has to be recompressed since a filter has been used. For MP4s, default codec is H.264 and default encoder is libx264. The <code>-crf 23</code> sets the bitrate control method (CRF) and value (23). Lower values retain more of the source quality at the expense of larger size. 18 to 28 are typical values.</p>

<p>You can get a ffmpeg binary for your platform from <a href="https://ffmpeg.org/download.html" rel="nofollow noreferrer">https://ffmpeg.org/download.html</a>. Always get the latest nightly or snapshot build. </p>

CC BY-SA 3.0
2017-03-11T09:28:50.063Z
2017-03-11T09:28:50.063Z
Gyan
<p>I have a modified setup where I took a timelapse every 1 hour for 30 days. I want to remove 12 hours of night. I had modified Gyan's <code>select</code> with the following:</p>
<pre><code>select='trunc(mod(t*30-2\,24)/12)'
</code></pre>
<p>Here I am multiplying <code>t</code> by my frame rate of <code>30</code> to convert time to a frame number. Then I provide a frame offset of <code>-2</code> to start at a different frame. Next I take the <code>mod 24</code> since I have 24 frames in 1 day. Finally, I divide by <code>12</code> and <code>trunc</code> since I want to remove 12 frames of each day. And here is the final code.</p>
<pre><code>ffmpeg -i in.mp4 -vf select='trunc(mod(t*30-2\,24)/12)',setpts=N/FRAME_RATE/TB -crf 23 out.mp4
</code></pre>

CC BY-SA 4.0
2020-11-16T17:00:45.803Z
2020-11-16T17:00:45.803Z
Matt
<p>FYI you have to add a backslash before the comma in the select function to make it work (at least on Linux), ie:</p>

<pre><code>ffmpeg -i in.mp4 -vf select='trunc(mod(t+2\,3))',setpts=N/FRAME_RATE/TB -crf 23 out.mp4
</code></pre>

<p>Otherwise, you will get a "too many arguments" error.</p>

CC BY-SA 4.0
2019-10-19T16:12:14.353Z
2019-10-19T16:12:14.353Z
Jim Klein
<p>I want to remove night footage from a Timelapse video of construction over 300 days. So I want to remove 300 nights from this video. How do I do it in an easier way? Is there a option to cut video at predefined frame/points after regular intervals in one single command? I want to avoid manual labor. I am using adobe premier pro cc 2014</p>

CC BY-SA 3.0
2017-03-10T19:42:37.897Z
Is it a fixed camera and an area of the frame show the sky? Actually, can you share a frame from night time?
Gyan
CC BY-SA 3.0
2017-03-10T19:50:37.053Z
It's a fixed Timelapse camera. It shows progress of the whole day in 3 secs. I want to slice out middle 1 sec from it. But the problem is footage is continuous for 300 days.. so i need to slice out every third second starting from 2nd sec i.e. 2nd,5th,8th,11th and so on. This is very tedious to do individually. Is there any option by which i can set formula like.. slice out 2to3sec, 2+3to3+3sex, 2+3n to 3+3n sec and so on until the end of video, all at once?
user18315
CC BY-SA 3.0
2017-03-10T20:10:13.213Z
If you are OK with using a command line tool (ffmpeg), I'll supply a command in the morning to do this.
Gyan
CC BY-SA 3.0
2017-03-10T20:15:17.833Z
I haven't used it yet but you send me a command, i'll learn to use commands.
user18315
<video><premiere><adobe><time-lapse><footage>
How do I remove night footage from 300 days of Time lapse video
user18315
# How do I remove night footage from 300 days of Time lapse video

(Asked by: username_0 on 2017-03-10)

I want to remove night footage from a Timelapse video of construction over 300 days. So I want to remove 300 nights from this video. How do I do it in an easier way? Is there a option to cut video at predefined frame/points after regular intervals in one single command? I want to avoid manual labor. I am using adobe premier pro cc 2014

**Tags:** video, premiere, adobe, time-lapse, footage

> **Comments:**
> **username_1**: Is it a fixed camera and an area of the frame show the sky? Actually, can you share a frame from night time?  
> **username_0**: It's a fixed Timelapse camera. It shows progress of the whole day in 3 secs. I want to slice out middle 1 sec from it. But the problem is footage is continuous for 300 days.. so i need to slice out every third second starting from 2nd sec i.e. 2nd,5th,8th,11th and so on. This is very tedious to do individually. Is there any option by which i can set formula like.. slice out 2to3sec, 2+3to3+3sex, 2+3n to 3+3n sec and so on until the end of video, all at once?  
> **username_1**: If you are OK with using a command line tool (ffmpeg), I'll supply a command in the morning to do this.  
> **username_0**: I haven't used it yet but you send me a command, i'll learn to use commands.  

---

## 3 answers

### Answer by username_1 on 2017-03-11. Score: 3

Using ffmpeg, a command line tool, you can use
ffmpeg -i in.mp4 -vf select='trunc(mod(t+2,3))',setpts=N/FRAME_RATE/TB -crf 23 out.mp4

The select filter is used on the video stream. This filter evaluates the supplied expression on each frame and keeps the frame if the expression evaluates to a non-zero value.
The expression used is trunc(mod(t+2,3)). The modulo function returns the remainder of the first operand when divided by the second. The first operand here is the timestamp of the evaluated frame. The truncate function truncates that result to an integer. If it is zero, the frame is discarded, else kept.
e.g. for a 25 fps video
t       t+2      mod(t+2,3)       trunc(mod(t+2,3))    select
0.00    2.00     2.00                    2             KEEP
0.04    2.04     2.04                    2             KEEP
...
0.96    2.96     2.96                    2             KEEP
1.00    3.00     0.00                    0             CUT
1.04    3.04     0.04                    0             CUT
...
1.96    3.96     0.96                    0             CUT
2.00    4.00     1.00                    1             KEEP
...
3.00    5.00     2.00                    2             KEEP
...
4.40    6.40     0.40                    0             CUT
...

Since you want to 'collapse' the video by removing the night time portions, the setpts filter is added to make all the kept frames continuous i.e. after the frame at 0.96, the next kept frame (2.00) will have the new timestamp of 1.00.
The video has to be recompressed since a filter has been used. For MP4s, default codec is H.264 and default encoder is libx264. The -crf 23 sets the bitrate control method (CRF) and value (23). Lower values retain more of the source quality at the expense of larger size. 18 to 28 are typical values.
You can get a ffmpeg binary for your platform from https://ffmpeg.org/download.html. Always get the latest nightly or snapshot build.


---

### Answer by username_2 on 2020-11-16. Score: 0

I have a modified setup where I took a timelapse every 1 hour for 30 days. I want to remove 12 hours of night. I had modified username_1's select with the following:
select='trunc(mod(t*30-2\,24)/12)'

Here I am multiplying t by my frame rate of 30 to convert time to a frame number. Then I provide a frame offset of -2 to start at a different frame. Next I take the mod 24 since I have 24 frames in 1 day. Finally, I divide by 12 and trunc since I want to remove 12 frames of each day. And here is the final code.
ffmpeg -i in.mp4 -vf select='trunc(mod(t*30-2\,24)/12)',setpts=N/FRAME_RATE/TB -crf 23 out.mp4


---

### Answer by username_3 on 2019-10-19. Score: 0

FYI you have to add a backslash before the comma in the select function to make it work (at least on Linux), ie:
ffmpeg -i in.mp4 -vf select='trunc(mod(t+2\,3))',setpts=N/FRAME_RATE/TB -crf 23 out.mp4

Otherwise, you will get a "too many arguments" error.


---

