How can I play a local video in my IPython notebook?

Chris picture Chris · Aug 2, 2013 · Viewed 49.9k times · Source

I've got a local video file (an .avi, but could be converted) that I would like to show a client (ie it is private and can't be published to the web), but I can't figure out how to play it in IPython notebook.

After a little Googling it seems that maybe the HTML5 video tag is the way to go, but I don't know any html and can't get it to play.

Any thoughts on how I can embed this?

Answer

Viktor Kerkez picture Viktor Kerkez · Aug 2, 2013

(updated 2019, removed unnecessarily costly method)

Just do:

from IPython.display import Video

Video("test.mp4")

If you get an error No video with supported format or MIME type found, just pass embed=True to the function: Video("test.mp4", embed=True).

Or if you want to use the HTML element:

from IPython.display import HTML

HTML("""
    <video alt="test" controls>
        <source src="test.mp4" type="video/mp4">
    </video>
""")