cut video
To upload files, please first save the app
import streamlit as st
from datetime import timedelta
st.title("Video Cutter")
st.write("Upload a video file and specify start/end times to cut it.")
# File uploader
uploaded_file = st.file_uploader(
"Choose a video file",
type=['mp4', 'mov', 'avi', 'mkv', 'webm']
)
if uploaded_file is not None:
# Display the original video
st.subheader("Original Video")
st.video(uploaded_file)
# Create columns for start and end time inputs
col1, col2 = st.columns(2)
with col1:
st.subheader("Start Time")
start_minutes = st.number_input("Minutes", min_value=0, value=0, key="start_min")
start_seconds = st.number_input("Seconds", min_value=0, max_value=59, value=0, key="start_sec")
with col2:
st.subheader("End Time")
end_minutes = st.number_input("Minutes", min_value=0, value=1, key="end_min")
end_seconds = st.number_input("Seconds", min_value=0, max_value=59, value=0, key="end_sec")
# Calculate total seconds
start_time_seconds = start_minutes * 60 + start_seconds
end_time_seconds = end_minutes * 60 + end_seconds
# Validation
if end_time_seconds <= start_time_seconds:
st.error("End time must be greater than start time!")
else:
# Display the cut video preview
st.subheader("Video Preview (Cut)")
st.write(f"Playing from {start_minutes}:{start_seconds:02d} to {end_minutes}:{end_seconds:02d}")
# Show video with start and end times
st.video(
uploaded_file,
start_time=start_time_seconds,
end_time=end_time_seconds
)
# Additional options
st.subheader("Playback Options")
col3, col4 = st.columns(2)
with col3:
loop_video = st.checkbox("Loop playback", value=False)
muted = st.checkbox("Muted", value=False)
with col4:
autoplay = st.checkbox("Autoplay", value=False)
# Show final video with all options
if st.button("Apply Settings"):
st.subheader("Final Video with Settings")
st.video(
uploaded_file,
start_time=start_time_seconds,
end_time=end_time_seconds,
loop=loop_video,
autoplay=autoplay,
muted=muted
)
st.success(f"Video cut applied! Duration: {end_time_seconds - start_time_seconds} seconds")
else:
st.info("Please upload a video file to get started.")
# Show example with a sample video URL
st.subheader("Example with Sample Video")
st.write("Here's an example of how the video cutter works:")
sample_url = "https://sample-videos.com/zip/10/mp4/SampleVideo_1280x720_1mb.mp4"
# Note: Using a sample video URL - in a real scenario, you'd want to use an actual video
st.write("Sample video (10 seconds, showing first 5 seconds):")
try:
st.video(sample_url, start_time=0, end_time=5)
except:
st.write("Sample video not available. Please upload your own video file above.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?