Spaces:
Paused
Paused
Update api/ltx_server.py
Browse files- api/ltx_server.py +28 -18
api/ltx_server.py
CHANGED
|
@@ -447,21 +447,37 @@ class VideoService:
|
|
| 447 |
|
| 448 |
return primeira, segunda
|
| 449 |
|
| 450 |
-
def _concat_mp4s_no_reencode(self,
|
| 451 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
try:
|
| 459 |
-
subprocess.check_call(shlex.split(cmd))
|
| 460 |
finally:
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
|
|
|
|
|
|
| 465 |
def generate(
|
| 466 |
self,
|
| 467 |
prompt,
|
|
@@ -690,12 +706,6 @@ class VideoService:
|
|
| 690 |
print(f"[DEBUG] Falha no move; usando tmp como final: {e}")
|
| 691 |
|
| 692 |
final_concat = os.path.join(results_dir, f"concat_fim_{used_seed}.mp4")
|
| 693 |
-
|
| 694 |
-
self._concat_mp4s_no_reencode(partes_mp4[0], partes_mp4[1], final_concat)
|
| 695 |
-
self._concat_mp4s_no_reencode(final_concat, partes_mp4[2], final_concat)
|
| 696 |
-
self._concat_mp4s_no_reencode(final_concat, partes_mp4[3], final_concat)
|
| 697 |
-
|
| 698 |
-
|
| 699 |
|
| 700 |
self._log_gpu_memory("Fim da Geração")
|
| 701 |
return final_concat, used_seed
|
|
|
|
| 447 |
|
| 448 |
return primeira, segunda
|
| 449 |
|
| 450 |
+
def _concat_mp4s_no_reencode(self, mp4_paths: List[str], out_path: str):
|
| 451 |
+
# Valida entradas
|
| 452 |
+
if not mp4_paths or len(mp4_paths) < 2:
|
| 453 |
+
raise ValueError("Forneça pelo menos dois MP4s para concatenação.") # [memory:5]
|
| 454 |
+
abs_paths = []
|
| 455 |
+
for p in mp4_paths:
|
| 456 |
+
if not os.path.exists(p):
|
| 457 |
+
raise FileNotFoundError(f"Arquivo não encontrado: {p}") # [memory:5]
|
| 458 |
+
abs_paths.append(os.path.abspath(p)) # [memory:5]
|
| 459 |
+
|
| 460 |
+
# Cria lista para o demuxer concat (sem reencode)
|
| 461 |
+
list_path = None
|
| 462 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 463 |
+
for ap in abs_paths:
|
| 464 |
+
# Escapa aspas simples no caminho se necessário
|
| 465 |
+
ap_escaped = ap.replace("'", r"'\''") # [memory:5]
|
| 466 |
+
f.write(f"file '{ap_escaped}'\n") # [memory:5]
|
| 467 |
+
list_path = f.name # [memory:5]
|
| 468 |
+
|
| 469 |
+
cmd = f"ffmpeg -y -f concat -safe 0 -i {list_path} -c copy {out_path}" # [memory:5]
|
| 470 |
+
print(f"[DEBUG] Concat: {cmd}") # [memory:8]
|
| 471 |
+
|
| 472 |
try:
|
| 473 |
+
subprocess.check_call(shlex.split(cmd)) # [memory:5]
|
| 474 |
finally:
|
| 475 |
+
if list_path:
|
| 476 |
+
try:
|
| 477 |
+
os.remove(list_path) # [memory:5]
|
| 478 |
+
except Exception:
|
| 479 |
+
pass # [memory:5] # --- 6. GERAÇÃO ---
|
| 480 |
+
|
| 481 |
def generate(
|
| 482 |
self,
|
| 483 |
prompt,
|
|
|
|
| 706 |
print(f"[DEBUG] Falha no move; usando tmp como final: {e}")
|
| 707 |
|
| 708 |
final_concat = os.path.join(results_dir, f"concat_fim_{used_seed}.mp4")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 709 |
|
| 710 |
self._log_gpu_memory("Fim da Geração")
|
| 711 |
return final_concat, used_seed
|