python 2.7中的FFMPEG文件编写器 [英] FFMPEG file writer in python 2.7

查看:69
本文介绍了python 2.7中的FFMPEG文件编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Trying to animate a string in python, i think my code is fine but just having difficulties with the file writer. My code is (based off 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文件的调用或放置中,但是我不确定自己在做什么错.可能非常明显,但暂时看不到/不确定错误消息的实际含义.

I think my error is in the calling or placement of the FFMpeg file but i'm unsure what i'm doing wrong. Probably very obvious but can't see it at the moment / unsure what the error message actually means.

推荐答案

您是否尝试过错误提示?在构造函数中传递参数:

Have you tried what the error says? passing the arguments in the constructor:

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

这篇关于python 2.7中的FFMPEG文件编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆