无法在Python中使用FFMPEG录制视频

时间:2019-05-23 18:54:47

标签: python python-3.x matplotlib 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"

已解决:

我只需要颠倒绘图的顺序并保存。

0 个答案:

没有答案