Display a video player.

Function signature[source]

st.video(data, format="video/mp4", start_time=0, *, subtitles=None)

Parameters

data (str, bytes, io.BytesIO, numpy.ndarray, or file)

Raw video data, filename, or URL pointing to a video to load. Includes support for YouTube URLs. Numpy arrays and raw data formats must include all necessary file headers to match specified file format.

format (str)

The mime type for the video file. Defaults to "video/mp4". See https://tools.ietf.org/html/rfc4281 for more info.

start_time (int)

The time from which this element should start playing.

subtitles (str, bytes, Path, io.BytesIO, or dict)

Optional subtitle data for the video, supporting several input types:

  • None (default): No subtitles.
  • A string, bytes, or Path: File path to a subtitle file in .vtt or .srt formats, or the raw content of subtitles conforming to these formats. If providing raw content, the string must adhere to the WebVTT or SRT format specifications.
  • io.BytesIO: A BytesIO stream that contains valid .vtt or .srt formatted subtitle data.
  • A dictionary: Pairs of labels and file paths or raw subtitle content in .vtt or .srt formats to enable multiple subtitle tracks. The label will be shown in the video player. Example: {"English": "path/to/english.vtt", "French": "path/to/french.srt"}

When provided, subtitles are displayed by default. For multiple tracks, the first one is displayed by default. If you don't want any subtitles displayed by default, use an empty string for the value in a dictrionary's first pair: {"None": "", "English": "path/to/english.vtt"}

Not supported for YouTube videos.

Example

import streamlit as st

video_file = open('myvideo.mp4', 'rb')
video_bytes = video_file.read()

st.video(video_bytes)

When you include subtitles, they will be turned on by default. A viewer can turn off the subtitles (or captions) from the browser's default video control menu, usually located in the lower-right corner of the video.

Here is a simple VTT file (subtitles.vtt):

WEBVTT

0:00:01.000 --> 0:00:02.000
Look!

0:00:03.000 --> 0:00:05.000
Look at the pretty stars!

If the above VTT file lives in the same directory as your app, you can add subtitles like so:

import streamlit as st

VIDEO_URL = "https://example.com/not-youtube.mp4"
st.video(VIDEO_URL, subtitles="subtitles.vtt")

See additional examples of supported subtitle input types in our video subtitles feature demo.

Note

Some videos may not display if they are encoded using MP4V (which is an export option in OpenCV), as this codec is not widely supported by browsers. Converting your video to H.264 will allow the video to be displayed in Streamlit. See this StackOverflow post or this Streamlit forum post for more information.

forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.