首页 > 解决方案 > 无法在 Python 中使用 FFMPEG 录制视频

问题描述

我使用 python 生成了这个动画。一旦它生成,它应该制作一个视频。我已经创建了文件,但是我得到了一个回溯错误。当我尝试打开文件时,里面什么都没有。

Windows 10,运行 python 3。

我弄乱了ffmpeg的PATH,直接放在文件夹里。我删除了一段生成唯一文件名的代码。并用字符串替换它。在此之前根本没有生成任何文件。

我也尝试更改编解码器,仍然没有。

创建视频的代码:

plt.show()
animation.save('Output_Test.mp4', fps=30, extra_args=['-vcodec', 'libx264'])

我希望只得到一个显示 Output_Test.mp4 的视频。我确实得到了,但它是空的。

回溯错误:

Traceback (most recent call last):
  File "C:\Users\andre\OneDrive\Desktop\FranchiseRevenueComparison-master\FranchiseAnimation.py", line 277, in <module>
    animation.save('Output_Test.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\animation.py", line 1139, in save
    anim._init_draw()
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\animation.py", line 1732, in _init_draw
    self._draw_frame(next(self.new_frame_seq()))
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\animation.py", line 1755, in _draw_frame
    self._drawn_artists = self._func(framedata, *self._args)
  File "C:\Users\andre\OneDrive\Desktop\FranchiseRevenueComparison-master\FranchiseAnimation.py", line 259, in animate
    self.ax.figure.canvas.draw()
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 10, in draw
    _backend_tk.blit(self._tkphoto, self.renderer._renderer, (0, 1, 2, 3))
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\site-packages\matplotlib\backends\_backend_tk.py", line 77, in blit
    photoimage.blank()
  File "C:\Users\andre\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 3548, in blank
    self.tk.call(self.name, 'blank')
_tkinter.TclError: invalid command name "pyimage10"

解决:

我只需要颠倒情节的顺序并保存。

标签: pythonpython-3.xmatplotlibffmpeg

解决方案


推荐阅读