VideoStream#
Download this notebook from GitHub (right-click to download).
import panel as pn
pn.extension()
The VideoStream
widget displays a video from a local stream (for example from a webcam) and allows accessing the streamed video data from Python.
For more information about listening to widget events and laying out widgets refer to the widgets user guide. Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the param user guide. To express interactivity entirely using Javascript without the need for a Python server take a look at the links user guide.
Parameters:#
For layout and styling related parameters see the customization user guide.
format
(str): Format of the captured images, either ‘png’ or ‘jpeg’paused
(boolean): Whether the video stream is pausedtimeout
(int): Interval between snapshots (if None then snapshot only taken if snapshot method is called)value
(string): String representation of the current snapshot
The VideoStream
widget by default simply displays the video stream:
video_stream = pn.widgets.VideoStream(name='Video Stream')
video_stream
To sync the state of the stream with Python we have two options. First, we can call the snapshot
method, which will trigger the value
of the widget to be updated:
video_stream.snapshot()
html = pn.pane.HTML(width=320, height=240)
def update(event):
html.object = '<img src="'+event.new+'" width=320 height=240 />'
video_stream.param.watch(update, 'value')
html
Alternatively, we can create a video stream with a timeout
that specifies how frequently the video stream will be updated:
video = pn.widgets.VideoStream(timeout=100)
html = pn.pane.HTML()
pause = pn.widgets.Toggle(name='Pause')
pause.jslink(video, value='paused')
video.jslink(html, code={'value': """
target.text = `<img src="${source.value}" width=320 height=240 />`
"""})
pn.Column(pause, pn.Row(video, html))
Lastly, the video stream can also be paused from Python:
video.paused = True
Controls#
The VideoStream
widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:
pn.Row(video_stream.controls(jslink=True), video_stream)
Download this notebook from GitHub (right-click to download).