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

How to Fix: concatenating multiple files is giving Non-monotonic DTS in output stream error

FFmpeg concatenation issue with non-monotonic DTS error

Quick Answer: Use the -segment_timecode option to ensure monotonic DTS. For example, add '-segment_timecode 1' after '-c copy'.

The error 'Non-monotonic DTS in output stream' occurs when the timestamps of the audio and video streams are not aligned properly, causing issues with playback. This issue affects users who concatenate multiple videos using ffmpeg.

This error can be frustrating because it prevents the user from playing the concatenated video smoothly. However, there is a solution to resolve this issue.

💡 Why You Are Getting This Error

  • The root cause of this error is that the concat demuxer in ffmpeg does not handle non-monotonic DTS (Display Time Stamp) correctly. When concatenating multiple videos, ffmpeg tries to align the timestamps of the audio and video streams, but if the DTS is not monotonic (i.e., it increases over time), it can result in incorrect timestamps in the output file.
  • Another possible cause is that the input videos have different frame rates or resolutions, which can affect the alignment of the timestamps.

🔧 Proven Troubleshooting Steps

Aligning DTS using -af

  1. Step 1: Open a text editor and create a new file called `align_dts.py` with the following code: `ffmpeg -i input.mp4 -af aformat=duration=INFINITY -c:v copy -c:a aac -f mp4 output.mp4`. This command aligns the DTS of the input video using the `aformat` filter.
  2. Step 2: Copy this command and replace `input.mp4` with the path to your first video file, and `output.mp4` with the desired output filename.
  3. Step 3: Repeat this process for each video file you want to concatenate, creating a new command for each one.

Using -metadata

  1. Step 1: Alternatively, you can use the `-metadata` option to specify the DTS of each input video. Open a text editor and create a new file called `concat_list.txt` with the following format: `file 'video1.mp4'`, `file 'video2.mp4'`, etc.
  2. Step 2: Copy this command and replace `video1.mp4` with the path to your first video file, and `video2.mp4` with the path to your second video file, etc.
  3. Step 3: Run this command: `ffmpeg -f concat -i concat_list.txt -c:v copy -c:a aac output.mp4`. This command concatenates the input videos using the `concat` filter.

🎯 Final Words

To resolve the 'Non-monotonic DTS in output stream' error, you can try one of two methods: aligning the DTS using `-af`, or using the `-metadata` option. By following these steps, you should be able to concatenate multiple videos smoothly and without errors.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions