Answers.Body: <p>MPEG-TS don't have a global keyframe index ,so even input <code>-ss</code> will seek to the next KF after the <code>ss</code> timestamp.</p>
  <p>Add <code>-copyts -start_at_zero</code> and seek to a few seconds earlier. Then add a trim filter with the exact timestamp.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-02T20:20:17.660Z
Answers.LastActivityDate: 2024-05-02T20:20:17.660Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>tnx gyan,
  more or less understood. I'll have to try.</p>
  <p>problem started with recent versions of ffmpeg (5.1 &amp; above); up to version 4.3 to extract a frame at exact timestamp, without waiting log time for output -ss seeking, I finally found that combining input -ss (up to at least before the previous keyframe) and adding output -ss up to the desired timestamp was correct IF TS file had only video track, otherwise was shifted by the difference between video_track start_time and earliest starting audio-track; calculating that difference with ffprobe and adding to output -ss gave the correct frame.
  with recent versions behaviour is different: if video-only TS file, than it's easy (no shift, and sum of the two -ss), but with audio-video files looks like it's initially reaching the first KF after input -ss, than if output -ss is less than input -ss returns that KF, otherwise if larger it returns the frame at output -ss timestamp (from beginning of file).
  so old procedure cannot be applied anymore.
  I will deep study what you suggested.</p>
  <p>thanks</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-03T19:10:03.733Z
Answers.LastActivityDate: 2024-05-03T19:10:03.733Z
Answers.UserDisplayName: templeton
Body: <p>As from FFmpeg version 2.1, <code>-ss</code> used as an input option should be frame accurate (when transcoding, not stream-copying).</p>
  <p>I tried it with different versions of FFmpeg, up to recent ones, and with MPEG-TS files doesn't look accurate to me. I still get the cut (or the frame extraction) at the first I-frame after the specified timestamp.</p>
  <p>Is it an exception for MPEG-TS files, or am I missing something?</p>
  
Tags: <ffmpeg>
Title: ffmpeg input -ss accuracy
UserDisplayName: templeton
ThreadText: # ffmpeg input -ss accuracy
  
  (Asked by: username_0 on 2024-05-02)
  
  As from FFmpeg version 2.1, `-ss` used as an input option should be frame accurate (when transcoding, not stream-copying).
  
  I tried it with different versions of FFmpeg, up to recent ones, and with MPEG-TS files doesn't look accurate to me. I still get the cut (or the frame extraction) at the first I-frame after the specified timestamp.
  
  Is it an exception for MPEG-TS files, or am I missing something?
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2024-05-02. Score: 1
  
  MPEG-TS don't have a global keyframe index ,so even input `-ss` will seek to the next KF after the `ss` timestamp.
  
  Add `-copyts -start_at_zero` and seek to a few seconds earlier. Then add a trim filter with the exact timestamp.
  
  
  ---
  
  ### Answer by username_0 on 2024-05-03. Score: 0
  
  tnx username_1,
  more or less understood. I'll have to try.
  
  problem started with recent versions of ffmpeg (5.1 & above); up to version 4.3 to extract a frame at exact timestamp, without waiting log time for output -ss seeking, I finally found that combining input -ss (up to at least before the previous keyframe) and adding output -ss up to the desired timestamp was correct IF TS file had only video track, otherwise was shifted by the difference between video\_track start\_time and earliest starting audio-track; calculating that difference with ffprobe and adding to output -ss gave the correct frame.
  with recent versions behaviour is different: if video-only TS file, than it's easy (no shift, and sum of the two -ss), but with audio-video files looks like it's initially reaching the first KF after input -ss, than if output -ss is less than input -ss returns that KF, otherwise if larger it returns the frame at output -ss timestamp (from beginning of file).
  so old procedure cannot be applied anymore.
  I will deep study what you suggested.
  
  thanks
  
  
  ---
  
  