Software⏱️ 4 min read📅 2026-06-11

How to Fix: Capturing TS video stream gives Invalid timestamps and Invalid DTS error messages

FFmpeg issues with capturing TS video stream and invalid timestamps and DTS error messages.

Quick Answer: Use the -re option to enable real-time decoding, which can help resolve the issue by forcing ffmpeg to redecode packets instead of relying on the timestamp information.

The error 'Invalid timestamps and Invalid DTS' occurs when FFmpeg is unable to accurately track the timestamp information of the TS video stream. This issue affects users who are capturing video streams using the HLS (HTTP Live Streaming) protocol, specifically those using the m3u8 playlist file format.

This error can be frustrating as it causes the captured video to have incorrect timestamps and potentially leads to playback issues. However, with the right troubleshooting steps, you can resolve this issue and capture high-quality videos.

⚠️ Common Causes

  • The primary reason for this error is due to the way FFmpeg handles timestamp information in HLS streams. When FFmpeg encounters a TS file, it tries to calculate the timestamp based on the DTS (Decoding Time Stamp) value. However, if the DTS value is not accurate or is missing, FFmpeg cannot correctly calculate the timestamp, resulting in 'Invalid timestamps' error messages.
  • Another possible cause of this error is due to the use of the `copy` mode for both audio and video codecs. When using the `copy` mode, FFmpeg does not re-encode the audio or video streams, but instead copies the existing stream. However, if the TS file contains incorrect timestamp information, the copied stream may also contain incorrect timestamps, leading to the 'Invalid DTS' error messages.

✅ Best Solutions to Fix It

Re-specifying Timestamps using `-ss` and `-t` options

  1. Step 1: To resolve this issue, you can use the `-ss` and `-t` options with FFmpeg to specify the start time and duration of the video stream. For example, `ffmpeg -i "http://streaming_url.com/playlist.m3u8" -ss 00:00:01 -t 10 -acodec copy -vcodec copy -absf aac_adtstoasc "out_put_file.mp4"`
  2. Step 2: This method allows you to specify the exact start time and duration of the video stream, which can help FFmpeg accurately calculate the timestamp information.
  3. Step 3: Note that this method requires you to know the exact start time and duration of the video stream. If you are unsure about these values, you may need to use a different approach.

Using `-hls_time` option with HLS streams

  1. Step 1: Another solution is to use the `-hls_time` option with FFmpeg when capturing HLS streams. This option allows FFmpeg to calculate the timestamp information based on the stream's timecode, rather than relying on the DTS value.
  2. Step 2: For example, `ffmpeg -i "http://streaming_url.com/playlist.m3u8" -hls_time 1 -acodec copy -vcodec copy -absf aac_adtstoasc "out_put_file.mp4"`
  3. Step 3: This method can be more accurate than the previous one, especially when dealing with streams that have varying DTS values.

💡 Conclusion

By using either of these methods, you should be able to resolve the 'Invalid timestamps and Invalid DTS' error messages and capture high-quality videos from your HLS stream. Remember to always check the documentation for FFmpeg and the streaming protocol you are using to ensure that you are using the correct options and settings.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions