【发布时间】:2020-03-30 22:02:51
【问题描述】:
我正在尝试旋转一个moviepy颜色剪辑而不对其进行动画处理,以便它在开始时旋转,并保持旋转直到视频结束。
我尝试了一些代码,希望它可以在 MoviePy 中旋转静止图像,而不是对其进行动画处理。以便在图像、ColorClip 或 Video 的整个持续时间内按输入角度旋转。
import moviepy.editor as mped
image = mped.ImageClip("image.jpg", duration=3)
image.rotate(20)
image.write_videofile('image_without_rotation.mp4', fps=5)
但是,这不会旋转静止图像,因为 ImageClip 没有旋转功能。
下面的代码会旋转到 3 秒。并且可以通过将 20*t 更改为像 20 这样的常量来适应固定旋转/非动画。
clip = mped.ImageClip('image.jpg')
rotated_clip = (clip.add_mask().fx(mped.vfx.rotate, lambda t: 20*t, expand=False).set_duration(3))
centered_rotated_clip = mped.CompositeVideoClip([rotated_clip.set_pos("center")])
centered_rotated_clip.write_videofile('rotated_image.mp4'), fps=10)
但是,此代码不适用于moviepy ColorClip。
color_clip = mped.ColorClip(size=[300, 300], color=[1 ,1, 1])
rotated_color_clip = (color_clip.fx(mped.vfx.rotate, lambda t: 20, expand=False).set_duration(3))
composited_clip = mped.CompositeVideoClip([rotated_Color_ clip.set_pos("center")])
composited_clip.write_videofile('rotated_clip.mp4', fps=10)
反而会出现以下错误
raise TypeError("Cannot handle this data type: %s, %s" % typekey)
TypeError: Cannot handle this data type: (1, 1, 3), <i8
因为它到达了这条线
return np.array( Image.fromarray(pic).rotate(angle, expand=expand),
在 pil_rotater 内部。
如何将moviepy ColorClip 旋转20 度?
【问题讨论】:
标签: python numpy python-imaging-library moviepy