在 Python 中以编程方式生成视频或动画 GIF? [英] Programmatically generate video or animated GIF in Python?

查看:26
本文介绍了在 Python 中以编程方式生成视频或动画 GIF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列图像,我想从中创建视频.理想情况下,我可以为每一帧指定一个帧持续时间,但固定的帧速率也可以.我在 wxPython 中这样做,所以我可以渲染到 wxDC 或者我可以将图像保存到文件中,比如 PNG.是否有 Python 库可以让我从这些帧创建视频(AVI、MPG 等)或动画 GIF?

I have a series of images that I want to create a video from. Ideally I could specify a frame duration for each frame but a fixed frame rate would be fine too. I'm doing this in wxPython, so I can render to a wxDC or I can save the images to files, like PNG. Is there a Python library that will allow me to create either a video (AVI, MPG, etc) or an animated GIF from these frames?

我已经尝试过 PIL,但它似乎不起作用.有人可以用这个结论纠正我或建议另一个工具包吗?这个链接似乎支持我关于 PIL 的结论:http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/

I've already tried PIL and it doesn't seem to work. Can someone correct me with this conclusion or suggest another toolkit? This link seems to backup my conclusion regarding PIL: http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/

推荐答案

好吧,现在我正在使用 ImageMagick.我将帧保存为 PNG 文件,然后从 Python 调用 ImageMagick 的 convert.exe 来创建动画 GIF.这种方法的好处是我可以单独为每个帧指定一个帧持续时间.不幸的是,这取决于机器上安装的 ImageMagick.他们有一个 Python 包装器,但它看起来很糟糕而且不受支持.仍然愿意接受其他建议.

Well, now I'm using ImageMagick. I save my frames as PNG files and then invoke ImageMagick's convert.exe from Python to create an animated GIF. The nice thing about this approach is I can specify a frame duration for each frame individually. Unfortunately this depends on ImageMagick being installed on the machine. They have a Python wrapper but it looks pretty crappy and unsupported. Still open to other suggestions.

这篇关于在 Python 中以编程方式生成视频或动画 GIF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆