为什么有时在moviepy中连接图像会失败?

时间:2015-03-21 07:01:04

标签: python animation moviepy

我使用以下代码读取两个图像,设置它们的持续时间并将它们连接成一个动画。

from moviepy.editor import *

ic_1 = ImageClip('pg_0.png')
ic_1 = ic_1.set_duration(2.0)

ic_2 = ImageClip('pg_1.png')
ic_2 = ic_2.set_duration(2.0)

video = concatenate([ic_1, ic_2], method="compose")
video.write_videofile('test.avi', fps=24, codec='mpeg4')

它符合pg_0.pngpg_1.png的预期效果。但是,如果我用另外两张图片替换这两张图片,我会收到一条错误消息:

ValueError: operands could not be broadcast together with shapes (272,363,3) (272,363) 

如果需要更多详细信息,请输入以下完整信息:

[MoviePy] >>>> Building video test.avi
[MoviePy] Writing video test.avi
|----------| 0/97   0% [elapsed: 00:00 left: ?, ? iters/sec]Traceback (most recent call last):
  File "test2.py", line 12, in <module>
    video.write_videofile('test.avi', fps=24, codec='mpeg4')
  File "<string>", line 2, in write_videofile
  File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<string>", line 2, in write_videofile
  File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "<string>", line 2, in write_videofile
  File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 339, in write_videofile
    ffmpeg_params=ffmpeg_params)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 204, in ffmpeg_write_video
    fps=fps, dtype="uint8"):
  File "/usr/local/lib/python2.7/dist-packages/tqdm.py", line 78, in tqdm
    for obj in iterable:
  File "/usr/local/lib/python2.7/dist-packages/moviepy/Clip.py", line 473, in generator
    frame = self.get_frame(t)
  File "<string>", line 2, in get_frame
  File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/Clip.py", line 95, in get_frame
    return self.make_frame(t)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/compositing/CompositeVideoClip.py", line 110, in make_frame
    f = c.blit_on(f, t)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 571, in blit_on
    return blit(img, picture, pos, mask=mask, ismask=self.ismask)
  File "/usr/local/lib/python2.7/dist-packages/moviepy/video/tools/drawing.py", line 45, in blit
    new_im2[yp1:yp2, xp1:xp2] = blitted
ValueError: operands could not be broadcast together with shapes (272,363,3) (272,363) 

为什么形状不同?我使用的所有图像都看作普通的png图像。我该如何解决这个问题?

0 个答案:

没有答案