rbughao commited on
Commit
e720154
·
verified ·
1 Parent(s): 39ba5e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import subprocess
4
+ import uuid
5
+
6
+ # Function to compress video using ffmpeg
7
+ def compress_video(video):
8
+ input_path = f"input_{uuid.uuid4()}.mp4"
9
+ output_path = f"compressed_{uuid.uuid4()}.mp4"
10
+
11
+ # Save uploaded video
12
+ with open(input_path, "wb") as f:
13
+ f.write(video.read())
14
+
15
+ # FFmpeg command for compression
16
+ command = [
17
+ "ffmpeg", "-i", input_path,
18
+ "-vcodec", "libx264", "-crf", "28", # CRF controls quality (lower = better quality)
19
+ "-preset", "fast",
20
+ output_path
21
+ ]
22
+ subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23
+
24
+ os.remove(input_path) # Clean up original file
25
+ return output_path
26
+
27
+ # Gradio UI
28
+ with gr.Blocks() as demo:
29
+ gr.Markdown("# 🎥 MP4 Video Compressor")
30
+ gr.Markdown("Upload an MP4 video, compress it, and download the result.")
31
+
32
+ with gr.Row():
33
+ with gr.Column():
34
+ video_input = gr.File(label="Upload MP4 Video", file_types=[".mp4"])
35
+ compress_button = gr.Button("Compress Video")
36
+ with gr.Column():
37
+ output_video = gr.File(label="Download Compressed Video")
38
+
39
+ compress_button.click(fn=compress_video, inputs=video_input, outputs=output_video)
40
+
41
+ demo.launch()
42
+ ``