Skip to content

[minor issue] animation.to_html5_video() with avconv #6338

Closed as not planned
Closed as not planned
@wernight

Description

@wernight

Matplotliv 1.5.1 on Linux (Debian) animation's method to_html5_video() seems not to support AVconv:

Example:

%matplotlib inline
from pylab import *
import matplotlib.animation
import matplotlib.patches

fig, ax = plt.subplots(figsize=(13, 8))
def update(frame):  
    ax.add_patch(matplotlib.patches.Rectangle(numpy.array([0, 0]), 1, 1))
anim = matplotlib.animation.FuncAnimation(fig, update, frames=10)
anim.save('anim.mp4', fps=20, writer='avconv', codec='libx264')

Gives exception:

/opt/conda/lib/python3.5/site-packages/matplotlib/animation.py in to_html5_video(self)
    949                 # We create a writer manually so that we can get the
    950                 # appropriate size for the tag
--> 951                 Writer = writers[rcParams['animation.writer']]
    952                 writer = Writer(codec='h264',
    953            

/opt/conda/lib/python3.5/site-packages/matplotlib/animation.py in __getitem__(self, name)
     87         if not self.avail:
     88             raise RuntimeError("No MovieWriters available!")
---> 89         return self.avail[name]
     90 
     91 writers = MovieWriterRegistry()

KeyError: 'ffmpeg'

I'm not sure what it does, but just having the video displayed in Jupyter is pretty simple:

from IPython.display import HTML
import base64
anim.save('temp.mp4', fps=20, writer='avconv', codec='libx264')
with open('temp.mp4', 'rb') as f:
    video_tag = '<video controls alt="test" src="data:video/x-m4v;base64,{0}">'.format(base64.b64encode(f.read()).decode('utf-8'))
HTML(video_tag)

I didn't find a simple way to ask to_html5_video() to use AVconv or set the writer, and FFmpeg is kind of deprecated on Debian (see package info stating "Be careful, FFmpeg is not available on Debian 8 Jessie"). Simplest seems to support AVconv by default or as fallback.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions