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:
|
subtitles (str, bytes, Path, io.BytesIO, or dict) | Optional subtitle data for the video, supporting several input types:
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:
|
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.
Still have questions?
Our forums are full of helpful information and Streamlit experts.