使用ffmpeg麻烦保存matplotlib动画 [英] Trouble saving matplotlib animation with ffmpeg
问题描述
我安装了ffmpeg,并希望保存动画.
I installed ffmpeg and would like to save an animation.
我的代码是
#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'])
动画运行并且看起来不错,但是我无法保存它.错误消息(在此阶段)是
The animation runs and it looks good, but I just can't get it to save. The error message (at this stage) is
我不确定出了什么问题.任何帮助表示赞赏.
I am not sure what's going wrong. Any help is appreciated.
以下无法保存matplotlib动画我添加的
plt.rcParams['animation.ffmpeg_path'] ='C:\\Program Files\\ffmpeg \\bin\\ffmpeg.exe'
哪个返回 警告:无法更改为其他GUI工具箱:qt.改用qt4. 错误:执行中止
Which returns Warning: Cannot change to a different GUI toolkit: qt. Using qt4 instead. ERROR: execution aborted
推荐答案
提供我的评论作为答案:
我认为您应该在实例的初始化中直接指定FFMpegWriter
的参数,而不是将某些参数提供给动画save
方法.
I think you should specify the arguments to FFMpegWriter
directly in the initialization of that instance instead of supplying some of them to the animation save
method.
FFwriter = animation.FFMpegWriter(fps=30, extra_args=['-vcodec', 'libx264'])
ani.save('basic_animation.mp4', writer = FFwriter)
这篇关于使用ffmpeg麻烦保存matplotlib动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!