0
我安装了ffmpeg并想保存动画。用ffmpeg节省matplotlib动画
我的代码是
#evo is the dataset composed of sequence of images
evo = np.load('bed_evolution_3000iter_2.npy')
fig = plt.figure(figsize=(15,15*2*width/length))
# make axesimage object
# the vmin and vmax here are very important to get the color map correct
im = plt.imshow(np.transpose(evo[0]), cmap=plt.get_cmap('jet'), vmin=0, vmax=1300)
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
fig.colorbar(im, cax=cbar_ax)
fig.subplots_adjust(right=0.8)
def updatefig(j):
# set the data in the axesimage object
im.set_array(np.transpose(evo[j]))
# return the artists set
return im,
# kick off the animation
ani = animation.FuncAnimation(fig, updatefig, frames=range(len(evo)),
interval=100, blit=True)
#now just need to get the ability to save... this uses
FFwriter = animation.FFMpegWriter()
ani.save('basic_animation.mp4', writer = FFwriter, fps=30, extra_args =([vcodec', 'libx264'])
动画运行和它看起来不错,但我只是不能让它保存。错误信息(在此阶段)是
我不知道发生了什么错误。任何帮助表示赞赏。
编辑: 继Can't save matplotlib animation我加
plt.rcParams['animation.ffmpeg_path'] ='C:\\Program Files\\ffmpeg \\bin\\ffmpeg.exe'
它返回 警告:不能切换到不同的GUI工具:QT。改用qt4。 错误:执行中止
内核似乎与下面的“编辑:”修订崩溃 – kevinkayaks
我不知道这是否是问题的原因,但你应该使用'='的论点。 ffmpeg路径中还有很多空间,不应该在那里。最后,我想你应该直接给'FFMpegWriter'指定参数:'FFwriter = animation.FFMpegWriter(fps = 30,extra_args = [' - vcodec','libx264']); ani.save('basic_animation.mp4',作家= FFwriter)'。 – ImportanceOfBeingErnest
谢谢@ImportanceOfBeingErnest。这只是一个在python和stack之间进行复制的错字。这不是问题的根源:( – kevinkayaks