我必须使用角色图像在电影中创建动画视频。
我有每个角色的png
个文件。
我想要的是制作固定尺寸 600x600 的空白视频,然后使用ImageClip
动画只是从左或右滑动到视频中的位置。
到目前为止我所做的是
from moviepy.editor import *
from moviepy.video.tools.segmenting import findObjects
import numpy as np
# animating image
img_character_doctor = 'media/hair_loss/png/doctor_1-01.png'
img_comment_box = 'media/hair_loss/png/comment.png'
text_comment = 'Hello Doctor'
video_size = (600,600)
# SLIDE FUNCTIONS
# slides from right to left
def arrive(screenpos,i):
v = np.array([-1,0])
print(v)
d = lambda t : max(0, 3-3*t)
print(d)
return lambda t: screenpos-400*v*d(t-0.2*i)
# slides from left to right
def arrive_opposite(screenpos,i):
v = np.array([-1,0])
d = lambda t : max(0, 3-3*t)
return lambda t: screenpos+400*v*d(t-0.2*i)
# empty video
videoMain = ColorClip(video_size, duration=3)
# character 1: doctor
clipImgCharacterDoctor = ImageClip(img_character_doctor)
# comment box
clipImgCommentBox = ImageClip(img_comment_box)
# comment text
txtClipCommentText = TextClip(text_comment, color='red', font='Amiri-Bold', kerning=5, fontsize=60)
# PREPARING CLIP ANIMATIONS
# animate doctor character clip
animate_clipImgCharacterDoctor = (clipImgCharacterDoctor.set_position(arrive_opposite(5,5), 0).set_duration(5))
animate_clipImgCharacterDoctor.fps = 24
# animate comment box
animate_clipImgCommentBox = (clipImgCommentBox.set_position(arrive(200,0), 0).set_duration(3).set_start(2))
animate_clipImgCommentBox.fps = 24
# animate text
animate_txtClipCommentText = (txtClipCommentText.set_position(arrive(100, 0),0).set_duration(2).set_start(3))
# animate_txtClipCommentText = (txtClipCommentText.set_pos(arrive(350,2), 0).set_duration(2).set_start(3))
output_clip = CompositeVideoClip([
animate_clipImgCharacterDoctor,
animate_clipImgCommentBox,
animate_txtClipCommentText
])
output_clip.fps = 24
output_clip.write_videofile('animate_doctor.avi', fps=24, codec='mpeg4')
output_clip.ipython_display(width=500)
我对此代码的问题很少
arrive
和arrive_opposite
未按预期工作。我希望传递4个参数start_x
,start_y
,end_x
,end_y
,因此图片或剪辑会从(start_x, start_y)
滑动到{{1 }}。
截至目前,视频大小已达到视频中使用的最大图片的大小。我想将视频大小固定为 600x600 ,但在 CompositeVideoClip 中使用 videoMain 会出错。
示例输出视频:https://www.dropbox.com/s/a9lqqaad6lcotk3/bx_6xPz8.mp4?dl=0
使用的文件:https://www.dropbox.com/s/uf8w4g27jkbuiqu/png.zip?dl=0