Update app.py
Browse files
app.py
CHANGED
|
@@ -5,47 +5,60 @@ import os
|
|
| 5 |
import time
|
| 6 |
|
| 7 |
def process_video(url):
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Download highest quality (no re-encode)
|
| 14 |
subprocess.run([
|
| 15 |
"ffmpeg", "-y", "-i", url,
|
| 16 |
-
"-c", "copy", "-bsf:a", "aac_adtstoasc",
|
| 17 |
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
output_file = "watermarked_smallest.mp4"
|
| 23 |
filter_graph = "drawtext=text='nt-animes':x=8:y=8:fontcolor=white:fontsize=12"
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"ffmpeg", "-y", "-i", input_file,
|
| 27 |
"-vf", filter_graph,
|
| 28 |
-
"-c:v", "
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
"""
|
|
|
|
|
|
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
-
gr.Markdown("#
|
| 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="
|
| 48 |
-
info = gr.Textbox(label="Stats")
|
| 49 |
|
| 50 |
btn.click(process_video, url_in, [video_out, info])
|
| 51 |
|
|
|
|
| 5 |
import time
|
| 6 |
|
| 7 |
def process_video(url):
|
| 8 |
+
start_total = time.time()
|
| 9 |
|
| 10 |
+
# Step 1: Download full episode
|
| 11 |
+
full_file = "full_episode.mp4"
|
| 12 |
+
t_download_start = time.time()
|
|
|
|
| 13 |
subprocess.run([
|
| 14 |
"ffmpeg", "-y", "-i", url,
|
| 15 |
+
"-c", "copy", "-bsf:a", "aac_adtstoasc", full_file
|
| 16 |
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 17 |
+
t_download = time.time() - t_download_start
|
| 18 |
+
size_full = os.path.getsize(full_file) / (1024**2)
|
| 19 |
|
| 20 |
+
# Step 2: Watermark full episode
|
| 21 |
+
watermarked_full = "watermarked_full.mp4"
|
| 22 |
+
t_wm_start = time.time()
|
|
|
|
| 23 |
filter_graph = "drawtext=text='nt-animes':x=8:y=8:fontcolor=white:fontsize=12"
|
| 24 |
+
subprocess.run([
|
| 25 |
+
"ffmpeg", "-y", "-i", full_file,
|
|
|
|
| 26 |
"-vf", filter_graph,
|
| 27 |
+
"-c:v", "libx264", "-preset", "fast", "-crf", "23",
|
| 28 |
+
"-c:a", "copy", watermarked_full
|
| 29 |
+
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 30 |
+
t_wm = time.time() - t_wm_start
|
| 31 |
+
size_wm = os.path.getsize(watermarked_full) / (1024**2)
|
| 32 |
|
| 33 |
+
# Step 3: Trim 1s from 12:00 for quality test
|
| 34 |
+
test_clip = "test_clip_12min.mp4"
|
| 35 |
+
subprocess.run([
|
| 36 |
+
"ffmpeg", "-y", "-i", watermarked_full,
|
| 37 |
+
"-ss", "00:12:00", "-t", "00:00:01",
|
| 38 |
+
"-c", "copy", test_clip
|
| 39 |
+
], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 40 |
|
| 41 |
+
# Cleanup full files
|
| 42 |
+
os.remove(full_file)
|
| 43 |
+
os.remove(watermarked_full)
|
| 44 |
|
| 45 |
+
total_time = time.time() - start_total
|
| 46 |
+
|
| 47 |
+
stats = f"""
|
| 48 |
+
Total time: {total_time:.1f}s
|
| 49 |
+
Download: {t_download:.1f}s → {size_full:.1f} MB
|
| 50 |
+
Watermark full: {t_wm:.1f}s → {size_wm:.1f} MB
|
| 51 |
+
Test clip: 1s from 12:00 (for quality/watermark check)
|
| 52 |
"""
|
| 53 |
+
|
| 54 |
+
return test_clip, stats
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
| 57 |
+
gr.Markdown("# Full Download + Watermark + 12min Test Clip")
|
| 58 |
url_in = gr.Textbox(value="https://hlsx3cdn.echovideo.to/naruto/1/master.m3u8", label="m3u8 URL")
|
| 59 |
btn = gr.Button("Process")
|
| 60 |
+
video_out = gr.Video(label="1s Test Clip (12:00)")
|
| 61 |
+
info = gr.Textbox(label="Time & Size Stats")
|
| 62 |
|
| 63 |
btn.click(process_video, url_in, [video_out, info])
|
| 64 |
|