Spaces:
Runtime error
Runtime error
Jeril commited on
Commit ·
d67b1c9
1
Parent(s): 45e1185
first commit
Browse files- app.py +49 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import ffmpeg
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def cut_video(video, start_time, end_time):
|
| 6 |
+
if not video:
|
| 7 |
+
raise gr.Error("No video file selected")
|
| 8 |
+
|
| 9 |
+
if start_time < 0:
|
| 10 |
+
raise gr.Error("Start time cannot be negative")
|
| 11 |
+
|
| 12 |
+
if end_time <= start_time:
|
| 13 |
+
raise gr.Error("End time must be greater than start time")
|
| 14 |
+
|
| 15 |
+
input_file = video
|
| 16 |
+
output_file = "media/cut_video.mp4"
|
| 17 |
+
|
| 18 |
+
os.makedirs(os.path.dirname(output_file), exist_ok=True)
|
| 19 |
+
|
| 20 |
+
if os.path.exists(output_file):
|
| 21 |
+
os.remove(output_file)
|
| 22 |
+
|
| 23 |
+
ffmpeg.input(input_file, ss=start_time, to=end_time).output(
|
| 24 |
+
output_file, format="mp4"
|
| 25 |
+
).run(overwrite_output=True)
|
| 26 |
+
|
| 27 |
+
return output_file
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("<center><h1> Video Cutter </h1></center><br>")
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
video_input = gr.Video(label="Upload Video")
|
| 35 |
+
video_output = gr.Video(label="Cut Video")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
start_time_input = gr.Number(label="Start Time (seconds)", value=0, precision=0)
|
| 39 |
+
end_time_input = gr.Number(label="End Time (seconds)", value=10, precision=0)
|
| 40 |
+
|
| 41 |
+
cut_button = gr.Button("Cut Video", variant="primary")
|
| 42 |
+
|
| 43 |
+
cut_button.click(
|
| 44 |
+
fn=cut_video,
|
| 45 |
+
inputs=[video_input, start_time_input, end_time_input],
|
| 46 |
+
outputs=video_output,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg-python
|