Carlos s commited on
Commit
33dc42e
·
verified ·
1 Parent(s): 6ae650c

Update api/ltx_server.py

Browse files
Files changed (1) hide show
  1. api/ltx_server.py +38 -29
api/ltx_server.py CHANGED
@@ -398,47 +398,56 @@ class VideoService:
398
  return out
399
 
400
 
401
- def _dividir_latentes(self, latents, num_por_chunk: int, overlap: int = 1):
 
402
  # latents: [B, C, T, H, W]
403
  T = latents.shape[2]
404
- L = num_por_chunk + overlap # janela com stop exclusivo
405
- stride = num_por_chunk - overlap # avanço
406
- print("================= DEBUG =================") # debug
407
- print(f"[DEBUG] T={T} L={L} stride={stride}") # debug
408
- print(f"[DEBUG] regra: slice [start:stop) com stop exclusivo") # debug
409
 
410
- if T <= L:
411
- start = max(0, T - L)
412
- stop = start + L
413
- chunk = latents[:, :, start:stop, :, :].clone().detach()
414
- print(f"[DEBUG] único chunk: [:, :, {start}:{stop}, :, :] len={stop-start}") # debug
415
- print("=========================================") # debug
416
- return [chunk]
417
 
 
418
  starts = []
419
  s = 0
420
- while s + L <= T:
421
- starts.append(s)
 
 
 
 
 
 
 
 
 
422
  s += stride
423
- if starts[-1] + L < T:
424
- starts.append(T - L)
425
 
426
- # remove duplicata contígua
427
- uniq = []
428
- for st in starts:
429
- if not uniq or uniq[-1] != st:
430
- uniq.append(st)
431
 
432
- chunks = []
433
- for i, st in enumerate(uniq):
434
- sp = st + L
 
 
 
 
 
 
 
 
435
  chunk = latents[:, :, st:sp, :, :].clone().detach()
436
- print(f"[DEBUG] chunk{i}: [:, :, {st}:{sp}, :, :] len={sp-st}") # debug
437
- chunks.append(chunk)
438
 
439
- print("=========================================") # debug
440
- return chunks
441
 
 
442
  def _get_total_frames(self, video_path: str) -> int:
443
  cmd = [
444
  "ffprobe",
 
398
  return out
399
 
400
 
401
+
402
+ def dividir_latentes(latents, num_por_chunk: int, overlap: int = 1):
403
  # latents: [B, C, T, H, W]
404
  T = latents.shape[2]
405
+ L = num_por_chunk + overlap
406
+ stride = num_por_chunk - overlap
 
 
 
407
 
408
+ print("================= DEBUG =================")
409
+ print(f"[DEBUG] T={T} L={L} stride={stride}")
410
+ print(f"[DEBUG] regra: slice [start:stop) com stop exclusivo")
 
 
 
 
411
 
412
+ chunks = []
413
  starts = []
414
  s = 0
415
+ # gera janelas “naturais” com possível encurtamento quando passam de T
416
+ while s < T:
417
+ start = s
418
+ stop = s + L
419
+ if stop > T:
420
+ # encurta janela intermediária em vez de descartar
421
+ stop = T
422
+ # evita janela vazia
423
+ if start < stop:
424
+ starts.append((start, stop))
425
+ # próximo início com sobreposição de 1
426
  s += stride
 
 
427
 
428
+ # condição de pare sem loop infinito
429
+ if s >= T:
430
+ break
 
 
431
 
432
+ # ancora uma janela final completa no fim [T-L:T), se necessário
433
+ final_start = max(0, T - L)
434
+ final_pair = (final_start, final_start + L)
435
+ if not starts or starts[-1] != final_pair:
436
+ # evita duplicar se já coincidiu
437
+ if not starts or starts[-1] != final_pair:
438
+ starts.append(final_pair)
439
+
440
+ # imprime e retorna
441
+ out = []
442
+ for i, (st, sp) in enumerate(starts):
443
  chunk = latents[:, :, st:sp, :, :].clone().detach()
444
+ print(f"[DEBUG] chunk{i}: [:, :, {st}:{sp if sp<=T else ''}, :, :] len={sp-st}")
445
+ out.append(chunk)
446
 
447
+ print("=========================================")
448
+ return out
449
 
450
+
451
  def _get_total_frames(self, video_path: str) -> int:
452
  cmd = [
453
  "ffprobe",