Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-25T11:52:47.427Z
Comments.Text: Share your full command.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-26T15:45:27.733Z
Comments.Text: I added an example command to the question
Comments.UserDisplayName: Dave Johansen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-27T04:14:49.617Z
Comments.Text: That command should result in an output equal to the length of input.mp4. How long is the actual output?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-27T16:52:26.380Z
Comments.Text: 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.
Comments.UserDisplayName: Dave Johansen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-09-28T04:42:50.400Z
Comments.Text: Add `-avoid_negative_ts make_zero` before `output.mp4` and check.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-01T01:07:40.153Z
Comments.Text: Adding `-avoid_negative_ts` before the first `-i` and before `output.mp4` doesn't change the output and it's byte for byte identical.
Comments.UserDisplayName: Dave Johansen
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-01T04:11:32.330Z
Comments.Text: Also add `-map_chapters -1 -dn -sn`
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-10-15T22:24:58.837Z
Comments.Text: I upgraded to 7.1 and `between` using `n` now works
Comments.UserDisplayName: Dave Johansen
Tags: <ffmpeg><filter>
Title: How to use -copyts with between?
UserDisplayName: Dave Johansen
ThreadText: # 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
  
  