Python:MP4转GIF_Moviepy

本文介绍了如何使用Python库MoviePy将MP4视频转换为GIF格式,过程中遇到的imageio安装问题及解决方案。通过示例代码演示了如何裁剪、缩放视频并设置输出参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

      相关文件地址及转换数据示意图:
在这里插入图片描述

>> 更多相关内容,点击Morven_Xie博客概览

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值