Search code examples
pythonvideomoviepy

How can I efficiently cut out part of a video?


I want to remove the first few seconds from a video that's about 25 minutes long. I found the moviepy package, and tried writing this code:

from moviepy.editor import *
clip = VideoFileClip("video1.mp4").cutout(0, 7)
clip.write_videofile("test.mp4")

However, it's very slow even for a single video. Is there a faster way to do this in Python?


Solution

  • Try this and tell us if it is faster (if it can, it will extract the video directly using ffmpeg, without decoding and reencoding):

    from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
    ffmpeg_extract_subclip("video1.mp4", start_time, end_time, targetname="test.mp4")
    

    If that doesn't help, have a look at the code