Spaces:
Paused
Paused
Update api/ltx_server.py
Browse files- api/ltx_server.py +20 -25
api/ltx_server.py
CHANGED
|
@@ -447,37 +447,32 @@ class VideoService:
|
|
| 447 |
|
| 448 |
return primeira, segunda
|
| 449 |
|
| 450 |
-
def
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 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
|
| 461 |
-
list_path = None
|
| 462 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 463 |
-
for
|
| 464 |
-
|
| 465 |
-
|
| 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}"
|
| 470 |
-
print(f"[DEBUG] Concat: {cmd}")
|
| 471 |
|
| 472 |
try:
|
| 473 |
-
subprocess.check_call(shlex.split(cmd))
|
| 474 |
finally:
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
def generate(
|
| 482 |
self,
|
| 483 |
prompt,
|
|
|
|
| 447 |
|
| 448 |
return primeira, segunda
|
| 449 |
|
| 450 |
+
def concat_mp4s_no_reencode(mp4_list: List[str], out_path: str):
|
| 451 |
+
"""
|
| 452 |
+
Concatena múltiplos MP4s sem reencode usando o demuxer do ffmpeg.
|
| 453 |
+
ATENÇÃO: todos os arquivos precisam ter mesmo codec, fps, resolução etc.
|
| 454 |
+
"""
|
| 455 |
+
if not mp4_list or len(mp4_list) < 2:
|
| 456 |
+
raise ValueError("Forneça pelo menos dois arquivos MP4 para concatenar.")
|
|
|
|
|
|
|
| 457 |
|
| 458 |
+
# Cria lista temporária para o ffmpeg
|
|
|
|
| 459 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 460 |
+
for mp4 in mp4_list:
|
| 461 |
+
f.write(f"file '{os.path.abspath(mp4)}'\n")
|
| 462 |
+
list_path = f.name
|
|
|
|
|
|
|
| 463 |
|
| 464 |
+
cmd = f"ffmpeg -y -f concat -safe 0 -i {list_path} -c copy {out_path}"
|
| 465 |
+
print(f"[DEBUG] Concat: {cmd}")
|
| 466 |
|
| 467 |
try:
|
| 468 |
+
subprocess.check_call(shlex.split(cmd))
|
| 469 |
finally:
|
| 470 |
+
try:
|
| 471 |
+
os.remove(list_path)
|
| 472 |
+
except Exception:
|
| 473 |
+
pass
|
| 474 |
+
|
| 475 |
+
|
| 476 |
def generate(
|
| 477 |
self,
|
| 478 |
prompt,
|