Skip to content

Instantly share code, notes, and snippets.

@cleemesser
Created September 18, 2020 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleemesser/b88548ad05ab35d67b821c15f7cb77e1 to your computer and use it in GitHub Desktop.
Save cleemesser/b88548ad05ab35d67b821c15f7cb77e1 to your computer and use it in GitHub Desktop.
show local mp4 video in panel (pyviz)
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.6.0
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# %%
import panel as pn
pn.extension()
# %% [markdown]
# The ``Video`` Pane displays a video player given a local or remote video file. The widget also allows access and control over the player state including toggling of playing/``paused`` and ``loop`` state, the current ``time``, and the ``volume``. Depending on the browser the video player supports ``mp4``, ``webm``, and ``ogg`` containers and a variety of codecs.
#
# #### Parameters:
#
# For layout and styling related parameters see the [customization user guide](../../user_guide/Customization.ipynb).
#
# * **``name``** (str): The title of the widget
# * **``loop``** (boolean): Whether to loop when reaching the end of playback
# * **``object``** (string): Local file path or remote URL pointing to audio file
# * **``paused``** (boolean): Whether the player is paused
# * **``throttle``** (int): How frequently to sample the current playback time in milliseconds
# * **``time``** (float): Current playback time in seconds
# * **``volume``** (int): Volume in the range 0-100
#
# ___
# %%
# pn.pane.Video?
# %% [markdown]
# The `Video` Pane can be constructed with a URL pointing to a remote video file or a local video file (in which case the data is embedded).
# %%
mp4filename = 'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4' # given as a url
mp4filename = 'animal.mp4' # local file is just given as a string with a file path to the mp4 filename
# note that is in the same directory as this file
video = pn.pane.Video( mp4filename, width=640, height=480, loop=True)
video
# %% [markdown]
# The player can be controlled using its own widgets, as well as by using Python code as follows. To pause or unpause it in code, use the ``paused`` property:
# %%
#video.paused = True
video.paused = False
# %% [markdown]
# The current player ``time`` can be read and set with the time variable (in seconds):
# %%
video.time
# %% [markdown]
# The ``volume`` may also be read and set:
# %%
video.volume = 100
# %% [markdown]
# ### Controls
#
# The `Video` pane 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.controls(jslink=True), video)
# %%
video.get_param_values()
# %%
pwd
# %%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment