EuuIia commited on
Commit
b5c96ef
·
verified ·
1 Parent(s): 6156fa0

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +16 -13
api/ltx_server.py CHANGED
@@ -436,10 +436,10 @@ class VideoService:
436
  print("================PODA CAUSAL=================")
437
  return chunks
438
 
439
-
440
- def _get_total_frames(self, video_path):
441
  cmd = [
442
- "ffprobe", "-v", "error",
 
443
  "-select_streams", "v:0",
444
  "-count_frames",
445
  "-show_entries", "stream=nb_read_frames",
@@ -448,7 +448,8 @@ class VideoService:
448
  ]
449
  result = subprocess.run(cmd, capture_output=True, text=True, check=True)
450
  return int(result.stdout.strip())
451
-
 
452
  def _gerar_lista_com_transicoes(self, pasta: str, video_paths: list[str], crossfade_frames: int = 8) -> list[str]:
453
  """
454
  Gera uma nova lista de vídeos aplicando transições suaves (blend frame a frame)
@@ -470,17 +471,19 @@ class VideoService:
470
 
471
  # --- PODA ---
472
  video_podado = os.path.join(pasta, f"{base}_podado_{i}.mp4")
473
- total_frames = self._get_total_frames(video_clone)
474
- trim_ini = 0
475
- trim_end = total_frames - poda # para cortar últimos frames
476
- cmd_poda = (
 
477
  f'ffmpeg -y -hide_banner -loglevel error -i "{video_clone}" '
478
- f'-vf "trim=start_frame={trim_ini}:end_frame={trim_end},setpts=PTS-STARTPTS" '
479
- f'-an "{video_podado}"'
480
  )
481
- subprocess.run(cmd_poda, shell=True, check=True)
482
- nova_lista.append(video_podado)
483
- print(f"[DEBUG] [{i}] Podado -> {video_podado}")
 
484
 
485
  # --- FADE_INI ---
486
  video_fade_ini = None
 
436
  print("================PODA CAUSAL=================")
437
  return chunks
438
 
439
+ def get_total_frames(video_path: str) -> int:
 
440
  cmd = [
441
+ "ffprobe",
442
+ "-v", "error",
443
  "-select_streams", "v:0",
444
  "-count_frames",
445
  "-show_entries", "stream=nb_read_frames",
 
448
  ]
449
  result = subprocess.run(cmd, capture_output=True, text=True, check=True)
450
  return int(result.stdout.strip())
451
+
452
+
453
  def _gerar_lista_com_transicoes(self, pasta: str, video_paths: list[str], crossfade_frames: int = 8) -> list[str]:
454
  """
455
  Gera uma nova lista de vídeos aplicando transições suaves (blend frame a frame)
 
471
 
472
  # --- PODA ---
473
  video_podado = os.path.join(pasta, f"{base}_podado_{i}.mp4")
474
+ total_frames = get_total_frames(video_clone)
475
+ trim_ini = total_frames - poda # posição inicial do fade
476
+ video_fade_fim = os.path.join(pasta, f"{base}_fade_fim_{i}.mp4")
477
+
478
+ cmd_fim = (
479
  f'ffmpeg -y -hide_banner -loglevel error -i "{video_clone}" '
480
+ f'-vf "trim=start_frame={trim_ini}:end_frame={total_frames},setpts=PTS-STARTPTS" '
481
+ f'-an "{video_fade_fim}"'
482
  )
483
+ subprocess.run(cmd_fim, shell=True, check=True)
484
+ video_anterior_fade_fim = video_fade_fim
485
+ print(f"[DEBUG] Fade_fim preparado -> {video_fade_fim}")
486
+
487
 
488
  # --- FADE_INI ---
489
  video_fade_ini = None