You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MoviePy读取视频首帧失败求助:生成有效输出仍报错

问题:MoviePy读取视频帧失败错误

遇到了类似线程的问题,但未切换文件夹,理论上应该可以读取文件,不清楚问题出在哪里?

代码可以正常处理输入视频,并且在抛出错误前会生成可正常使用的输出文件,但仍不知道如何修复该错误。之前测试文件可以正常运行,但后续做了一些修改后出现问题。当前处理的文件是通过代码将MKV文件转为MP4得到的,尝试多个转换后的文件均无法解决问题。另外,Python和Pip仅能通过python3和pip3调用;无法通过pip3安装ImageMagick,但已通过brew成功安装。

处理视频代码

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}")

MKV转MP4代码

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

完整错误信息

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.

运行环境

  • MacOS Monterey 12.4
  • MoviePy 1.0.3
  • FFmpeg 1.4

内容的提问来源于stack exchange,提问作者HypnoticOcelot

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 06:16:18