huny

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=r"out11.gif"):
    VideoFileClip(path).\
        subclip(duration[0], duration[1]).\
        speedx(0.3).\
        resize(0.5).\
        write_gif(savepath, fps=10, program="ffmpeg")

# 截取想要的部分的小姐姐图像
def SecondLevel(path="2.mp4", duration=((0, 4.8), (0, 6.3)), savepath="out1.gif", region=(0, 0, 540, 480)):
    VideoFileClip(path).\
        subclip(duration[0], duration[1]).\
        crop(x1=region[0], y1=region[1], x2=region[2], y2=region[3]).\
        speedx(0.3).\
        resize(0.5).\
        write_gif(savepath, fps=10, program="ffmpeg")


def ThirdLevel(path="2.mp4", duration=((0, 4.8), (0, 6.3)), savepath="out2.gif", region=(0, 0, 540, 480), text="菜鸟学python"):
    video = VideoFileClip(path). \
        subclip(duration[0], duration[1]). \
        crop(x1=region[0], y1=region[1], x2=region[2], y2=region[3]). \
        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="ffmpeg")


if __name__ == \'__main__\':
   ThirdLevel()

代码解析

这里运行会报一个错误:

 

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

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

 

分类:

技术点:

相关文章:

  • 2021-06-19
  • 2021-04-16
  • 2021-12-09
  • 2022-12-23
  • 2021-06-11
  • 2021-09-10
  • 2021-07-28
  • 2021-10-01
猜你喜欢
  • 2021-10-09
  • 2021-07-02
  • 2021-06-18
  • 2021-12-17
  • 2022-01-15
  • 2021-09-14
  • 2021-06-19
相关资源
相似解决方案