moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Multi-core CPU rendering

Open rahulbagal opened this issue 7 years ago • 6 comments

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 ?

rahulbagal avatar Jun 08 '17 09:06 rahulbagal

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)

ghost avatar Jun 14 '17 15:06 ghost

@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?

ngbien83 avatar Sep 28 '17 01:09 ngbien83

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 ?

Zulko avatar Sep 28 '17 10:09 Zulko

^ I added a proof of concept multithreading support, albeit a bit gimmicky it appears to be working.

MythicManiac avatar Jan 19 '18 00:01 MythicManiac

@Zulko Will multithreading work on Windows? I think it works only on Linux due to the Python GIL.

adam-grant-hendry avatar Mar 20 '20 19:03 adam-grant-hendry

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

idan92 avatar Apr 22 '22 19:04 idan92

Closing this older issue with a link to this Moviepy Roadmap comment regarding (potential future) multithreading support.

keikoro avatar Oct 11 '22 02:10 keikoro