from ipywebrtc import VideoStream
You can create a video stream from a local file, note that the content of the file is embedded in the widget, meaning your notebook file can become quite large.
# commented out since it increases the size of the notebook a lot # video = VideoStream.from_file('./Big.Buck.Bunny.mp4') # video
# video2 = VideoStream.from_url('http://localhost:8888/path_to_your_hosted_file.mp4') video2 = VideoStream.from_url('./Big.Buck.Bunny.mp4') video2
In this example, video2 does not include the data of the video itself, only the url.
For convenience, if a video is not same-origin, the below code will download it and put the content of the file in the widget (note again that the notebook will be large).
# commented out since it increases the size of the notebook a lot # video3 = VideoStream.from_download('https://webrtc.github.io/samples/src/video/chrome.webm') # video3
You can control a video for intance by linking a ToggleButton to a VideoStream:
import ipywidgets as widgets play_button = widgets.ToggleButton(description="Play") widgets.jslink((play_button, 'value'), (video2, 'playing')) widgets.VBox(children=[video2, play_button])