我正在尝试使用Python对参数化复杂函数的颜色映射表示进行动画处理。我逐渐将一些东西放在一起,并检查它们是否正常工作。但是我不能保存动画。
我遇到了这个错误:
Requested MovieWriter (ffmpeg) not available
然而,ffmpeg确实安装在我的系统上,在Windows控制台上,ffmpeg -version
会返回各种关于ffmpeg的信息。此外,我还使用pip pip install ffmpeg
在Python脚本目录中安装了ffmpeg,这是成功的。我还在我的代码中设置了ffmepg路径:plt.rcParams['animation.ffmpeg_path'] = "C:\FFmpeg\bin\ffmpeg.exe"
我的点子快用完了。
这是我的代码。感谢您的阅读。
import numpy as np
import math
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
pi=math.pi
plt.rcParams['animation.ffmpeg_path'] = "C:\FFmpeg\bin\ffmpeg.exe"
fig = plt.figure()
def complex_array_to_rgb(X, theme='dark', rmax=None):
absmax = rmax or np.abs(X).max()
Y = np.zeros(X.shape + (3,), dtype='float')
Y[..., 0] = np.angle(X) / (2 * pi) % 1
if theme == 'light':
Y[..., 1] = np.clip(np.abs(X) / absmax, 0, 1)
Y[..., 2] = 1
elif theme == 'dark':
Y[..., 1] = 1
Y[..., 2] = np.clip(np.abs(X) / absmax, 0, 1)
Y = matplotlib.colors.hsv_to_rgb(Y)
return Y
# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
fps = 10
nSeconds = 1
snapshots = [ complex_array_to_rgb(np.array([[3*(x + 1j*y)**(2.9+p/300) + 1/(x + 1j*y)**2 for x in np.arange(-1,1,0.05)] for y in np.arange(-1,1,0.05)])) for p in range( nSeconds * fps ) ]
fig = plt.figure( figsize=(3,3) )
Z2=snapshots[0]
im=plt.imshow(Z2, extent=(-1,1,-1,1))
def animate_func(i):
if i % fps == 0:
print( '.')
im.set_array(snapshots[i])
return [im]
anim = animation.FuncAnimation(
fig,
animate_func,
frames = nSeconds * fps,
interval = 1000 / fps, # in ms
)
anim.save('test_anim.mp4', writer=writer)
发布于 2020-07-03 18:47:29
Python在字符串中使用反斜杠作为转义字符,因此它们会扰乱您的文件路径。尝试使用以下任一方法
plt.rcParams['animation.ffmpeg_path'] = "C:/FFmpeg/bin/ffmpeg"
或者,更混乱一点
plt.rcParams['animation.ffmpeg_path'] = "C:\\FFmpeg\\bin\\ffmpeg"
如果这也不起作用,你可以尝试直接使用ffmpeg编写器类:
FFwriter = animation.FFMpegWriter()
发布于 2021-10-15 13:37:44
使用Windows10和JupyterLab
我以前做过一些动画,效果很好……但几天前,我使用了完全相同的笔记本/计算机,但它失败了,给出了错误
RuntimeError: Requested MovieWriter (ffmpeg) not available
当然,FFmpeg就在那里!经过搜索,我发现有不止一个,与其他软件(OBS,Shotcut等)相关联。
在尝试了很多方法之后,唯一起作用的就是下载一个版本(https://www.gyan.dev/ffmpeg/builds/),并在笔记本中添加如下地址(包括'ffmpeg.exe')
plt.rcParams['animation.ffmpeg_path'] = r'c:\FFMPEG\ffmpeg-2021-10-14-git-c336c7a9d7-full_build\bin\ffmpeg.exe'
https://stackoverflow.com/questions/62699992
复制相似问题