forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst_video.py
103 lines (84 loc) · 2.59 KB
/
st_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import time
from os.path import abspath, dirname, join
import requests
import streamlit as st
# Construct test assets path relative to this script file to
# allow its execution with different working directories.
TEST_ASSETS_DIR = join(dirname(abspath(__file__)), "test_assets")
WEBM_VIDEO_PATH = join(TEST_ASSETS_DIR, "sintel-short.webm")
MP4_VIDEO_PATH = join(TEST_ASSETS_DIR, "sintel-short.mp4")
VTT_EN_PATH = join(TEST_ASSETS_DIR, "sintel-en.vtt")
VTT_DE_PATH = join(TEST_ASSETS_DIR, "sintel-de.vtt")
url = "https://www.w3schools.com/html/mov_bbb.mp4"
file = requests.get(url).content
st.video(file)
# Test start time with video
timestamp = st.number_input("Start Time (in seconds)", min_value=0, value=6)
st.video(url, start_time=int(timestamp))
# Test local file with video
st.video(MP4_VIDEO_PATH, start_time=17)
# Test subtitle with video
st.video(
MP4_VIDEO_PATH,
start_time=31,
subtitles={
"English": VTT_EN_PATH,
"Deutsch": VTT_DE_PATH,
},
)
# Test subtitle with webm video
st.video(
WEBM_VIDEO_PATH,
start_time=25,
subtitles={
"English": VTT_EN_PATH,
"Deutsch": VTT_DE_PATH,
},
)
# Test end time webm video
st.video(
WEBM_VIDEO_PATH,
start_time=31,
end_time=33,
)
# Test end time mp4 video
st.video(
MP4_VIDEO_PATH,
start_time=31,
end_time=33,
)
# Test end time and loop webm video
st.video(WEBM_VIDEO_PATH, start_time=35, end_time=39, loop=True)
# Test end time and loop mp4 video
st.video(MP4_VIDEO_PATH, start_time=35, end_time=39, loop=True)
# Test autoplay with video
autoplay = st.checkbox("Autoplay", value=False)
if st.button("Create some elements to unmount component"):
for _ in range(3):
# The sleep here is needed, because it won't unmount the
# component if this is too fast.
time.sleep(1)
st.write("Another element")
st.video(
WEBM_VIDEO_PATH,
autoplay=autoplay,
)
# Test muted with video
st.video(
WEBM_VIDEO_PATH,
autoplay=True,
muted=True,
)