1 功能介绍
视频文件上传优快云不方便,需要转换为GIF格式,同时网站对图片大小有限制(5M),博客介绍使用Moviepy(MP4转换GIF)。
2 轮子安装
安装时提示错误:ERROR: 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.参考博客优快云:woood小陈博客
在pip安装时,不直接采用pip install imageio,而用pip install --ignore-installed imageio。
2 源程序
参考Rachelnew1900_优快云:使用python 调用MoviePy制作GIF动图博客内容,源程序三段话:
- 引入库
- 调入视频压缩
- 转码
源程序如下:
from moviepy.editor import *
clipVideo =(VideoFileClip(r"D:\SoftApp\Python\MP4ToGIF\\MP4Data\3.mp4").subclip(0,16).resize(0.6))
clipVideo.write_gif(r"D:\SoftApp\Python\MP4ToGIF\MP4Data\3.gif", fps=2)
相关修改压缩GIF视频参数入如下:
@requires_duration
@convert_masks_to_RGB
def write_gif(self, filename, fps=None, program='imageio',
opt='nq', fuzz=1, verbose=True,
loop=0, dispose=False, colors=None, tempfiles=False,
logger='bar'):
""" Write the VideoClip to a GIF file.
相关文件地址及转换数据示意图: