Search code examples
pythonmoviepy

Why does "'VideoFileClip' object has no attribute 'subclip'" error occur in MoviePy 2.1.2?


i'm using MoviePy version 2.1.2, and I'm encountering the following error:

AttributeError: 'VideoFileClip' object has no attribute 'subclip'

Here is the code snippet where the error occurs:

from moviepy.editor import VideoFileClip

clip = VideoFileClip("example.mp4")
subclip = clip.subclip(10, 20)  # Extracts a 10-second clip
subclip.write_videofile("output.mp4")

This same code worked perfectly in an older version of MoviePy. I'm guessing there might have been changes or deprecations in the latest version.

MoviePy version: 2.1.2 Python version: 3.9.10

Could someone please confirm if subclip() has been renamed, removed, or replaced with a different method? If so, what is the new way to extract a portion of a video?

Any help or documentation references would be greatly appreciated!


Solution

  • Since moviepy 2, you can import the VideoFileClip class directly from moviepy. So your import statement should be:

    from moviepy import VideoFileClip
    

    Also you're getting the error because you're calling the wrong method here clip.subclip(10, 20) it should be:

    subclip = clip.subclipped(10, 20)
    

    See the Example on https://pypi.org/project/moviepy/