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