Update api/ltx_server.py
Browse files- api/ltx_server.py +11 -12
api/ltx_server.py
CHANGED
|
@@ -485,10 +485,8 @@ class VideoService:
|
|
| 485 |
)
|
| 486 |
subprocess.run(cmd_fim, shell=True, check=True)
|
| 487 |
video_anterior_fade_fim = video_fade_fim
|
| 488 |
-
print(f"[DEBUG] Fade_fim preparado -> {video_fade_fim}")
|
| 489 |
-
|
| 490 |
-
|
| 491 |
|
|
|
|
| 492 |
# --- FADE_INI ---
|
| 493 |
video_fade_ini = None
|
| 494 |
if i > 0:
|
|
@@ -498,8 +496,7 @@ class VideoService:
|
|
| 498 |
f'-vf "trim=end_frame={poda},setpts=PTS-STARTPTS" -an "{video_fade_ini}"'
|
| 499 |
)
|
| 500 |
subprocess.run(cmd_ini, shell=True, check=True)
|
| 501 |
-
|
| 502 |
-
|
| 503 |
# --- TRANSIÇÃO ---
|
| 504 |
if video_anterior_fade_fim and video_fade_ini:
|
| 505 |
transicao = os.path.join(pasta, f"transicao_{i-1}_{i}.mp4")
|
|
@@ -511,8 +508,7 @@ class VideoService:
|
|
| 511 |
)
|
| 512 |
subprocess.run(cmd_blend, shell=True, check=True)
|
| 513 |
nova_lista.append(transicao)
|
| 514 |
-
|
| 515 |
-
|
| 516 |
# --- FADE_FIM ---
|
| 517 |
if i < total_partes - 1:
|
| 518 |
video_fade_fim = os.path.join(pasta, f"{base}_fade_fim_{i}.mp4")
|
|
@@ -522,9 +518,10 @@ class VideoService:
|
|
| 522 |
cmd_fim = f'ffmpeg -y -hide_banner -loglevel error -i "{video_clone}" -vf "trim=start_frame={start_frame},setpts=PTS-STARTPTS" -an "{video_fade_fim}"'
|
| 523 |
subprocess.run(cmd_fim, shell=True, check=True)
|
| 524 |
video_anterior_fade_fim = video_fade_fim
|
| 525 |
-
|
| 526 |
-
|
| 527 |
print(f"[DEBUG] Nova lista finalizada com {len(nova_lista)} partes.")
|
|
|
|
|
|
|
| 528 |
return nova_lista
|
| 529 |
|
| 530 |
def _concat_mp4s_no_reencode(self, mp4_list: List[str], out_path: str):
|
|
@@ -534,14 +531,16 @@ class VideoService:
|
|
| 534 |
"""
|
| 535 |
if not mp4_list or len(mp4_list) < 2:
|
| 536 |
raise ValueError("Forneça pelo menos dois arquivos MP4 para concatenar.")
|
| 537 |
-
|
|
|
|
|
|
|
|
|
|
| 538 |
# Cria lista temporária para o ffmpeg
|
| 539 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 540 |
ind =0
|
| 541 |
for mp4 in mp4_list:
|
| 542 |
ind += 1
|
| 543 |
-
|
| 544 |
-
f.write(f"file '{os.path.abspath(mp4)}'\n")
|
| 545 |
list_path = f.name
|
| 546 |
|
| 547 |
cmd = f"ffmpeg -y -f concat -safe 0 -i {list_path} -c copy {out_path}"
|
|
|
|
| 485 |
)
|
| 486 |
subprocess.run(cmd_fim, shell=True, check=True)
|
| 487 |
video_anterior_fade_fim = video_fade_fim
|
|
|
|
|
|
|
|
|
|
| 488 |
|
| 489 |
+
|
| 490 |
# --- FADE_INI ---
|
| 491 |
video_fade_ini = None
|
| 492 |
if i > 0:
|
|
|
|
| 496 |
f'-vf "trim=end_frame={poda},setpts=PTS-STARTPTS" -an "{video_fade_ini}"'
|
| 497 |
)
|
| 498 |
subprocess.run(cmd_ini, shell=True, check=True)
|
| 499 |
+
|
|
|
|
| 500 |
# --- TRANSIÇÃO ---
|
| 501 |
if video_anterior_fade_fim and video_fade_ini:
|
| 502 |
transicao = os.path.join(pasta, f"transicao_{i-1}_{i}.mp4")
|
|
|
|
| 508 |
)
|
| 509 |
subprocess.run(cmd_blend, shell=True, check=True)
|
| 510 |
nova_lista.append(transicao)
|
| 511 |
+
|
|
|
|
| 512 |
# --- FADE_FIM ---
|
| 513 |
if i < total_partes - 1:
|
| 514 |
video_fade_fim = os.path.join(pasta, f"{base}_fade_fim_{i}.mp4")
|
|
|
|
| 518 |
cmd_fim = f'ffmpeg -y -hide_banner -loglevel error -i "{video_clone}" -vf "trim=start_frame={start_frame},setpts=PTS-STARTPTS" -an "{video_fade_fim}"'
|
| 519 |
subprocess.run(cmd_fim, shell=True, check=True)
|
| 520 |
video_anterior_fade_fim = video_fade_fim
|
| 521 |
+
|
|
|
|
| 522 |
print(f"[DEBUG] Nova lista finalizada com {len(nova_lista)} partes.")
|
| 523 |
+
print(f"[DEBUG] {nova_lista}")
|
| 524 |
+
|
| 525 |
return nova_lista
|
| 526 |
|
| 527 |
def _concat_mp4s_no_reencode(self, mp4_list: List[str], out_path: str):
|
|
|
|
| 531 |
"""
|
| 532 |
if not mp4_list or len(mp4_list) < 2:
|
| 533 |
raise ValueError("Forneça pelo menos dois arquivos MP4 para concatenar.")
|
| 534 |
+
|
| 535 |
+
for i in range(mp4_list):
|
| 536 |
+
print(f"[DEBUG] mp4_list {mp4} FRAMES {self._get_total_frames(mp4_list[i])}")
|
| 537 |
+
|
| 538 |
# Cria lista temporária para o ffmpeg
|
| 539 |
with tempfile.NamedTemporaryFile("w", delete=False, suffix=".txt") as f:
|
| 540 |
ind =0
|
| 541 |
for mp4 in mp4_list:
|
| 542 |
ind += 1
|
| 543 |
+
f.write(f"file '{os.path.abspath(mp4)}'\n")
|
|
|
|
| 544 |
list_path = f.name
|
| 545 |
|
| 546 |
cmd = f"ffmpeg -y -f concat -safe 0 -i {list_path} -c copy {out_path}"
|