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.
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:
- 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.
- 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.
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.