【发布时间】:2015-09-07 01:01:58
【问题描述】:
在 Raspbian (Raspberry Pi 2) 上,从我的脚本中删除的以下最小示例正确地生成了一个 mp4 文件:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
def anim_lift(x, y):
#set up the figure
fig = plt.figure(figsize=(15, 9))
def animate(i):
# update plot
pointplot.set_data(x[i], y[i])
return pointplot
# First frame
ax0 = plt.plot(x,y)
pointplot, = ax0.plot(x[0], y[0], 'or')
anim = animation.FuncAnimation(fig, animate, repeat = False,
frames=range(1,len(x)),
interval=200,
blit=True, repeat_delay=1000)
anim.save('out.mp4')
plt.close(fig)
# Number of frames
nframes = 200
# Generate data
x = np.linspace(0, 100, num=nframes)
y = np.random.random_sample(np.size(x))
anim_lift(x, y)
现在,制作的文件质量很好,而且文件大小非常小,但是制作 170 帧的电影需要 15 分钟,这对我的应用程序来说是不可接受的。我正在寻找显着的加速,视频文件大小增加不是问题。
我认为视频制作的瓶颈在于将帧临时保存为 png 格式。在处理过程中,我可以看到 png 文件出现在我的工作目录中,CPU 负载仅为 25%。
请提出一个解决方案,该解决方案也可能基于不同的包,而不是简单的 matplotlib.animation,例如 OpenCV(无论如何已经导入到我的项目中)或 moviepy。
正在使用的版本:
- python 2.7.3
- matplotlib 1.1.1rc2
- ffmpeg 0.8.17-6:0.8.17-1+rpi1
【问题讨论】:
标签: python matplotlib ffmpeg raspberry-pi raspbian