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?
To display local video files in the Jupyter notebook, we should use an Html video tag ( <video... ), and set the base64 encoded video file content to the src attribute of the Html video tag ( <video ..... src='data:video/x-m4v;base64,...... ' ). So we should use IPython.
Launch a Notebook To launch a Jupyter notebook, open your terminal and navigate to the directory where you would like to save your notebook. Then type the command jupyter notebook and the program will instantiate a local server at localhost:8888 (or another specified port).
(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> """)
Play it as an HTML5 video :]
from IPython.display import HTML
HTML(""" <video width="320" height="240" controls> <source src="path/to/your.mp4" type="video/mp4"> </video> """)
UPDATE
Additionally, use a magic cell:
%%HTML <video width="320" height="240" controls> <source src="path/to/your.mp4" type="video/mp4"> </video>
and the same applies for audio too
%%HTML <audio controls> <source src="AUDIO-FILE.mp3"> </audio>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With