Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,52 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
import tempfile
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
r = requests.post(LITTERBOX_API, data=data, files=files, timeout=300)
|
| 17 |
-
r.raise_for_status()
|
| 18 |
-
url = r.text.strip()
|
| 19 |
-
return f"Success!\nRaw MP4 link: {url}"
|
| 20 |
-
except Exception as e:
|
| 21 |
-
return f"Failed: {str(e)}"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
fn=upload_litterbox,
|
| 25 |
-
inputs=gr.File(label="Upload Video"),
|
| 26 |
-
outputs=gr.Textbox(label="Result"),
|
| 27 |
-
title="Litterbox Upload Test",
|
| 28 |
-
description="Upload MP4 → get raw link (up to 1GB, 72h expiry)"
|
| 29 |
-
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
+
def process_video(url):
|
| 8 |
+
start = time.time()
|
| 9 |
+
|
| 10 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
| 11 |
+
input_file = tmp.name
|
| 12 |
+
|
| 13 |
+
# Download highest quality (no re-encode)
|
| 14 |
+
subprocess.run([
|
| 15 |
+
"ffmpeg", "-y", "-i", url,
|
| 16 |
+
"-c", "copy", "-bsf:a", "aac_adtstoasc", input_file
|
| 17 |
+
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 18 |
+
|
| 19 |
+
input_size = os.path.getsize(input_file) / (1024**2)
|
| 20 |
+
|
| 21 |
+
# Watermark ONLY (copy video stream, no re-encode)
|
| 22 |
+
output_file = "watermarked_smallest.mp4"
|
| 23 |
+
filter_graph = "drawtext=text='nt-animes':x=8:y=8:fontcolor=white:fontsize=12"
|
| 24 |
+
|
| 25 |
+
cmd = [
|
| 26 |
+
"ffmpeg", "-y", "-i", input_file,
|
| 27 |
+
"-vf", filter_graph,
|
| 28 |
+
"-c:v", "copy", "-c:a", "copy", output_file
|
| 29 |
+
]
|
| 30 |
+
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 31 |
+
|
| 32 |
+
os.remove(input_file)
|
| 33 |
+
|
| 34 |
+
output_size = os.path.getsize(output_file) / (1024**2)
|
| 35 |
+
total_time = time.time() - start
|
| 36 |
+
|
| 37 |
+
return output_file, f"""
|
| 38 |
+
Time: {total_time:.1f}s
|
| 39 |
+
Input: {input_size:.1f} MB
|
| 40 |
+
Output: {output_size:.1f} MB (smallest possible, no quality loss)
|
| 41 |
+
"""
|
| 42 |
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("# Smallest Size + Zero Quality Loss")
|
| 45 |
+
url_in = gr.Textbox(value="https://hlsx3cdn.echovideo.to/naruto/1/master.m3u8", label="m3u8 URL")
|
| 46 |
+
btn = gr.Button("Process")
|
| 47 |
+
video_out = gr.Video(label="Watermarked Video")
|
| 48 |
+
info = gr.Textbox(label="Stats")
|
| 49 |
+
|
| 50 |
+
btn.click(process_video, url_in, [video_out, info])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|