| import json |
| import os |
| import shutil |
| import subprocess |
|
|
| import gradio as gr |
|
|
|
|
| def probe_video(video_path): |
| if not video_path: |
| return "Please upload a video.", None |
|
|
| if shutil.which("ffprobe") is None: |
| return ( |
| "ffprobe not found. Add `ffmpeg` to packages.txt at the repo root.", |
| None, |
| ) |
|
|
| try: |
| result = subprocess.run( |
| [ |
| "ffprobe", |
| "-v", "quiet", |
| "-print_format", "json", |
| "-show_format", |
| "-show_streams", |
| video_path, |
| ], |
| capture_output=True, |
| text=True, |
| check=True, |
| ) |
| except subprocess.CalledProcessError as e: |
| return f"ffprobe failed:\n{e.stderr}", None |
|
|
| info = json.loads(result.stdout) |
| fmt = info.get("format", {}) or {} |
| streams = info.get("streams", []) or [] |
| v = next((s for s in streams if s.get("codec_type") == "video"), {}) |
| a = next((s for s in streams if s.get("codec_type") == "audio"), {}) |
|
|
| summary = { |
| "filename": os.path.basename(fmt.get("filename", "")), |
| "format": fmt.get("format_long_name") or fmt.get("format_name"), |
| "duration_sec": fmt.get("duration"), |
| "size_bytes": fmt.get("size"), |
| "overall_bitrate_bps": fmt.get("bit_rate"), |
| "video": { |
| "codec": v.get("codec_name"), |
| "profile": v.get("profile"), |
| "width": v.get("width"), |
| "height": v.get("height"), |
| "pix_fmt": v.get("pix_fmt"), |
| "frame_rate": v.get("r_frame_rate"), |
| "bitrate_bps": v.get("bit_rate"), |
| }, |
| "audio": { |
| "codec": a.get("codec_name"), |
| "sample_rate": a.get("sample_rate"), |
| "channels": a.get("channels"), |
| "bitrate_bps": a.get("bit_rate"), |
| }, |
| } |
| return json.dumps(summary, indent=2, ensure_ascii=False), video_path |
|
|
|
|
| with gr.Blocks(title="OneVision Encoder Codec View") as demo: |
| gr.Markdown( |
| "# OneVision Encoder Codec View\n" |
| "Upload a video to inspect its container / codec metadata via `ffprobe`." |
| ) |
| with gr.Row(): |
| with gr.Column(): |
| video_in = gr.Video(label="Input video", sources=["upload"]) |
| run_btn = gr.Button("Probe", variant="primary") |
| with gr.Column(): |
| video_out = gr.Video(label="Preview") |
| info_out = gr.Code(label="Metadata (JSON)", language="json") |
| run_btn.click(probe_video, inputs=video_in, outputs=[info_out, video_out]) |
|
|
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|