<p>I'm using <code>enable=between(t,0,5)</code> with <code>ffmpeg</code> to apply a filter during only part of a video, but when I add <code>-copyts</code> to maintain the timestamps in the file, then it extends the length of the output based on the <code>PTS</code> of the input and causes playback issues.</p>
<p>I've also tried filtering by frames using <code>enable=between(n,0,150)</code> but the same problem happens.</p>
<p>Is there a way to still use <code>-copyts</code> without it extending the beginning like this?</p>
<p>Here's an example command:</p>
<pre><code>ffmpeg -i input.mp4 -i overlay1.svg -i overlay2.svg -filter_complex &quot;[0:v][1:v]overlay=10:10:enable='between(n,0,150)'[v0];[v0][2:v]overlay=10:10:enable='between(t,150,1200)&quot; -c:v libx264 -copyts -muxdelay 0 output.mp4
</code></pre>

CC BY-SA 4.0
2024-09-25T11:52:47.427Z
Share your full command.
Gyan
CC BY-SA 4.0
2024-09-26T15:45:27.733Z
I added an example command to the question
Dave Johansen
CC BY-SA 4.0
2024-09-27T04:14:49.617Z
That command should result in an output equal to the length of input.mp4. How long is the actual output?
Gyan
CC BY-SA 4.0
2024-09-27T16:52:26.380Z
The length of the actual data is the same (i.e. the number of frames is the same and `ffprobe` says that it's the same length), but when I play it in QuickTime or VLC then it say it's an hour long.
QuickTime starts at the beginning of the time and there's an hour of black that I have to scroll through before the actual video starts.
VLC shows all of that time but starts playing the video and shows it scrolled through that hour.
Dave Johansen
CC BY-SA 4.0
2024-09-28T04:42:50.400Z
Add `-avoid_negative_ts make_zero` before `output.mp4` and check.
Gyan
CC BY-SA 4.0
2024-10-01T01:07:40.153Z
Adding `-avoid_negative_ts` before the first `-i` and before `output.mp4` doesn't change the output and it's byte for byte identical.
Dave Johansen
CC BY-SA 4.0
2024-10-01T04:11:32.330Z
Also add `-map_chapters -1 -dn -sn`
Gyan
CC BY-SA 4.0
2024-10-15T22:24:58.837Z
I upgraded to 7.1 and `between` using `n` now works
Dave Johansen
<ffmpeg><filter>
How to use -copyts with between?
Dave Johansen
# How to use -copyts with between?

(Asked by: username_0 on 2024-09-25)

I'm using enable=between(t,0,5) with ffmpeg to apply a filter during only part of a video, but when I add -copyts to maintain the timestamps in the file, then it extends the length of the output based on the PTS of the input and causes playback issues.
I've also tried filtering by frames using enable=between(n,0,150) but the same problem happens.
Is there a way to still use -copyts without it extending the beginning like this?
Here's an example command:
ffmpeg -i input.mp4 -i overlay1.svg -i overlay2.svg -filter_complex "[0:v][1:v]overlay=10:10:enable='between(n,0,150)'[v0];[v0][2:v]overlay=10:10:enable='between(t,150,1200)" -c:v libx264 -copyts -muxdelay 0 output.mp4

**Tags:** ffmpeg, filter

> **Comments:**
> **username_1**: Share your full command.  
> **username_0**: I added an example command to the question  
> **username_1**: That command should result in an output equal to the length of input.mp4. How long is the actual output?  
> **username_0**: The length of the actual data is the same (i.e. the number of frames is the same and `ffprobe` says that it's the same length), but when I play it in QuickTime or VLC then it say it's an hour long. QuickTime starts at the beginning of the time and there's an hour of black that I have to scroll through before the actual video starts. VLC shows all of that time but starts playing the video and shows it scrolled through that hour.  
> **username_1**: Add `-avoid_negative_ts make_zero` before `output.mp4` and check.  
> **username_0**: Adding `-avoid_negative_ts` before the first `-i` and before `output.mp4` doesn't change the output and it's byte for byte identical.  
> **username_1**: Also add `-map_chapters -1 -dn -sn`  
> **username_0**: I upgraded to 7.1 and `between` using `n` now works  

---

## 0 answers

