Display a video player.

Function signature[source]

st.video(data, format="video/mp4", start_time=0, *, subtitles=None, end_time=None, loop=False, autoplay=False, muted=False)

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, float, timedelta, str, or None)

The time from which the element should start playing. This can be one of the following:

  • None (default): The element plays from the beginning.
  • An int or float specifying the time in seconds. float values are rounded down to whole seconds.
  • A string specifying the time in a format supported by Pandas' Timedelta constructor, e.g. "2 minute", "20s", or "1m14s".
  • A timedelta object from Python's built-in datetime library, e.g. timedelta(seconds=70).

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.

end_time (int, float, timedelta, str, or None)

The time at which the element should stop playing. This can be one of the following:

  • None (default): The element plays through to the end.
  • An int or float specifying the time in seconds. float values are rounded down to whole seconds.
  • A string specifying the time in a format supported by Pandas' Timedelta constructor, e.g. "2 minute", "20s", or "1m14s".
  • A timedelta object from Python's built-in datetime library, e.g. timedelta(seconds=70).

loop (bool)

Whether the video should loop playback.

autoplay (bool)

Whether the video should start playing automatically. This is False by default. Browsers will not autoplay unmuted videos if the user has not interacted with the page by clicking somewhere. To enable autoplay without user interaction, you must also set muted=True.

muted (bool)

Whether the video should play with the audio silenced. This is False by default. Use this in conjunction with autoplay=True to enable autoplay without user interaction.

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.