Search code examples
pythonmoviepy

MoviePy - Error when appending Clips to List with VideoFileClip


I am currently trying to create a script that combines all videos with a specific ending from a folder.

import os
from moviepy.editor import *
project_name = "manhattan4"
clips = []

for filename in os.listdir('renderings/'):
    if filename.endswith(".mp4"):
        clips.append(VideoFileClip(filename))
        print(clips)

However, I get the following error.

Traceback (most recent call last):
  File "vid_merger.py", line 8, in <module>
    clips.append(VideoFileClip(filename))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/moviepy/video/io/VideoFileClip.py", line 88, in __init__
    self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_reader.py", line 35, in __init__
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_reader.py", line 270, in ffmpeg_parse_infos
    raise IOError(("MoviePy error: the file %s could not be found!\n"
OSError: MoviePy error: the file render_7_manhattan4.mp4 could not be found!
Please check that you entered the correct path.

Interesting is the fact that if I don't use VideoFileClip it works well, even with render_7_manhattan4.mp4. So I am clueless about where the problem is. Where is the problem to fix or better how can I fix this?


Solution

  • Since you need to give the full path to the file. So you can do something like this:

    import os
    from moviepy.editor import *
    project_name = "manhattan4"
    clips = []
    
    for filename in os.listdir('renderings/'):
        if filename.endswith(".mp4"):
            clips.append(VideoFileClip('renderings/' + str(filename))) # Change here
            print(clips)