Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- app.py +38 -0
- packages.txt +1 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def compress_video(video_path, crf=28, max_width=1280):
|
| 8 |
+
if video_path is None:
|
| 9 |
+
return None
|
| 10 |
+
|
| 11 |
+
out_path = os.path.join(tempfile.gettempdir(), "compressed_" + os.path.basename(video_path))
|
| 12 |
+
|
| 13 |
+
cmd = [
|
| 14 |
+
"ffmpeg", "-y", "-i", video_path,
|
| 15 |
+
"-vf", f"scale='min({max_width},iw)':-2",
|
| 16 |
+
"-c:v", "libx264", "-crf", str(crf), "-preset", "slower",
|
| 17 |
+
"-c:a", "aac", "-b:a", "128k",
|
| 18 |
+
"-movflags", "+faststart",
|
| 19 |
+
out_path,
|
| 20 |
+
]
|
| 21 |
+
subprocess.run(cmd, check=True, capture_output=True)
|
| 22 |
+
return out_path
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=compress_video,
|
| 27 |
+
inputs=[
|
| 28 |
+
gr.Video(label="Input video"),
|
| 29 |
+
gr.Slider(18, 35, value=28, step=1, label="CRF (higher = smaller file, lower quality)"),
|
| 30 |
+
gr.Slider(480, 1920, value=1280, step=10, label="Max width (px)"),
|
| 31 |
+
],
|
| 32 |
+
outputs=gr.Video(label="Compressed video"),
|
| 33 |
+
title="Video Compressor (ffmpeg)",
|
| 34 |
+
description="Server-side H.264 re-encode to shrink file size. Runs entirely on the HF Space, no local processing.",
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio==5.9.1
|