FFmpeg and Jupyter Notebooks



我得到错误RuntimeError: Requested MovieWriter (ffmpeg) not available时,试图运行这个简单的例子创建和显示动画在Jupyter笔记本

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-799d6a3690af> in <module>
8 
9 # Define the meta data for the movie
---> 10 FFMpegWriter = manimation.writers['ffmpeg']
11 metadata = dict(title='Movie Test', artist='Matplotlib',
12                 comment='a red circle following a blue sine wave')
/usr/local/lib/python3.8/dist-packages/matplotlib/animation.py in __getitem__(self, name)
164         if self.is_available(name):
165             return self._registered[name]
--> 166         raise RuntimeError(f"Requested MovieWriter ({name}) not available")
167 
168 
RuntimeError: Requested MovieWriter (ffmpeg) not available

运行!pip install ffmpeg没有帮助,因为ffmpeg已经安装,显然:

Requirement already satisfied: ffmpeg in /home/username/.local/lib/python3.8/site-packages

我怎样才能使它工作?

我设法解决了这个问题,但它花了我相当多的时间来找到正确的解决方案,所以我将分享它,以防它帮助别人。基本上,您需要下载FFmpeg的最新静态构建并将其添加到PATH,以便python可以找到它。您可以通过运行以下脚本轻松地做到这一点:

# Download a static FFmpeg build and add it to PATH.
exist = !which ffmpeg
if not exist:
!curl https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz -o ffmpeg.tar.xz 
&& tar -xf ffmpeg.tar.xz && rm ffmpeg.tar.xz
ffmdir = !find . -iname ffmpeg-*-static
path = %env PATH
path = path + ':' + ffmdir[0]
%env PATH $path
print('')
!which ffmpeg
print('Done!')

希望有帮助!

最新更新