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', 'avi', 'mov', 'mkv', 'webm'])
if uploaded_file is not None:
# Display original video
st.subheader("Original Video")
st.video(uploaded_file)
# Time input controls
st.subheader("Cut Settings")
col1, col2 = st.columns(2)
with col1:
st.write("**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")
start_time = start_minutes * 60 + start_seconds
with col2:
st.write("**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")
end_time = end_minutes * 60 + end_seconds
# Validation
if end_time <= start_time:
st.error("End time must be greater than start time")
else:
# Display cut video preview
st.subheader("Cut Video Preview")
st.write(f"Showing video from {start_minutes}:{start_seconds:02d} to {end_minutes}:{end_seconds:02d}")
try:
st.video(
uploaded_file,
start_time=start_time,
end_time=end_time
)
except Exception as e:
st.error(f"Error playing video segment: {str(e)}")
# Additional options
st.subheader("Additional Options")
loop_video = st.checkbox("Loop video", value=False)
mute_audio = st.checkbox("Mute audio", value=False)
autoplay = st.checkbox("Autoplay", value=False)
if st.button("Apply Settings"):
st.subheader("Final Cut Video")
st.video(
uploaded_file,
start_time=start_time,
end_time=end_time,
loop=loop_video,
muted=mute_audio,
autoplay=autoplay
)
st.success(f"Video cut applied! Showing segment from {start_time}s to {end_time}s")
# Show cut information
duration = end_time - start_time
st.info(f"Cut duration: {duration} seconds ({duration//60}:{duration%60:02d})")
else:
st.info("Please upload a video file to get started")
# Show example
st.subheader("Example")
st.write("Here's an example with a sample video URL:")
sample_url = st.text_input("Enter video URL (optional)", placeholder="https://example.com/sample.mp4")
if sample_url:
try:
st.video(sample_url, start_time=10, end_time=30)
st.write("This shows the video from 10 seconds to 30 seconds")
except Exception as e:
st.error(f"Error loading video from URL: {str(e)}")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?