video
To upload files, please first save the app
import streamlit as st
st.title("Video Player Demo")
st.write("This app demonstrates Streamlit's video functionality with various options.")
# Sample video URLs for demonstration
video_options = {
"Big Buck Bunny (MP4)": "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4",
"YouTube Video": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"Local File Upload": None
}
st.subheader("Choose a video source:")
selected_option = st.selectbox("Video Source", list(video_options.keys()))
if selected_option == "Local File Upload":
uploaded_file = st.file_uploader("Upload a video file", type=['mp4', 'mov', 'avi', 'mkv'])
if uploaded_file is not None:
st.video(uploaded_file)
else:
video_url = video_options[selected_option]
# Video controls
st.subheader("Video Controls:")
col1, col2 = st.columns(2)
with col1:
autoplay = st.checkbox("Autoplay", value=False)
muted = st.checkbox("Muted", value=False)
loop = st.checkbox("Loop", value=False)
with col2:
start_time = st.number_input("Start time (seconds)", min_value=0, value=0)
end_time = st.number_input("End time (seconds)", min_value=0, value=0)
if end_time == 0:
end_time = None
st.subheader("Video Player:")
# Display video with controls
try:
st.video(
video_url,
start_time=start_time if start_time > 0 else None,
end_time=end_time,
loop=loop,
autoplay=autoplay,
muted=muted
)
except Exception as e:
st.error(f"Error loading video: {e}")
st.info("Note: Some video URLs may not work due to CORS restrictions or server policies.")
st.subheader("Supported Features:")
st.write("""
- **Autoplay**: Video starts playing automatically (requires muted=True for most browsers)
- **Muted**: Video plays without sound
- **Loop**: Video repeats when it reaches the end
- **Start/End Time**: Control playback range
- **Subtitles**: Add subtitle files (VTT or SRT format)
- **Multiple Formats**: Supports MP4, MOV, AVI, MKV and more
- **YouTube URLs**: Direct YouTube video support
""")
# Example with subtitles (if you have a subtitle file)
st.subheader("Video with Subtitles Example:")
st.code('''
st.video(
"your_video.mp4",
subtitles="subtitles.vtt" # or {"English": "en.vtt", "Spanish": "es.vtt"}
)
''')
st.info("💡 Tip: For local development, you can place video files in your app directory and reference them directly.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?