VideoPlayer widget in Supervisely is a media player that utilizes the HTML <video> tag and provides additional functionalities to control it through Python code such as seeking and controlling the current playback time in seconds. It uses the built-in browser player, which is supported by most devices.
In addition, Video Player has a feature for overlaying an image on top of the video without modifying the video itself.
Video url or local path to video on the host. Determines the video to be displayed on widget.
type:str
default value:None
mime_type
Determines video type.
type:str
default value:video/mp4
widget_id
ID of the widget.
type:str
default value:None
Methods and attributes
Attributes and Methods
Description
url
Get url property.
mime_type
Get mime_type property.
set_video(url: str, mime_type: str = "video/mp4")
Set video in VideoPlayer widget by url.
play()
Start video to play.
pause()
Stop video playback.
get_current_timestamp()
Return current video playing step.
set_current_timestamp(value: int)
Set current video playing step.
draw_mask(path: str)
Draw a mask image on top of the video without changing video.
hide_mask()
Hide the drawn mask from the video.
Mini App Example
You can find this example in our Github repository:
Import libraries
import os
from pathlib import Path
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Button, Card, Container, Checkbox
from supervisely.app.widgets import Flexbox, InputNumber, VideoPlayer
from supervisely._utils import abs_url
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
Prepare videos url and type
video_id = int(os.environ["modal.state.slyVideoId"]) # get video ID from environment
video_info = api.video.get_info_by_id(id=video_id) # get VideoInfo from server
video_url = abs_url(video_info.path_original)
video_mime_type = video_info.file_meta["mime"]
local_video_url = "/static/video-cam2.mp4" # local video url
local_video_type = "video/mp4" # local video url