Search code examples
html5-videoipythonjupyter-notebook

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


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?


Solution

  • (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). In previous IPython versions, you may need to call the from_file method: Video.from_file("test.mp4").

    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>
    """)