Spaces:
Paused
Paused
Upload app.py
Browse files193 unmodified lines19419519619719819719819920020120220312 unmodified lines216217218219220221222223224225226227228229218219220221222223224225230231232233234235236237238239240241242243231232233234235236237244245246247248249250240241242243244245246251252253254255256257258259193 unmodified lines yield None, "β Nenhum vΓdeo enviado!" return
# gr.File pode retornar objeto com .name em algumas versΓ΅es do Gradio if hasattr(video_file, "name"): # Gradio 6 pode retornar dict {"path": "..."}, objeto com .name, ou string if isinstance(video_file, dict): video_file = video_file.get("path") or video_file.get("name", "") elif hasattr(video_file, "name"): video_file = video_file.name
ext = os.path.splitext(video_file)[1].lower() or ".mp4"12 unmodified lines probe_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), None except json.JSONDecodeError: return None, r.stdout[:300]
# ββ 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] 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}" return stream = 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)) 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 βββββββββββββββββββββββββββββββββββββββββββ 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 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 modoapp.py+34-24