gpt4 book ai didi

python - 虽然安装了 ffmpeg,但无法将 mp4 文件保存在磁盘上

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

虽然我已经安装了ffmpeg , matplotlib 报告 MovieWriter ffmpeg is unavailable并且创建的 MP4 文件是空的。

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,

# animation function. This is called sequentially
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,

# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)

# save the animation as an mp4. This requires ffmpeg or mencoder to be
# installed. The extra_args ensure that the x264 codec is used, so that
# the video can be embedded in html5. You may need to adjust this for
# your system: for more information, see
# http://matplotlib.sourceforge.net/api/animation_api.html
anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264'])

plt.show()

我什至添加了 plt.switch_backend('TkAgg') 行在另一个帖子中提出,没有任何改变。这是我的matplotlib:
Name: matplotlib
Version: 2.1.0
Summary: Python plotting package
Home-page: http://matplotlib.org

我的ffmpeg:
Name: ffmpeg
Version: 1.4
Summary: ffmpeg python package url [https://github.com/jiashaokun/ffmpeg]
Home-page: https://github.com/jiashaokun/ffmpeg

和我的 Python 版本:
Python 3.6.5

我得到的错误是:
/usr/local/lib/python3.6/site-packages/matplotlib/animation.py:1218: UserWarning: MovieWriter ffmpeg unavailable
warnings.warn("MovieWriter %s unavailable" % writer)

这个错误在stackoverflow上已经报过很多次了,每次的解决方法是要么安装 ffmpeg (我的已安装)或添加关于后端的额外行,这对我来说没有任何改变。

奇怪的是 plt.show()命令有效,我确实预览了动画,但保存它的唯一文件格式是(非动画)PNG。

最佳答案

终于在an older stackoverflow post找到了答案: 那些说“安装ffmpeg ”并不意味着“安装 Python 包 ffmpeg ”,而是“安装二进制文件 ffmpeg ” 可以从 the FFMPEG official site 获得.一旦我这样做了,一切都很好。对于那些使用 Mac 的用户,并且由于本网站上没有安装说明:下载最新版本的 ffmpeg作为 DMG,打开 DMG,将文件复制到桌面上,然后执行 sudo cp ~/Desktop/ffmpeg /usr/local/bin ,这就是你所需要的。

关于python - 虽然安装了 ffmpeg,但无法将 mp4 文件保存在磁盘上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56210075/

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