I'm trying to rotate a moviepy color clip without animating it, so that it is rotated at the start, and remains rotated until the end of the video.
I tried some code hoping that it would rotate a still image in MoviePy, without animating it. So that it is rotated by the input angle for the entire duration of the image, ColorClip, or 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)
However, this doesn't rotate the still image, because ImageClip doesn't have a rotation function.
This code below rotates until 3 seconds. and can be adapted for a fixed rotation / non animated by changing 20*t to the a constant like 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)
However, this code won't work for a 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)
instead it will give the following error
raise TypeError("Cannot handle this data type: %s, %s" % typekey)
TypeError: Cannot handle this data type: (1, 1, 3), <i8
because it reaches this line
return np.array( Image.fromarray(pic).rotate(angle, expand=expand),
inside pil_rotater.
How can I rotate a moviepy ColorClip by 20 degrees ?