Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat videos too slow using Python MoviePY

I am joining 50s or more videos of 1,2,3 minutes using MoviePY but it's giving me 20 hours, even though I have 64 GB of ram, i7 and GTX 670, not top of range yet reasonable. Is there anyway I can speed this process up ?

padding = 10 # padding option
video_clips = [VideoFileClip(video_dir + video) for video in os.listdir(video_dir)]
video_fx_list = [video_clips[0]]

idx = video_clips[0].duration - padding
for video in video_clips[1:]:
video_fx_list.append(video.set_start(idx).crossfadein(padding))
idx += video.duration - padding

final_video = CompositeVideoClip(video_fx_list)
final_video.write_videofile(video_dir + 'myoutfile.mp4', fps=24)

I don't need original audio these clips have, would removing it going to speed things up ? not sure how to remove audio though/

enter image description here

like image 932
Mathematics Avatar asked Dec 10 '22 02:12

Mathematics


1 Answers

You can specify a number of threads in write_videofile . It will significantly speed up the export by using all cores of your machine.

final_video.write_videofile(video_dir + 'myoutfile.mp4', threads = 8, fps=24)

Aditionnal notes:

  • You could resize all videos to a lower resolution (e.g. 720p)

  • Decreasing fps makes also a big difference, but 24 fps is already well optimized

  • Moviepy uses only the CPU to render the video. Consider to upgrade your CPU or run your program on cloud services (e.g. Amazon AWS, Google Cloud, MS Azure..) for better performance

like image 81
SciPy Avatar answered Dec 28 '22 10:12

SciPy