Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wernight opened this issue Apr 26, 2016 · 14 comments
Closed

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

wernight opened this issue Apr 26, 2016 · 14 comments

Comments

@wernight
Copy link

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.

@wernight
Copy link
Author

Ha! I see, can set rcParams['animation.writer'] = 'avconv'. It's set by default to ffmpeg in my case, not sure why. It could be that Jupyter should actually have smarter defaults.

@wernight wernight changed the title animation.to_html5_video() with avconv [minor issue] animation.to_html5_video() with avconv Apr 26, 2016
@WeatherGod
Copy link
Member

You can also set the parameter in your matplotlibrc file as well to be more permanent.

@QuLogic
Copy link
Member

QuLogic commented Apr 26, 2016

I could have sworn Debian switched back to ffmpeg since avconv is less developed/secure.

@dopplershift
Copy link
Contributor

To be clear anim.save() and anim.to_html5_video() are two completely different things. The former is for manually saving the animation to whatever format you want; the latter is for notebook inline views, and is called automatically if the animation.html rcparameter is set to 'html5'.

The reason the html5 video is locked to ffmpeg is because that's the only one for which I was able to reliably find the magic incantation to create h264 video that plays in multiple browers on multiple platforms. Incantations for other tools welcome, but making them robust wasn't simple, at least as simple as I expected.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone May 1, 2016
@Thatfreesky
Copy link

How to do

rcParams['animation.writer'] = 'avconv'

I can not solve this problem:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-5114ccf53b4c> in <module>()
----> 1 HTML(anim.to_html5_video())

/home/mountain/anaconda3/envs/biomedickeras/lib/python2.7/site-packages/matplotlib/animation.pyc in to_html5_video(self)
   1153                 # We create a writer manually so that we can get the
   1154                 # appropriate size for the tag
-> 1155                 Writer = writers[rcParams['animation.writer']]
   1156                 writer = Writer(codec='h264',
   1157                                 bitrate=rcParams['animation.bitrate'],

/home/mountain/anaconda3/envs/biomedickeras/lib/python2.7/site-packages/matplotlib/animation.pyc in __getitem__(self, name)
    128         if not self.avail:
    129             raise RuntimeError("No MovieWriters available!")
--> 130         return self.avail[name]
    131 
    132 writers = MovieWriterRegistry()

KeyError: u'ffmpeg'

@wernight
Copy link
Author

wernight commented Jul 13, 2017

import matplotlib
print(matplotlib.animation.writers.list())

This show what's available.

There are two issues here:

  1. I've avconv on my system but it's not detected: animation.py line 426 and overwritten line 616. The issue seems to be that 'Libav' is in the output ('Libav' in err.decode()). This seems to be a bug.
  2. It should do like if name not in self.avail: raise RuntimeError("Current animation.writer ({}) is not one of available writers detected ({}).".format(name, self.avail))

@tacaswell
Copy link
Member

@wernight I believe that #8743 is a fix for your issue.

@wernight
Copy link
Author

@tacaswell Probably a fix for (1). I'd suggest also fixing (2).

@dopplershift
Copy link
Contributor

@wernight I'd merge a PR doing so--would you submit?

@wernight
Copy link
Author

It would take me a lot of time to test it. I almost wrote the change here in my comment.

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@jonathan-alvaro
Copy link

Is this issue still open? If yes, I would like to try tackling it.

@jklymak
Copy link
Member

jklymak commented Sep 28, 2019

Seems like it’s still an issue but I’ve not tested. Test it first and if it’s an issue go ahead and follow up with a PR!

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Mar 25, 2023
@ksunden
Copy link
Member

ksunden commented Mar 25, 2023

Libav/avconv is now completely abandoned, so no reason to support it here

@ksunden ksunden closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2023
@QuLogic QuLogic removed this from the future releases milestone Mar 25, 2023
@QuLogic QuLogic removed the status: inactive Marked by the “Stale” Github Action label Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants