why does moviepy's write_videofile function get slower and slower as it processes each frame? And how to improve/fix it?
See original GitHub issueMy script takes two movie files as an input, and writes a 2x1 array movie output (stereoscopic Side-by-Side Half-Width). The input video clips are of equal resolution (1280x720), frame rate (60), number of frames (23,899), format (mp4)… When the write_videofile function starts processing, it provides an estimated time of completion that is very reasonable ~20min. As it processes every frame, the process gets slower and slower and slower (indicated by progress bar and estimated completion time). In my case, the input movie clips are about 6min long. After three minutes of processing, it indicates it will take over 3 hours to complete. After a half hour of processing, it then indicates it will take over 24hours to complete. I have tried the ‘threads’ option of the write_videofile function, butit did not help.
Any idea? Thanks for the help.
---- Script ----
movie_L = 'movie_L.mp4'
movie_R = 'movie_R.mp4'
output_movie = 'new_movie.mp4')
clip_L = VideoFileClip(movie_L)
(width_L, height_L) = clip_L.size
clip_L = clip_L.resize((width_L/2, height_L))
clip_R = VideoFileClip(movie_R)
(width_R, height_R) = clip_R.size
clip_R = clip_R.resize((width_R/2, height_R))
print("*** Make an array of the two movies side by side")
arrayClip = clips_array([[clip_L, clip_R]])
print("*** Write the video file")
arrayClip.write_videofile(output_movie, threads=4, audio = False)
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Related StackOverflow Question
I was getting the exact same issue when running a script through IDLE on python 3.6.4/Win64
Are you using IDLE? When I utilize the IDLE shell to execute a .write_videofile() the shell fills up with progress bar updates and slows down due to the constant writing to the shell. When I run the script on its own it performs fine.
To get better performance out of the IDLE, pass the parameter ‘progress_bar = False’ to the write_videofile()
For your example:
arrayClip.write_videofile(output_movie, threads=4, audio = False, progress_bar = False)This will disable the writing of the bar to the shell, and increased performance on my machine considerably.
File Generated by
CompositeVideoCliptakes too much time while writing to output file but video object created byconcate_video_clipsis quite fast. As i’m usingvideoclip.crossfadein()and it only works withCmpositeVideoClipso it takes too much time while writing to output file. I’m already usingthreads=4inwrite_videofile(). Any suggestions?