Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.55k stars 1.57k forks source link

Efficiency Disparity Between MoviePy and FFmpeg #2165

Open OtokoNoIzumi opened 6 months ago

OtokoNoIzumi commented 6 months ago

I recently encountered a significant difference in processing time when extracting a 70-second clip from a video using different methods. Utilizing MoviePy's subclip and write_videofile functions took over 20 seconds to complete the task. In stark contrast, invoking FFmpeg through subprocess with the -c copy command on the same file and clip took merely milliseconds. How can I achieve similar efficiency using MoviePy? Currently, I observe that writing at the original speed is approximately 90 iterations per second (it/s), but when I introduce final_duration to expedite the process, the speed drops drastically to just a few it/s, which is considerably slower. If there is no way to enhance the speed, I would appreciate an explanation of the design philosophy and benefits behind MoviePy's chosen architecture. Specifically, what are the intended advantages of this approach?

here is the python code demo clip = VideoFileClip(video_paths[0]).subclip(0, 70) clip.write_videofile("my_new_video.mp4")

here is the subprocess params for FFmpeg cmd=[ ffmpeg_path, '-i', input_video_path, '-c', 'copy', '-map', '0','-ss',str(start_time) , '-t', str(duration), '-q:v', '0', output_video_path,'-y', ]

bzczb commented 5 months ago

There's a performance problem in recent versions of moviepy, because of the way some decorators were implemented: #2094

If you patch that, you might not be able to get -c copy performance, but it'll be much improved.