EuuIia commited on
Commit
289bb8a
·
verified ·
1 Parent(s): 4cdfd1b

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +22 -7
api/ltx_server.py CHANGED
@@ -436,6 +436,19 @@ class VideoService:
436
  print("================PODA CAUSAL=================")
437
  return chunks
438
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
  def _gerar_lista_com_transicoes(self, pasta: str, video_paths: list[str], crossfade_frames: int = 8) -> list[str]:
440
  """
441
  Gera uma nova lista de vídeos aplicando transições suaves (blend frame a frame)
@@ -457,16 +470,18 @@ class VideoService:
457
 
458
  # --- PODA ---
459
  video_podado = os.path.join(pasta, f"{base}_podado_{i}.mp4")
460
- trim_ini = poda if i > 0 else 0
461
- trim_fim = -poda if i < total_partes - 1 else 0
462
- filtro_trim = f"trim=start_frame={trim_ini}"
463
- if trim_fim != 0:
464
- filtro_trim += f":end_frame=nb_frames+{trim_fim}"
465
- cmd_poda = f'ffmpeg -y -hide_banner -loglevel error -i "{video_clone}" -vf "{filtro_trim},setpts=PTS-STARTPTS" -an "{video_podado}"'
 
 
466
  subprocess.run(cmd_poda, shell=True, check=True)
467
  nova_lista.append(video_podado)
468
  print(f"[DEBUG] [{i}] Podado -> {video_podado}")
469
-
470
  # --- FADE_INI ---
471
  video_fade_ini = None
472
  if i > 0:
 
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",
446
+ "-of", "default=nokey=1:noprint_wrappers=1",
447
+ video_path
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
 
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
487
  if i > 0: