ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile
ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile
为什么它对某些文件抛出此错误,而对其他文件却没有?
文件都是.mp4视频。
'ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile.'
代码,附注释:
# The videos on which we will work on (intro & a video)
intro = VideoFileClip('./videos/intro.mp4')
original = VideoFileClip('./videos/original_video.mp4')
# We cut 2s and crop the original video
original.cutout(0, 2)
original = vfx.crop(original, x1=10)
# Adding a watermark on top of the original video
watermark = (ImageClip("./images/watermark.png")
.set_duration(original.duration)
.set_position(("center","bottom"))
.resize(width=intro.w))
watermaked = CompositeVideoClip([original, watermark], size=original.size)
# Our final video: Intro + Waterkarmed, and output it.
final_render = concatenate_videoclips([intro, watermaked], method='compose')
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1)
错误堆栈:
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1)
File "<decorator-gen-51>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "<decorator-gen-50>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "<decorator-gen-49>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "/usr/lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 288, in write_videofile
raise ValueError("MoviePy couldn't find the codec associated "
ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile.
您需要使用 codec 参数手动设置编解码器。
代码应如下所示:
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1, codec="libx264")
编解码器根据视频文件扩展名变化:
Extension
Codec
mp4
libx264
ogv
libtheora
webm
libvpx
ogg
libvorbis
mp3
pcm_s16le
wav
libvorbis
m4a
libfdk_aac
为什么它对某些文件抛出此错误,而对其他文件却没有?
文件都是.mp4视频。
'ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile.'
代码,附注释:
# The videos on which we will work on (intro & a video)
intro = VideoFileClip('./videos/intro.mp4')
original = VideoFileClip('./videos/original_video.mp4')
# We cut 2s and crop the original video
original.cutout(0, 2)
original = vfx.crop(original, x1=10)
# Adding a watermark on top of the original video
watermark = (ImageClip("./images/watermark.png")
.set_duration(original.duration)
.set_position(("center","bottom"))
.resize(width=intro.w))
watermaked = CompositeVideoClip([original, watermark], size=original.size)
# Our final video: Intro + Waterkarmed, and output it.
final_render = concatenate_videoclips([intro, watermaked], method='compose')
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1)
错误堆栈:
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1)
File "<decorator-gen-51>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "<decorator-gen-50>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
return f(clip, *new_a, **new_kw)
File "<decorator-gen-49>", line 2, in write_videofile
File "/usr/lib/python2.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "/usr/lib/python2.7/site-packages/moviepy/video/VideoClip.py", line 288, in write_videofile
raise ValueError("MoviePy couldn't find the codec associated "
ValueError: MoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile.
您需要使用 codec 参数手动设置编解码器。
代码应如下所示:
final_render.write_videofile('./videos/output_video.mp4', fps=30, threads=1, codec="libx264")
编解码器根据视频文件扩展名变化:
Extension | Codec |
---|---|
mp4 | libx264 |
ogv | libtheora |
webm | libvpx |
ogg | libvorbis |
mp3 | pcm_s16le |
wav | libvorbis |
m4a | libfdk_aac |