import subprocess
import json
from pathlib import Path

def probe(p):
    cmd = ["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", str(p)]
    res = subprocess.run(cmd, capture_output=True, text=True)
    return json.loads(res.stdout) if res.stdout else {}

p_new = Path("gradio_version/outputs/ep01_scene01_shot01_ltx.mp4")
p_old = Path("04_Assets/videos/ep02_scene01_shot01_10s.mp4")

d_new = probe(p_new)
d_old = probe(p_old)

print("=== NEW (HF ZeroGPU LTX-Video) ===")
print("File:", p_new.name, f"({p_new.stat().st_size / (1024*1024):.2f} MB)")
fmt_new = d_new.get("format", {})
print("Duration:", fmt_new.get("duration"), "seconds")
print("Bitrate:", fmt_new.get("bit_rate"))
for st in d_new.get("streams", []):
    ctype = st.get("codec_type")
    cname = st.get("codec_name")
    if ctype == "video":
        print(f"Video: {cname} | {st.get('width')}x{st.get('height')} @ {st.get('r_frame_rate')} fps")
    elif ctype == "audio":
        print(f"Audio: {cname} | {st.get('sample_rate')} Hz, {st.get('channels')} channels")

print("\n=== OLD (Muse.ai Web Automation) ===")
print("File:", p_old.name, f"({p_old.stat().st_size / (1024*1024):.2f} MB)")
fmt_old = d_old.get("format", {})
print("Duration:", fmt_old.get("duration"), "seconds")
print("Bitrate:", fmt_old.get("bit_rate"))
for st in d_old.get("streams", []):
    ctype = st.get("codec_type")
    cname = st.get("codec_name")
    if ctype == "video":
        print(f"Video: {cname} | {st.get('width')}x{st.get('height')} @ {st.get('r_frame_rate')} fps")
    elif ctype == "audio":
        print(f"Audio: {cname} | {st.get('sample_rate')} Hz, {st.get('channels')} channels")
