在ImageClip中使用gif不起作用,这是正常行为吗?
#!/usr/bin/env python
from moviepy.editor import *
video = VideoFileClip('./video.mp4')
watermark = (ImageClip("./my.gif")
.set_duration(10))
watermaked = CompositeVideoClip([video, watermark], size=video.size)
watermaked.write_videofile('./gif_output.mp4', fps=30, threads=1)
ValueError: could not broadcast input array from shape (150,150) into shape (150,150,3)
Traceback (most recent call last):
File "./gif_test.py", line 9, in <module>
watermaked.write_videofile('./gif_output.mp4', fps=30, threads=1)
File "<decorator-gen-51>", line 2, in write_videofile
File "/Library/Python/2.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 "/Library/Python/2.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 "/Library/Python/2.7/site-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, *a, **k)
File "/Library/Python/2.7/site-packages/moviepy/video/VideoClip.py", line 349, in write_videofile
progress_bar=progress_bar)
File "/Library/Python/2.7/site-packages/moviepy/video/io/ffmpeg_writer.py", line 209, in ffmpeg_write_video
fps=fps, dtype="uint8"):
File "/Library/Python/2.7/site-packages/tqdm/_tqdm.py", line 833, in __iter__
for obj in iterable:
File "/Library/Python/2.7/site-packages/moviepy/Clip.py", line 475, in generator
frame = self.get_frame(t)
File "<decorator-gen-14>", line 2, in get_frame
File "/Library/Python/2.7/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "/Library/Python/2.7/site-packages/moviepy/Clip.py", line 95, in get_frame
return self.make_frame(t)
File "/Library/Python/2.7/site-packages/moviepy/video/compositing/CompositeVideoClip.py", line 110, in make_frame
f = c.blit_on(f, t)
File "/Library/Python/2.7/site-packages/moviepy/video/VideoClip.py", line 611, in blit_on
return blit(img, picture, pos, mask=mask, ismask=self.ismask)
File "/Library/Python/2.7/site-packages/moviepy/video/tools/drawing.py", line 45, in blit
new_im2[yp1:yp2, xp1:xp2] = blitted
ValueError: could not broadcast input array from shape (150,150) into shape (150,150,3)
答案 0 :(得分:0)
TL:DR,
Gif被视为视频:VideoFileclip(“image.gif”)而不是ImageClip(“image.gif”)。
#!/usr/bin/env python
from moviepy.editor import *
video = VideoFileClip('./video.mp4')
watermark = VideoFileclip("./image.gif")
watermaked = CompositeVideoClip([video, watermark], size=video.size)
watermaked.write_videofile('./gif_output.mp4', fps=30, threads=1)