import gradio as gr import subprocess import tempfile import os import time def process_video(url): start_total = time.time() # Step 1: Download full episode full_file = "full_episode.mp4" t_download_start = time.time() subprocess.run([ "ffmpeg", "-y", "-i", url, "-c", "copy", "-bsf:a", "aac_adtstoasc", full_file ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) t_download = time.time() - t_download_start size_full = os.path.getsize(full_file) / (1024**2) # Step 2: Watermark full episode watermarked_full = "watermarked_full.mp4" t_wm_start = time.time() filter_graph = "drawtext=text='nt-animes':x=8:y=8:fontcolor=white:fontsize=12" subprocess.run([ "ffmpeg", "-y", "-i", full_file, "-vf", filter_graph, "-c:v", "libx264", "-preset", "ultrafast", "-crf", "23", "-c:a", "copy", watermarked_full ], check=True) t_wm = time.time() - t_wm_start size_wm = os.path.getsize(watermarked_full) / (1024**2) # Step 3: Trim 1s from 12:00 for quality test test_clip = "test_clip_12min.mp4" subprocess.run([ "ffmpeg", "-y", "-i", watermarked_full, "-ss", "00:12:00", "-t", "00:00:01", "-c", "copy", test_clip ], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # Cleanup full files os.remove(full_file) os.remove(watermarked_full) total_time = time.time() - start_total stats = f""" Total time: {total_time:.1f}s Download: {t_download:.1f}s → {size_full:.1f} MB Watermark full: {t_wm:.1f}s → {size_wm:.1f} MB Test clip: 1s from 12:00 (for quality/watermark check) """ return test_clip, stats with gr.Blocks() as demo: gr.Markdown("# Full Download + Watermark + 12min Test Clip") url_in = gr.Textbox(value="https://hlsx3cdn.echovideo.to/naruto/1/master.m3u8", label="m3u8 URL") btn = gr.Button("Process") video_out = gr.Video(label="1s Test Clip (12:00)") info = gr.Textbox(label="Time & Size Stats") btn.click(process_video, url_in, [video_out, info]) demo.launch()