使用python的moviepy库。
首先安装moviepy库:
1.进入cmd,pip install moviepy
安装时若出现错误:
Cannot uninstall 'imageio'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决方法为:pip install moviepy --ignore-install imageio
2.使用代码:
import moviepy.editor as mpy
#视频文件的本地路径
content = mpy.VideoFileClip("F:\cejing.mp4")
# 剪辑0分0秒到0分4秒的片段。resize为修改清晰度
c1 = content.subclip((0,0),(0,4)).resize((480,320))
# 将片段保存为gif图到python的默认路径
c1.write_gif("gav24.gif")
运行,完活!