matplotlib.animation:脚本在Windows下运行,在Linux下可以用于短动画,但是可以无限期挂起以获得更长的动画效果吗?

时间:2014-08-15 18:50:19

标签: python animation matplotlib debian

以下是相关的代码段:

ani = animation.FuncAnimation(fig, animate, outputFiles, blit=True, interval=25)

print "Starting to write animation file..."
# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']

fps = 2
animationFileName = "animation"
if fps <= 2:
    animationFileName = animationFileName + "_slow.mp4"
if fps < 120:
    animationFileName = animationFileName + ".mp4"
else:
    animationFileName = animationFileName + "_fast.mp4"

writer = Writer(fps=fps, metadata=dict(artist='Alien'), bitrate=1800)
ani.save(os.path.join(graphicsOutputDirectory, animationFileName), writer=writer)
print "Finished writing animation file..."

在Linux(Debian Wheezy)中运行脚本时,我看到以下输出:

>>> python make_animation.py
Starting to run animation file...

在Windows中,脚本运行得很好。我已经确定我没有像使用不正确的文件名那样犯愚蠢的错误。简短的动画似乎在我的GNU / Linux机器上运行得很好,而更严重的动画似乎无限期地挂起......

这里的问题可能是什么?我想我应该提到的一个相关细节是我使用虚拟环境来运行matplotlib的最新版本。

1 个答案:

答案 0 :(得分:1)

Ubuntu和Debian现在发布了弃用的FFMPEG版本。这可能是个问题。尝试用FFMPEG网站上的最新版本替换/ usr / bin中的ffmpeg二进制文件。

另一个可能的问题涉及Python 3,其中子进程具有较小的缓冲区,并且如果ffmpeg将过多的信息发送回Python,它将永远挂起。你是Python 3吗?