Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Animation conversion to HTML5 video #4785

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

Merged
merged 5 commits into from
Jul 27, 2015

Conversation

dopplershift
Copy link
Contributor

This adds a method to render animations as an HTML5 video tag (h264 encoded video, base64-encoded directly into the tag.) It then adds the IPython display hook to allow it to automatically render in the notebook, though by default it is off. The use of the rcparam can be extended to also include JSAnimation.

This paves the way for displaying animations in IPython notebooks.
This is configurable using rc params, and defaults to off.
@dopplershift
Copy link
Contributor Author

I really wish I had gotten this in sooner for 1.5....

self._base64_video = vid64.decode('ascii')
self._video_size = 'width="{0}" height="{1}"'.format(
*writer.frame_size)
os.remove(f.name) # Now we can remove
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to remove an open file on all platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so--good catch. I don't think there's any reason to move that line out of the with.

@jenshnielsen
Copy link
Member

I like it and don't have any problem with it being merged late. It is a new completely optional feature and we can always mark it as experimental if need be. I do think that it needs an entry in whats new thou.

There are a few usability problems with the nbagg backend. The nbagg backend in interactive mode will show the notebook window with the animation along with the repr_html (if that is enabled) producing double output. But that may be more of an issue with the nbagg backend?

@dopplershift
Copy link
Contributor Author

Thanks, I'll address those comments shortly, as well as a few other tweaks.

Regarding nbagg, the original version I'm adapting called plt.close() to address the double display problem. Personally, I think I'd end up working around this behavior as often as I'd want it. I can't think of any less draconian way to eliminate the display of the figure.

It looks like you can work around this by putting the animation in a different cell than the figure creation.

@jenshnielsen
Copy link
Member

Great. It might be possible in the long term to be more cleaver about when nbagg displays a figure but that is out of the scope of this PR in any case. I ended up wrapping the animation with plt.ioff() and plt.ion() to prevent the nbagg backend in showing a figure automatically.

It might also be worth mentioning somewhere that you can do:

from IPython.display import HTML
HTML(ani. to_html5_video())

If you don't want to enable the repr_html

@tacaswell
Copy link
Member

I talked to @minrk about a related issue at Scipy, but I don't remember the exact outcome of that conversation.

@jenshnielsen
Copy link
Member

👍 Looks good to me

@tacaswell Do we want to do any kind of feature freeze or are we ok to merge this?

@jamespjh this may be of interest to you

@tacaswell
Copy link
Member

Merge it, i want to break feature freeze in a couple of other things that
are far more major changes

On Mon, Jul 27, 2015, 2:28 PM Jens Hedegaard Nielsen <
[email protected]> wrote:

[image: 👍] Looks good to me

@tacaswell https://github.com/tacaswell Do we want to do any kind of
feature freeze or are we ok to merge this?

@jamespjh https://github.com/jamespjh this may be of interest to you


Reply to this email directly or view it on GitHub
#4785 (comment)
.

jenshnielsen added a commit that referenced this pull request Jul 27, 2015
Animation conversion to HTML5 video
@jenshnielsen jenshnielsen merged commit 271a646 into matplotlib:master Jul 27, 2015
@dopplershift dopplershift deleted the anim-html5-video branch July 28, 2015 03:06
@dopplershift
Copy link
Contributor Author

cc @jclark754 @lesserwhirls

@QuLogic QuLogic added this to the v1.5.0 milestone Jun 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants