video-cutter / app.py
Jeril
some fixes
06c292f
raw
history blame
1.33 kB
import gradio as gr
import ffmpeg
import os
def cut_video(video, start_time, end_time):
if not video:
raise gr.Error("No video file selected")
if start_time < 0:
raise gr.Error("Start time cannot be negative")
if end_time <= start_time:
raise gr.Error("End time must be greater than start time")
input_file = video
output_file = "media/output.mp4"
os.makedirs(os.path.dirname(output_file), exist_ok=True)
if os.path.exists(output_file):
os.remove(output_file)
ffmpeg.input(input_file, ss=start_time, to=end_time).output(
output_file, format="mp4"
).run(overwrite_output=True)
return output_file
with gr.Blocks() as demo:
gr.Markdown("<center><h1> Video Cutter </h1></center><br>")
with gr.Row():
video_input = gr.Video(label="Upload Video")
video_output = gr.Video(label="Cut Video")
with gr.Row():
start_time_input = gr.Number(label="Start Time (seconds)", value=0, precision=0)
end_time_input = gr.Number(label="End Time (seconds)", value=10, precision=0)
cut_button = gr.Button("Cut Video", variant="primary")
cut_button.click(
fn=cut_video,
inputs=[video_input, start_time_input, end_time_input],
outputs=video_output,
)
demo.launch()