Reputation: 1189
I am using moviepy, a python module for creating movies, to create movies of one pic of mike, followed by one pic of emily with a different song every 2 pictures. I implemented this in the following way:
clips = []
for i in range(n):
audio = AudioFileClip(audiofiles[i]).set_duration(10)
video1 = ImageClip(images_mike[i]).set_duration(5)
video2 = ImageClip(images_emily[i]).set_duration(5)
video = concatenate([video1,video2],method='compose')
movie.set_audio(audio)
clips.append(movie)
video = concatenate(clips,method='compose')
video.write_videofile('my_movie.mp4')
audiofiles, is a list of audio filenames. images_mike and images_emily are each lists of image filenames.
But this method is really really slow. video.write_videofile('my_movie.mp4') can take an hour to compile a 4 minute clip. Furthermore, I run into memory allocation errors when im trying to make a 10 minute clip. What is wrong with this implementation? Surely this isn't right.
I don't know if this is relevant, but im on a laptop, with 16gb ram and i7 processor.
Upvotes: 2
Views: 3470
Reputation: 47
Please use ImageSequenceClip()
instead of concatenate()
eg:
ImageSequenceClip(/dir/where_your_pics/are, fps=20)
Also note, for some reason, ImageSequenceClip()
is not yet documented on web ask ChatGPT about it for more details or check the GitHub repo for moviepy at .../io/ImageSequenceClip
Upvotes: 0
Reputation: 11
try using "method='chain' " in concatenate. It increased my speed from 4 it/s up to 20 it/s. Visually I had no differences in output at all however, this depends on your code and video you are making.
Upvotes: 1
Reputation: 544
If it's the write_videofile
that's slow, there is a preset
argument that tells FFMPEG how much time to spend trying to optimize the compression. The default is 'medium'. If you don't care how big your video file gets, try using preset='ultrafast'
. Per the documentation, the quality will not change no matter which option you choose, but the file could get a lot larger with a faster setting.
video.write_videofile('my_movie.mp4', preset='ultrafast')
Choices are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo.
You can also use the threads
argument, which defaults to None
...try setting it to 2 or 3 and see if that helps.
Upvotes: 3