matplotlib 动画电影:电影质量随时间下降 [英] matplotlib animation movie: quality of movie decreasing with time

查看:58
本文介绍了matplotlib 动画电影:电影质量随时间下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用matplotlib中的 animation.FuncAnimation 函数创建电影.这部电影在交互中看起来不错,但是当我用命令保存时

I am trying to create a movie with the animation.FuncAnimation function in matplotlib. The movie looks fine interactively, but when I save it with the command

anim2.save('somefilm.mp4',codec='mpeg4', fps=15)

开始很好,但后来变得模糊(都使用 QuickTime 和 vlc,所以我认为这是电影,而不是播放器).

It starts out fine, but then becomes blurry (both using QuickTime and vlc, so I figured it's the movie, not the player).

我玩过blitting,因为我认为这可能是因为画布没有重绘,但无济于事.增加比特率也无济于事.

I've played around with blitting, since I thought it was maybe the fact that the canvas wasn't redrawn, but to no avail. Increasing the bitrate also doesn't help.

设置 dpi = 500 确实会提高电影的质量,尽管随后反复出现卡住现象,这使观看变得困难.

Setting dpi=500 does improve the quality of the movie somewhat, though then it gets stuck repeatedly, which makes it difficult to watch.

我只是想知道这是否是最好的选择,还是我错过了什么?

I was just wondering whether this is the best one can do, or am I missing something?

推荐答案

要深入研究此问题,重要的是要了解视频文件通常以高度有损的压缩方式进行压缩,而交互式显示则不进行压缩.通常的电影压缩通常对图形极为不利,这与压缩参数有关.

In order to dig into this problem it is important to understand that video files are usually compressed with a highly lossy compression whereas the interactive display is not compressed. The usual movie compressions are often extremely bad with graphs, and it is a matter of compression parameters.

您可以做四件事:

  • 设置图像分辨率(通过 dpi ),但这实际上可能会使输出在视觉上更差,因为问题通常出在缺少像素上

  • set the image resolution (by dpi), but this may actually make the output visually poorer, as the problem is usually not in the lacking pixels

设置图像比特率(通过 bitrate );你的比特率越高,你的电影就越好 - 一种可能性是设置 bitrate=-1 并让 matplotlib 选择最佳比特率

set the image bitrate (by bitrate); the higher your bitrate, the better your movie will be - one possibility is to set bitrate=-1 and let matplotlib choose the best bitrate

更改编解码器(例如,更改为 codec="libx264")

change the codec (e.g., to codec="libx264")

为编解码器提供额外的参数(例如,extra_args=['-pix_fmt', 'yuv420p'])

give extra arguments to the codec (e.g., extra_args=['-pix_fmt', 'yuv420p'])

不幸的是,这些选项确实取决于视频编解码器,第三方程序(通常为 ffmpeg ),视频的预期用途以及平台.我会首先添加 kwarg bitrate=-1 以查看它是否有所改善.

Unfortunately, these options really depend on the video codec, which is a third-party program (usually ffmpeg), the intended use of your video, and your platform. I would start by adding the kwarg bitrate=-1 to see if it improves things.

如果无法使其正常工作,请添加一个完整的(但要尽可能简单)示例,以说明如何创建错误的文件.那就更容易调试了!

If you cannot make it work, please add a full (but as simple as possible) example of how to create a bad file. Then it is easier to debug!

这篇关于matplotlib 动画电影:电影质量随时间下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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