moviepy
moviepy copied to clipboard
Multi-core CPU rendering
When I render my MoviePy video on ubuntu it uses only one core of the machine. As per below thread , ffmpeg supports multiprocessor based on codec ( http://www.ffmpeg-archive.org/FFMPEG-on-multiprocessor-machine-td935307.html )
Is there a way this can be leveraged ?
try setting the threads argument in the write_videofile function. for example to use 4 threads, you could do...
video.write_videofile("myvideo.mp4", threads=4)
@earney threads argument won't force the action to use more machine cores. It doesn't speed up the write file proccess, even I tried "threads=100". Is there any way to use all the machine cores and memory to rendering the videos faster?
As I understand it, the thread argument should make ffmpeg use several threads, which your OS may dispatch on several processors. However, it is possible that your bottleneck is the generation of the frames, and not the encoding. If moviepy's frame generation (which is single-threaded if I remember well) is slower than the encoding, then ffmpeg will only require a single thread, even when several are provided. Not sure if this applies to your case ?
^ I added a proof of concept multithreading support, albeit a bit gimmicky it appears to be working.
@Zulko Will multithreading work on Windows? I think it works only on Linux due to the Python GIL.
Hi guys, in the past I was same problem and I solved that.
You need to use this command in your code ONLY one time.
video = CompositeVideoClip([clip1, clip2, clip3])
and export the video:
video.write_videofile(path_final_video)
while the video is export, moviepy will use all your cores.
Hope I helped :)
Closing this older issue with a link to this Moviepy Roadmap comment regarding (potential future) multithreading support.