ffmpeg: Non-monotonous DTS in output stream 0:0 – Video Generation Series (Part 2) [ERROR]

This error occured when I used ffmpeg to concatenate different videos that I generated:

ffmpeg -f concat -safe 0 -i list.txt -c copy final_video.avi -y
BTW, if you want to run ffmpeg or any other command inside a python script (a very reasonable idea), use subprocess:

command = "ffmpeg -f concat -safe 0 -i list.txt -c copy final_video.avi -y"
subprocess.Popen(command.split(), stdout=subprocess.PIPE)

As a result – the videos got smashed together – some frames even never appeared.

Solution

I tried a lot, including different libraries and codecs. For no avail.

But for me, the problem was that I tried to concatenate videos of different FPS.

Say, my list.txt of videos and their FPS look like this:

video_1.avi - 24 FPS
video_2.avi - 1 FPS
video_3.avi - 1 FPS
video_4.avi - 24 FPS

That is due to the nature of these generated videos:

  1. The video_1.avi and video_4.avi include GIFs, I wrote about how I achieved that in the previous post of the Video Generation series.
  2. And video_2.avi and video_3.avi are regular videos with static background and some audio. I used FPS=1 for them as I didn’t need more to show animation or something.

I used OpenCV to generate all of these videos, so I just had to change FPS in the initializer for the videos that had FPS equaling 1:

fps = 24  # it used to be 1
video = cv2.VideoWriter(video_destination, 0, fps, (width, height))

And it worked fine.

Conclusion

Set FPS of all of your videos to the same number.

If one video requires at very least 24 FPS – all of them should be 24 FPS.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.