pythonmoviepyoserror

MoviePy Error: failed to read the first frame of video file


I'm having a similar issue to this thread, but the difference is that I'm not attempting to change folders at all, it still should be able to read the file. I don’t see why there’s an issue with it?

for x in newfiles:
    x = x + ".mp4"
    xstr = x
    xstr2 = xstr.replace(".mp4", "")
    x = VideoFileClip(x)
    x = x.resize(width=720)
    durationsecs = x.duration
    fullclip = CompositeVideoClip([bgnosnd.set_position((0,0)).set_end(durationsecs), x.set_position((0,20))], size=(720, 1080))
    textclip = TextClip(f"Part {xstr2}", font="fjalla-one.ttf",fontsize=125, color="white", stroke_color="black", stroke_width=5)
    textclip = textclip.set_pos('center').set_duration(durationsecs) 
    fullclip = CompositeVideoClip([fullclip, textclip])
    fullclip = fullclip.volumex(per)
    fullclip = vfx.make_loopable(fullclip, 0.5)
    fullclip.write_videofile(f"final{xstr}")

The code processes both input videos properly, and does spit out a working output file before throwing the error, but I'm still unsure how to fix the error. It seemed to work before on a testing file, but I have made a couple changes since then. One thing to note is that my current file was converted from an mkv file to an mp4 file with this code:

  convert = VideoFileClip(filename)
  convert.write_videofile(f"converted_{filename2}.mp4", codec="libx264",audio_codec="aac")

I've tried to do this with multiple files that are converted with the same code, but none seem to work. Another thing to note is that my python and pip only work with "pip3" and "python3", and not normally - I was unable to install imagemagick through pip3, but i got it to work with brew Full error:

Traceback (most recent call last):
  File "tikgen.py", line 74, in <module>
    fullclip.write_videofile(f"final{xstr}")
  File "<decorator-gen-55>", line 2, in write_videofile
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-54>", line 2, in write_videofile
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<decorator-gen-53>", line 2, in write_videofile
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/VideoClip.py", line 300, in write_videofile
    ffmpeg_write_video(self, filename, fps, codec,
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/io/ffmpeg_writer.py", line 220, in ffmpeg_write_video
    for t,frame in clip.iter_frames(logger=logger, with_times=True,
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 472, in iter_frames
    frame = self.get_frame(t)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 187, in <lambda>
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 111, in make_frame
    f = c.blit_on(f, t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/VideoClip.py", line 527, in blit_on
    img = self.get_frame(ct)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 111, in make_frame
    f = c.blit_on(f, t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/VideoClip.py", line 527, in blit_on
    img = self.get_frame(ct)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 111, in make_frame
    f = c.blit_on(f, t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/VideoClip.py", line 527, in blit_on
    img = self.get_frame(ct)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/VideoClip.py", line 490, in <lambda>
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "<decorator-gen-11>", line 2, in get_frame
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/io/VideoFileClip.py", line 113, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/io/ffmpeg_reader.py", line 184, in get_frame
    result = self.read_frame()
  File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/video/io/ffmpeg_reader.py", line 133, in read_frame
    raise IOError(("MoviePy error: failed to read the first frame of "
OSError: MoviePy error: failed to read the first frame of video file 1.mp4. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.

If you have any questions with what part of my code means what, don't hesitate to ask!

Running MacOS Monterey 12.4

Running moviepy 1.0.3

Running ffmpeg 1.4


Solution

  • I've tried to reproduce and got the same error as you.

    It's a known problem that got fixed in latest release of MoviePy.

    After I installed the latest release, for me the problem was gone:

    pip uninstall moviepy
    pip install moviepy==2.0.0.dev2