python截取视频制作动态表情包+文字

前端之家收集整理的这篇文章主要介绍了python截取视频制作动态表情包+文字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1:安装moviepy库

 

 2:安装IPython库

 

 代码如下:

from moviepy.editor import *
from IPython.display import Image


def Base(path="2.mp4",duration=((0,4.8),(0,6.3)),savepath=rout11.gif"):
    VideoFileClip(path).\
        subclip(duration[0],duration[1]).\
        speedx(0.3).\
        resize(0.5).\
        write_gif(savepath,fps=10,program=ffmpeg)

# 截取想要的部分的小姐姐图像
def SecondLevel(path=out1.gif)):
    VideoFileClip(path).\
        subclip(duration[0],1)">]).\
        crop(x1=region[0],y1=region[1],x2=region[2],y2=region[3)


def ThirdLevel(path=out2.gif菜鸟学python):
    video = VideoFileClip(path). \
        subclip(duration[0],1)">]). \
        crop(x1=region[0],1)">]). \
        speedx(0.3). \
        resize(0.5)
     创建文字
    text = TextClip(text,fontsize=20,color='white',interline=25,font=FangSong)\
        .set_position((2,1)).\
        set_duration(video.duration)
    compose = CompositeVideoClip([video,text])
    compose.write_gif(savepath,program=if __name__ == __main__':
   ThirdLevel()

代码解析

这里运行会报一个错误

 

 解决办法:https://blog.csdn.net/kd_2015/article/details/80157713  此文章又详细的解决步骤,我就不再记录了

然后重新运行你的代码生成新的图片就是你需要的动态表情包加文字

 

猜你在找的Python相关文章