animation - FFMPEG file writer in python 2.7 -
trying animate string in python, think code fine having difficulties file writer. code (based off https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/):
import numpy np import scipy sci import matplotlib.pyplot plt import matplotlib.animation animation plt.rcparams['animation.ffmpeg_path'] = 'c:\ffmpeg\bin\ffmpeg' s1=10.15 gamma=(np.pi*np.sqrt(2))/2 gamma=sci.special.jn_zeros(0,10) gamma1=gamma[9] gamma2=gamma[8] print gamma1,gamma2 sigma=np.linspace(0,2*s1,10000) def xprime(sigma,t): alpha = gamma1*(np.cos(np.pi*t/s1)*np.cos((np.pi*sigma)/s1)) beta = gamma1*(np.sin(np.pi*t/s1)*np.sin((np.pi*sigma)/s1)) xprime=np.cos(alpha)*np.cos(beta) return xprime def yprime(sigma,t): alpha = gamma2*(np.cos(np.pi*t/s1)*np.cos((np.pi*sigma)/s1)) beta = gamma2*(np.sin(np.pi*t/s1)*np.sin((np.pi*sigma)/s1)) yprime=np.cos(alpha)*np.sin(beta) return yprime fig = plt.figure() ax = plt.axes(xlim=(-0.4, 0.4), ylim=(-3, 3)) line, = ax.plot([], [], lw=2) def init(): line.set_data([], []) return line, def animate(i): sigma=np.linspace(0,2*s1,10000) t = (i*2*s1)/200 yint=sci.integrate.cumtrapz(yprime(sigma,t),sigma) xint=sci.integrate.cumtrapz(xprime(sigma,t),sigma) line.set_data(xint, yint) return line, anim = animation.funcanimation(fig, animate, init_func=init, frames=200, interval=20, blit=true) ffwriter=animation.ffmpegwriter() anim.save('basic_animation.mp4', writer=ffwriter, fps=30, extra_args=['-vcodec', 'libx264']) plt.show()
currently getting error message
runtimeerror: passing in values arguments arguments fps, codec, bitrate, extra_args, or metadata not supported when writer existing moviewriter instance. these should instead passed arguments when creating moviewriter instance.'
i think error in calling or placement of ffmpeg file i'm unsure i'm doing wrong. obvious can't see @ moment / unsure error message means.
have tried error says? passing arguments in constructor:
ffwriter=animation.ffmpegwriter(fps=30, extra_args=['-vcodec', 'libx264']) anim.save('basic_animation.mp4', writer=ffwriter)
Comments
Post a Comment