Update deformes4D_engine.py
Browse files- deformes4D_engine.py +25 -21
deformes4D_engine.py
CHANGED
|
@@ -125,33 +125,37 @@ class Deformes4DEngine:
|
|
| 125 |
video_resolution: int, use_continuity_director: bool,
|
| 126 |
progress: gr.Progress = gr.Progress()):
|
| 127 |
|
| 128 |
-
# --- Lógica de Controle Dinâmico
|
| 129 |
-
|
|
|
|
| 130 |
total_chunks_gerados = max(5, int(round(seconds_per_fragment * 24 / 8)))
|
| 131 |
-
video_chunk_count = max(1, int(round(total_chunks_gerados * (1 - (trim_percent / 100)))))
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
#
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
| 142 |
|
| 143 |
-
# O ponto de aplicação do handler agora é fixo para maior estabilidade
|
| 144 |
HANDLER_FRAME_TARGET = (trim_chunks - 2) * 8
|
| 145 |
FRAMES_TO_GENERATE = (total_chunks_gerados - 1) * 8 + 1
|
| 146 |
DESTINATION_FRAME_TARGET = FRAMES_TO_GENERATE - 1
|
| 147 |
|
| 148 |
logger.info("="*60)
|
| 149 |
-
logger.info("MODO DE GERAÇÃO: Estratégia de
|
| 150 |
-
logger.info(f" - Geração Bruta: {total_chunks_gerados} chunks")
|
| 151 |
-
logger.info(f" -
|
| 152 |
-
logger.info(f" -
|
| 153 |
-
logger.info(f" - Guia
|
| 154 |
-
logger.info(f" -
|
|
|
|
| 155 |
logger.info("="*60)
|
| 156 |
|
| 157 |
base_ltx_params = {"guidance_scale": 1.0, "stg_scale": 0.0, "rescaling_scale": 0.15, "num_inference_steps": 20}
|
|
@@ -202,11 +206,11 @@ class Deformes4DEngine:
|
|
| 202 |
new_full_latents = self._generate_latent_tensor_internal(conditioning_items, current_ltx_params, target_resolution_tuple, FRAMES_TO_GENERATE)
|
| 203 |
logger.info(f" [1. GERAÇÃO] Tensor latente bruto gerado com shape: {new_full_latents.shape}.")
|
| 204 |
|
| 205 |
-
eco_latent_for_next_loop = new_full_latents[:, :,
|
| 206 |
-
handler_latent_for_next_loop = new_full_latents[:, :,
|
| 207 |
logger.info(f" [GUIAS] Guias para a próxima iteração extraídas. Eco shape: {eco_latent_for_next_loop.shape}, Handler shape: {handler_latent_for_next_loop.shape}.")
|
| 208 |
|
| 209 |
-
latents_for_video = new_full_latents[:, :,
|
| 210 |
logger.info(f" [2. EDIÇÃO] Tensor final para vídeo extraído com {latents_for_video.shape[2]} chunks.")
|
| 211 |
|
| 212 |
base_name = f"fragment_{i}_{int(time.time())}"
|
|
|
|
| 125 |
video_resolution: int, use_continuity_director: bool,
|
| 126 |
progress: gr.Progress = gr.Progress()):
|
| 127 |
|
| 128 |
+
# --- [INÍCIO] Lógica de Controle Dinâmico Baseada em Dois Sliders ---
|
| 129 |
+
|
| 130 |
+
# 1. Calcular o total de chunks a serem gerados a partir dos segundos
|
| 131 |
total_chunks_gerados = max(5, int(round(seconds_per_fragment * 24 / 8)))
|
|
|
|
| 132 |
|
| 133 |
+
# 2. Calcular o número de chunks a podar com base na porcentagem, com mínimo de 4
|
| 134 |
+
trim_chunks = max(4, int(round(total_chunks_gerados * (trim_percent / 100))))
|
| 135 |
+
|
| 136 |
+
# Regra de segurança para evitar que a poda consuma o vídeo inteiro
|
| 137 |
+
if trim_chunks >= total_chunks_gerados:
|
| 138 |
+
trim_chunks = total_chunks_gerados - 1
|
| 139 |
+
logger.warning(f"A poda ({trim_percent}%) era muito grande. Ajustada para {trim_chunks} chunks para deixar 1 chunk de vídeo.")
|
| 140 |
|
| 141 |
+
# 3. Definir fatias e alvos com base nos cálculos
|
| 142 |
+
VIDEO_CHUNK_COUNT = total_chunks_gerados - trim_chunks
|
| 143 |
+
|
| 144 |
+
HANDLER_CHUNK_INDICES = slice(total_chunks_gerados - 2, total_chunks_gerados)
|
| 145 |
+
ECO_CHUNK_INDICES = slice(total_chunks_gerados - 4, total_chunks_gerados - 2)
|
| 146 |
|
|
|
|
| 147 |
HANDLER_FRAME_TARGET = (trim_chunks - 2) * 8
|
| 148 |
FRAMES_TO_GENERATE = (total_chunks_gerados - 1) * 8 + 1
|
| 149 |
DESTINATION_FRAME_TARGET = FRAMES_TO_GENERATE - 1
|
| 150 |
|
| 151 |
logger.info("="*60)
|
| 152 |
+
logger.info("MODO DE GERAÇÃO: Estratégia de Cauda Longa Dinâmica")
|
| 153 |
+
logger.info(f" - Duração Solicitada: {seconds_per_fragment}s -> Geração Bruta: {total_chunks_gerados} chunks")
|
| 154 |
+
logger.info(f" - Poda Solicitada: {trim_percent}% -> Chunks de Poda (Cauda): {trim_chunks}")
|
| 155 |
+
logger.info(f" - Clipe Final por Fragmento: {VIDEO_CHUNK_COUNT} chunks")
|
| 156 |
+
logger.info(f" - Guia de Eco (Memória): Chunks {ECO_CHUNK_INDICES.start}-{ECO_CHUNK_INDICES.stop-1}")
|
| 157 |
+
logger.info(f" - Guia de Handler (Evolução): Chunks {HANDLER_CHUNK_INDICES.start}-{HANDLER_CHUNK_INDICES.stop-1}")
|
| 158 |
+
logger.info(f" - PONTO DE APLICAÇÃO DO HANDLER (DINÂMICO): Frame {HANDLER_FRAME_TARGET}")
|
| 159 |
logger.info("="*60)
|
| 160 |
|
| 161 |
base_ltx_params = {"guidance_scale": 1.0, "stg_scale": 0.0, "rescaling_scale": 0.15, "num_inference_steps": 20}
|
|
|
|
| 206 |
new_full_latents = self._generate_latent_tensor_internal(conditioning_items, current_ltx_params, target_resolution_tuple, FRAMES_TO_GENERATE)
|
| 207 |
logger.info(f" [1. GERAÇÃO] Tensor latente bruto gerado com shape: {new_full_latents.shape}.")
|
| 208 |
|
| 209 |
+
eco_latent_for_next_loop = new_full_latents[:, :, ECO_CHUNK_INDICES, :, :].clone()
|
| 210 |
+
handler_latent_for_next_loop = new_full_latents[:, :, HANDLER_CHUNK_INDICES, :, :].clone()
|
| 211 |
logger.info(f" [GUIAS] Guias para a próxima iteração extraídas. Eco shape: {eco_latent_for_next_loop.shape}, Handler shape: {handler_latent_for_next_loop.shape}.")
|
| 212 |
|
| 213 |
+
latents_for_video = new_full_latents[:, :, :VIDEO_CHUNK_COUNT, :, :]
|
| 214 |
logger.info(f" [2. EDIÇÃO] Tensor final para vídeo extraído com {latents_for_video.shape[2]} chunks.")
|
| 215 |
|
| 216 |
base_name = f"fragment_{i}_{int(time.time())}"
|