gpt4 book ai didi

python - python 2.7中的FFMPEG文件编写器

转载 作者:行者123 更新时间:2023-12-04 22:53:31 31 4
gpt4 key购买 nike

尝试在 python 中为字符串设置动画,我认为我的代码很好,但文件编写器遇到了困难。我的代码是(基于 https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ ):

import numpy as np
import scipy as sci
import matplotlib.pyplot as plt
import matplotlib.animation as 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()

当前收到错误消息
RuntimeError: Passing in values for arguments for arguments fps, codec, bitrate, extra_args, or metadata is not supported when writer is an existing MovieWriter instance. These should instead be passed as arguments when creating the MovieWriter instance.'

我认为我的错误在于 FFMpeg 文件的调用或放置,但我不确定我做错了什么。可能非常明显,但目前看不到/不确定错误消息的实际含义。

最佳答案

您是否尝试过错误所说的内容?在构造函数中传递参数:

FFwriter=animation.FFMpegWriter(fps=30, extra_args=['-vcodec', 'libx264'])
anim.save('basic_animation.mp4', writer=FFwriter)

关于python - python 2.7中的FFMPEG文件编写器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43251965/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com