title: Ffmpeg inaccurate cutting with ts and m3u8 files despite resamping audio filter
body: <p>I need to accurately seek and cut a video. Some online sources say put -ss in front or after the source. The result is the same for me. In the examples below, the start time is accurate but the duration is not accurate.</p>
  <pre><code>ffmpeg -y -ss 00:00:05 -t 00:00:05 -i output.ts 5s.wav
  ffprobe 5s.wav
  
  Duration: 00:00:04.74
  
  ffmpeg -y -i output.ts -ss 00:00:05 -t 00:00:05 5s.wav
  ffprobe 5s.wav
  
  Duration: 00:00:04.74
  </code></pre>
  <p>Sometimes the starting point is not accurate but the duration is. This is clearly audible by cutting the ts file and cutting an uncompressed wav file, and listening to both.</p>
  <pre><code>ffmpeg -y -i output.ts -ss 00:00:15 -t 00:00:05 5s.wav
  
  ffmpeg -y -i output.wav -ss 00:00:15 -t 00:00:05 5s-reference.wav
  </code></pre>
  <p>What fixes the starting time is if I use an m3u8 file that contains the byte offset for every keyframe AND I put the -ss option in front of the source file (if I put it after the source, the start time is inaccurate but the duration is accurate):</p>
  <pre><code>ffmpeg -y -ss 00:00:15 -t 00:00:05 -i output.m3u8 5s.wav
  </code></pre>
  <p>This fixes the start time but the duration is at the location that I would get had I used no m3u8 file (duration is just 4.47s).</p>
  <p>It seems different timestamps are involved, and sometimes one or the other gets used.</p>
  <p>The ts file was generated by capturing a UDP stream and storing it with ffmpeg and -codec:v copy.</p>
  <p>Is ffmpeg broken, or the ts file? How do I work around this issue or fix the ts file? What I realize is that the video starts later than the audio, probably because the video does not start with a keyframe. Can I get ffmpeg to start the -codec:v copy after the first keyframe? What I also notice is that using ffprobe reports &quot;start: 1.400000&quot;. Can I force it to start at 0?</p>
  <p>Any hints would be appreciated.</p>
  <p>I tried both ffmpeg 4.3.1 and ffmpeg git-2020-07-24-21442a8.</p>
  <p>The output.* files were generated as follows. The statement &quot;af aresample=async=1&quot; should fill missing audio according to <a href="https://stackoverflow.com/questions/41136242/duration-of-source-video-and-subtracted-audio-are-different">Duration of source video and subtracted audio are different</a>. Adding this statement makes no difference in terms of accuracy or duration. The question is not a duplicate.</p>
  <pre><code>ffmpeg -i udp://example:port ^
  -af aresample=async=1 ^
  -codec:v copy ^
  -codec:a aac -ac 2 -ar 44100 -b:a 160k ^
  -hls_time 4 -hls_flags single_file -hls_list_size 0 -hls_segment_filename output.ts -hls_segment_type mpegts output.m3u8 ^
  -codec:a pcm_s16le -bitexact -ar 11025 -ac 1 output.wav
  </code></pre>