Spaces:
Paused
Paused
Upload app.py
Browse files193 unmodified lines19419519619719819920020112 unmodified lines214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249193 unmodified linesyield None, "β Nenhum vΓdeo enviado!"return# gr.File pode retornar objeto com .name em algumas versΓ΅es do Gradioif hasattr(video_file, "name"):video_file = video_file.nameext = os.path.splitext(video_file)[1].lower() or ".mp4"12 unmodified linesprobe_extra = ["-analyzeduration", "100M", "-probesize", "100M"] if precisa_probe_extra else []fmt_extra = ["-f", "mpeg"] if ext == ".vob" else []# ββ Detecta dimensΓ£o / orientaΓ§Γ£o βββββββββββββββββββββββββββprobe = subprocess.run(["ffprobe", "-v", "error"] + probe_extra + fmt_extra + ["-select_streams", "v:0","-show_entries", "stream=width,height","-of", "json", input_path], capture_output=True, text=True)probe_data = json.loads(probe.stdout)stream = probe_data.get("streams", [{}])[0]vid_w = int(stream.get("width", 1920))vid_h = int(stream.get("height", 1080))is_vertical = vid_h > vid_w# ββ DuraΓ§Γ£o βββββββββββββββββββββββββββββββββββββββββββββββββprobe_dur = subprocess.run(["ffprobe", "-v", "error"] + probe_extra + fmt_extra + ["-show_entries", "format=duration","-of", "json", input_path], capture_output=True, text=True)dur_data = json.loads(probe_dur.stdout)total_duration = float(dur_data.get("format", {}).get("duration", 0))# ββ Detecta Γ‘udio βββββββββββββββββββββββββββββββββββββββββββprobe_audio = subprocess.run(["ffprobe", "-v", "error"] + probe_extra + fmt_extra + ["-select_streams", "a","-show_entries", "stream=codec_type","-of", "json", input_path], capture_output=True, text=True)has_audio = len(json.loads(probe_audio.stdout).get("streams", [])) > 0# ββ GPU / logo ββββββββββββββββββββββββββββββββββββββββββββββquer_gpu = "GPU" in modo193 unmodified lines19419519619719819920020120220312 unmodified lines216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259193 unmodified linesyield None, "β Nenhum vΓdeo enviado!"return# Gradio 6 pode retornar dict {"path": "..."}, objeto com .name, ou stringif isinstance(video_file, dict):video_file = video_file.get("path") or video_file.get("name", "")elif hasattr(video_file, "name"):video_file = video_file.nameext = os.path.splitext(video_file)[1].lower() or ".mp4"12 unmodified linesprobe_extra = ["-analyzeduration", "100M", "-probesize", "100M"] if precisa_probe_extra else []fmt_extra = ["-f", "mpeg"] if ext == ".vob" else []def _run_ffprobe(args):"""Roda ffprobe e retorna dict parsed; em caso de falha loga e retorna {}."""r = subprocess.run(args, capture_output=True, text=True)if r.returncode != 0 or not r.stdout.strip():return None, r.stderr.strip()try:return json.loads(r.stdout), Noneexcept json.JSONDecodeError:return None, r.stdout[:300]# ββ Detecta dimensΓ£o / orientaΓ§Γ£o βββββββββββββββββββββββββββdata, err = _run_ffprobe(["ffprobe", "-v", "error"] + probe_extra + fmt_extra +["-select_streams", "v:0", "-show_entries", "stream=width,height","-of", "json", input_path])if data is None:yield None, f"β ffprobe falhou ao ler o vΓdeo:\n{err}"returnstream = data.get("streams", [{}])[0]vid_w = int(stream.get("width", 1920))vid_h = int(stream.get("height", 1080))is_vertical = vid_h > vid_w# ββ DuraΓ§Γ£o βββββββββββββββββββββββββββββββββββββββββββββββββdata_dur, _ = _run_ffprobe(["ffprobe", "-v", "error"] + probe_extra + fmt_extra +["-show_entries", "format=duration", "-of", "json", input_path])total_duration = float((data_dur or {}).get("format", {}).get("duration", 0))# ββ Detecta Γ‘udio βββββββββββββββββββββββββββββββββββββββββββdata_audio, _ = _run_ffprobe(["ffprobe", "-v", "error"] + probe_extra + fmt_extra +["-select_streams", "a", "-show_entries", "stream=codec_type","-of", "json", input_path])has_audio = len((data_audio or {}).get("streams", [])) > 0# ββ GPU / logo ββββββββββββββββββββββββββββββββββββββββββββββquer_gpu = "GPU" in modo
app.py+34-24