python - 无法在 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"
解决:
我只需要颠倒情节的顺序并保存。
解决方案
推荐阅读
- r - 从相关热图中获取特定列
- pandas - 从 pandas 数据框中删除 nan 并重塑数据框
- snowflake-cloud-data-platform - 强制立即清除永久表
- python-3.x - 文本输入突然停止在 Kivy 应用程序中工作
- drupal-8 - 我正在尝试更改我的 custon 模块中的路线。但它已经在其中一个 contrib 模块中被覆盖
- php - Laravel Passport JWT 身份验证失败
- c# - 为什么最初为所有数组列表项调用 CellValueNedded
- git - 为什么 git clean 和 reset 会留下文件?
- python - 在 heroku 上使用 eventlet 部署 Flask Socket.io 应用程序
- circuit-sdk - USER.SUBMIT_FORM_DATA:UPDATE Outgoing WebHook 调用的事件过滤器失败