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 issue

My 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:closed
  • Created 6 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

21reactions
hvonsaltzacommented, Jan 6, 2018

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.

3reactions
azeemakhter-arbisoftcommented, May 24, 2021

File Generated by CompositeVideoClip takes too much time while writing to output file but video object created by concate_video_clips is quite fast. As i’m using videoclip.crossfadein() and it only works with CmpositeVideoClip so it takes too much time while writing to output file. I’m already using threads=4 in write_videofile(). Any suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

why does moviepy's write_videofile function get slower and ...
As it processes every frame, the process gets slower and slower and slower (indicated by progress bar and estimated completion time). In my...
Read more >
write_videofile is extremely slow : r/moviepy - Reddit
write_videofile is extremely slow. Hi all, I'm using moviepy for automating the editing and rendering of a few internal videos.
Read more >
How to be efficient with MoviePy
Press Escape abort the previewing. Note that if the clip is complex and your computer not fast enough, the preview will appear slowed...
Read more >
MoviePy – Applying Speed effect on Video Clip - GeeksforGeeks
MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF's. Speed up video or...
Read more >
Classes of Video Clips — MoviePy documentation
Each repetition will have a value in the linear function between 1 and this value, ... myClip.resize(lambda t : 1+0.02*t) # slow swelling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found