我有一个与这条线类似的问题,但区别在于我根本没有试图更改文件夹,它仍然应该能够读取文件。我不明白为什么会有问题?
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")
我试图用多个用相同代码转换的文件来实现这一点,但似乎没有一个文件能工作。另外要注意的是,我的python和pip只与" pip3“和"python3”一起工作,而不是正常情况下--我无法通过pip3安装imagemagick,但是我让它处理brew 完全错误:。
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蒙特雷12.4
运行电影1.0.3
运行ffmpeg 1.4
发布于 2022-08-02 11:15:21
我试着复制并得到了和你一样的错误。
这是一个已知的问题,在最新发布 of MoviePy中得到了解决。
在我安装了最新的版本之后,对我来说,问题就消失了:
pip uninstall moviepy
pip install moviepy==2.0.0.dev2
https://stackoverflow.com/questions/73139990
复制相似问题