Body: <p>I try to <strong>set pts for each frame</strong> of the input video.</p>
  <p>Here is the command I use to slowdown frame 1 and speed up frame 2:</p>
  <pre><code>ffmpeg -i input.mkv -filter_complex &quot;[0:v]setpts='PTS*2*eq(N,0)+PTS*0.5*eq(N,1)+...'[out]&quot; -map [out] output.mkv
  </code></pre>
  <p>I am new to ffmpeg and I can't figure out why my output duration is longer than my input.</p>
  <p>If I make the 1st frame 2x slower and the 2nd frame 2x faster the output should have the same duration as the input ?</p>
  <p>Thanks !</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-05T04:14:28.583Z
Comments.Text: No, if you had 2 frames and your original frame duration was 1 second, then total duration would be 2 seconds. If you changed frame 1 duration to 2 seconds and frame 2 to 0.5 seconds, then total duration would become 2.5 seconds, which is longer.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-05T04:19:21.420Z
Comments.Text: Now, what your setpts expr actually does is multiply the presentation timestamp directly. That does not do what you intend. PTS have to be monotonic i.e. always increasing, so if frame 20 has original pts 20 seconds, and frame 21 has 21 seconds, then with your expr, frame 20 will have new pts 40 and frame 21 will have new pts 10.5. That's not valid and ffmpeg will adjust the pts of 21 to be larger than frame 20.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-06T07:21:49.230Z
Comments.Text: Ok, it's clear now. I was confused because I thought that PTS was the starting point of the current frame (taking into account the pts of the previous frame) but if I understood correctly, it is that of the entry without consideration of the previous frames and their pts. Thank you very much for your time! Your answer is well explained !
Comments.UserDisplayName: legeba
Tags: <ffmpeg><video>
Title: ffmpeg - set dynamic pts on video
UserDisplayName: legeba
ThreadText: # ffmpeg - set dynamic pts on video
  
  (Asked by: username_0 on 2024-05-04)
  
  I try to **set pts for each frame** of the input video.
  
  Here is the command I use to slowdown frame 1 and speed up frame 2:
  
  ```
  ffmpeg -i input.mkv -filter_complex "[0:v]setpts='PTS*2*eq(N,0)+PTS*0.5*eq(N,1)+...'[out]" -map [out] output.mkv
  
  ```
  
  I am new to ffmpeg and I can't figure out why my output duration is longer than my input.
  
  If I make the 1st frame 2x slower and the 2nd frame 2x faster the output should have the same duration as the input ?
  
  Thanks !
  
  **Tags:** ffmpeg, video
  
  > **Comments:**
  > **username_1**: No, if you had 2 frames and your original frame duration was 1 second, then total duration would be 2 seconds. If you changed frame 1 duration to 2 seconds and frame 2 to 0.5 seconds, then total duration would become 2.5 seconds, which is longer.  
  > **username_1**: Now, what your setpts expr actually does is multiply the presentation timestamp directly. That does not do what you intend. PTS have to be monotonic i.e. always increasing, so if frame 20 has original pts 20 seconds, and frame 21 has 21 seconds, then with your expr, frame 20 will have new pts 40 and frame 21 will have new pts 10.5. That's not valid and ffmpeg will adjust the pts of 21 to be larger than frame 20.  
  > **username_0**: Ok, it's clear now. I was confused because I thought that PTS was the starting point of the current frame (taking into account the pts of the previous frame) but if I understood correctly, it is that of the entry without consideration of the previous frames and their pts. Thank you very much for your time! Your answer is well explained !  
  
  ---
  
  ## 0 answers
  
  