推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
linzhi
V2EX  ›  Python

把 vedio 比如.mp4 格式的短视频转换为 gif 图 有啥方便的办法么。。查了个 Python 的库 moviepy, but 有个问题需要 fix 才能使用

  •  
  •   linzhi · Feb 23, 2017 · 5793 views
  •   You need to sign in to view this topic
    This topic created in 3555 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Feb 23, 2017
    video 笔误 抱歉~~~
    23 replies  •  2017-02-27 10:40:47 +08:00
    liujun3712
    liujun3712
    Feb 23, 2017 via Android❤️2
    1
    你这个 vedio 我看了半天
    timwei
    timwei
    Feb 23, 2017❤️2
    2
    我 research 下;再 answer 你的 question 。
    justou
    justou
    Feb 23, 2017
    3
    moviepy 用的 ffmpeg, imagemagick 为底层, 可以直接在 py 中调用它们的命令行.
    moviepy 有啥问题捏?
    kera0a
    kera0a
    Feb 23, 2017
    4
    我调研一番后, 是直接 python 调 ffmpeg 命令行~
    linzhi
    linzhi
    OP
    Feb 23, 2017
    5
    @liujun3712 sorry 写错了。。。
    linzhi
    linzhi
    OP
    Feb 23, 2017
    6
    justou
    justou
    Feb 23, 2017
    7
    把 write_gif 的 program 参数改成'ffmpeg'或者'ImageMagick'试试, 默认的的 imageio 不好用, 兼容性似乎也有问题. 不过要另外去下 ffmpeg 或者 imagemagick 安装
    ys0290
    ys0290
    Feb 23, 2017 via iPhone
    8
    ps
    linzhi
    linzhi
    OP
    Feb 23, 2017
    9
    @justou 恩 感谢 program 使用 ffmpeg 可以正常
    justou
    justou
    Feb 23, 2017❤️1
    10
    我这儿试了下, 两个都可以用. 转化成 gif imagemagick 要比 ffmpeg 好很多, ffmpeg 的输出有时很诡异, 画面会花, 使用 imagemagick 的时候要把参数 opt 设置为 optimizeplus 或 OptimizeTransparency, 不然 py 可能卡死. 虽然生成的图会大点, 但是效果很好. 想要精确控制的话还是直接调用相应命令行, 传一摞参数进去, moviepy 只提供了简单功能.
    exoticknight
    exoticknight
    Feb 23, 2017❤️1
    11
    直接用 ffmpeg ?根据我的经验,凡是视频的东西找它就对了……
    likuku
    likuku
    Feb 23, 2017
    12
    刚刚随手测试了下, ffmpeg 先视频转 dpx 序列帧,再从序列帧转成 gif ,这样 OK 的。

    69M h264 1080p 30fps 视频,转 dpx 序列帧 6.6GB ,转 480p 10fps gif , 88M

    ffmpeg -i IMG_.MOV dpx/t_%06d.dpx
    ffmpeg -y -i dpx/t_%06d.dpx -vf scale=-1:480 -r 10 t.gif

    Orz
    likuku
    likuku
    Feb 23, 2017❤️1
    13
    ffmpeg 直接视频转 480p 10fps gif , gif 74MB
    ffmpeg -i IMG.MOV -vf scale=-1:400 -r 10 t.gif

    ffmpeg 直接视频转成 100p 10fps gif , gif 2.1MB
    ffmpeg -y -i IMG.MOV -vf scale=-1:100 -r 10 t.gif

    $ file t.gif
    t.gif: GIF image data, version 89a, 178 x 100

    $ du -sh t.gif
    2.1M t.gif
    myself659410
    myself659410
    Feb 23, 2017
    14
    @likuku ffmpeg 真是音视频处理的瑞士军刀
    biubuibiu
    biubuibiu
    Feb 23, 2017❤️1
    15
    UPYUN
    UPYUN
    Feb 24, 2017
    17
    又拍云可以定制此功能,需要的话可联系 https://www.upyun.com/index.html 客服:)
    linzhi
    linzhi
    OP
    Feb 24, 2017
    18
    @justou 用 imagemagick 看来要设置参数,直接用的话 会一直卡在 0%。。。
    linzhi
    linzhi
    OP
    Feb 24, 2017
    19
    @likuku 这个视频转 gif ,一般会选择 10 fps 么,选的过大,造成 gif 太大 无法展示,选择太小又容易失真
    likuku
    likuku
    Feb 24, 2017
    20
    @linzhi 这个得自己测试了,得看画面动态幅度大小吧... 我尝试用 mediainfo 来检查 gif 文件,发现并无 fps 这个属性。
    linzhi
    linzhi
    OP
    Feb 27, 2017
    21
    @justou 奇怪 我这用 clip.write_gif("dog.gif", program='imagemagick', opt="OptimizeTransparency") 或者 clip.write_gif("dog.gif", program='imagemagick', opt="optimizeplus") python 都会卡死。。。转换的进度一直在 0%
    linzhi
    linzhi
    OP
    Feb 27, 2017
    22
    @justou 不对 是用 ImageMagick
    linzhi
    linzhi
    OP
    Feb 27, 2017
    23
    @justou 使用 ImageMagick 清晰 不过压缩后太大了。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2486 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 63ms · UTC 11:31 · PVG 19:31 · LAX 03:31 · JFK 06:31
    ♥ Do have faith in what you're doing.