Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
|
@@ -194,8 +194,10 @@ def reencode_video(
|
|
| 194 |
yield None, "β Nenhum vΓdeo enviado!"
|
| 195 |
return
|
| 196 |
|
| 197 |
-
#
|
| 198 |
-
if
|
|
|
|
|
|
|
| 199 |
video_file = video_file.name
|
| 200 |
|
| 201 |
ext = os.path.splitext(video_file)[1].lower() or ".mp4"
|
|
@@ -214,36 +216,44 @@ def reencode_video(
|
|
| 214 |
probe_extra = ["-analyzeduration", "100M", "-probesize", "100M"] if precisa_probe_extra else []
|
| 215 |
fmt_extra = ["-f", "mpeg"] if ext == ".vob" else []
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
# ββ Detecta dimensΓ£o / orientaΓ§Γ£o βββββββββββββββββββββββββββ
|
| 218 |
-
|
| 219 |
-
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 220 |
-
"-select_streams", "v:0",
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
| 226 |
vid_w = int(stream.get("width", 1920))
|
| 227 |
vid_h = int(stream.get("height", 1080))
|
| 228 |
is_vertical = vid_h > vid_w
|
| 229 |
|
| 230 |
# ββ DuraΓ§Γ£o βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 231 |
-
|
| 232 |
-
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 233 |
-
"-show_entries", "format=duration",
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
dur_data = json.loads(probe_dur.stdout)
|
| 237 |
-
total_duration = float(dur_data.get("format", {}).get("duration", 0))
|
| 238 |
|
| 239 |
# ββ Detecta Γ‘udio βββββββββββββββββββββββββββββββββββββββββββ
|
| 240 |
-
|
| 241 |
-
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 242 |
-
"-select_streams", "a",
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
has_audio = len(json.loads(probe_audio.stdout).get("streams", [])) > 0
|
| 247 |
|
| 248 |
# ββ GPU / logo ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 249 |
quer_gpu = "GPU" in modo
|
|
|
|
| 194 |
yield None, "β Nenhum vΓdeo enviado!"
|
| 195 |
return
|
| 196 |
|
| 197 |
+
# Gradio 6 pode retornar dict {"path": "..."}, objeto com .name, ou string
|
| 198 |
+
if isinstance(video_file, dict):
|
| 199 |
+
video_file = video_file.get("path") or video_file.get("name", "")
|
| 200 |
+
elif hasattr(video_file, "name"):
|
| 201 |
video_file = video_file.name
|
| 202 |
|
| 203 |
ext = os.path.splitext(video_file)[1].lower() or ".mp4"
|
|
|
|
| 216 |
probe_extra = ["-analyzeduration", "100M", "-probesize", "100M"] if precisa_probe_extra else []
|
| 217 |
fmt_extra = ["-f", "mpeg"] if ext == ".vob" else []
|
| 218 |
|
| 219 |
+
def _run_ffprobe(args):
|
| 220 |
+
"""Roda ffprobe e retorna dict parsed; em caso de falha loga e retorna {}."""
|
| 221 |
+
r = subprocess.run(args, capture_output=True, text=True)
|
| 222 |
+
if r.returncode != 0 or not r.stdout.strip():
|
| 223 |
+
return None, r.stderr.strip()
|
| 224 |
+
try:
|
| 225 |
+
return json.loads(r.stdout), None
|
| 226 |
+
except json.JSONDecodeError:
|
| 227 |
+
return None, r.stdout[:300]
|
| 228 |
+
|
| 229 |
# ββ Detecta dimensΓ£o / orientaΓ§Γ£o βββββββββββββββββββββββββββ
|
| 230 |
+
data, err = _run_ffprobe(
|
| 231 |
+
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 232 |
+
["-select_streams", "v:0", "-show_entries", "stream=width,height",
|
| 233 |
+
"-of", "json", input_path]
|
| 234 |
+
)
|
| 235 |
+
if data is None:
|
| 236 |
+
yield None, f"β ffprobe falhou ao ler o vΓdeo:\n{err}"
|
| 237 |
+
return
|
| 238 |
+
stream = data.get("streams", [{}])[0]
|
| 239 |
vid_w = int(stream.get("width", 1920))
|
| 240 |
vid_h = int(stream.get("height", 1080))
|
| 241 |
is_vertical = vid_h > vid_w
|
| 242 |
|
| 243 |
# ββ DuraΓ§Γ£o βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 244 |
+
data_dur, _ = _run_ffprobe(
|
| 245 |
+
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 246 |
+
["-show_entries", "format=duration", "-of", "json", input_path]
|
| 247 |
+
)
|
| 248 |
+
total_duration = float((data_dur or {}).get("format", {}).get("duration", 0))
|
|
|
|
|
|
|
| 249 |
|
| 250 |
# ββ Detecta Γ‘udio βββββββββββββββββββββββββββββββββββββββββββ
|
| 251 |
+
data_audio, _ = _run_ffprobe(
|
| 252 |
+
["ffprobe", "-v", "error"] + probe_extra + fmt_extra +
|
| 253 |
+
["-select_streams", "a", "-show_entries", "stream=codec_type",
|
| 254 |
+
"-of", "json", input_path]
|
| 255 |
+
)
|
| 256 |
+
has_audio = len((data_audio or {}).get("streams", [])) > 0
|
|
|
|
| 257 |
|
| 258 |
# ββ GPU / logo ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 259 |
quer_gpu = "GPU" in modo
|