EuuIia commited on
Commit
35d232d
·
verified ·
1 Parent(s): cf11167

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. 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 _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,
 
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,