Update aduc_framework/engineers/deformes4D.py
Browse files
aduc_framework/engineers/deformes4D.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Versão 3.0.
|
| 6 |
#
|
| 7 |
# Este engenheiro implementa a Câmera (Ψ) e o Destilador (Δ) da arquitetura
|
| 8 |
# ADUC-SDR. Ele orquestra a geração sequencial de fragmentos de vídeo com base
|
|
@@ -115,7 +115,8 @@ class Deformes4DEngine:
|
|
| 115 |
for i in range(num_transitions_to_generate):
|
| 116 |
fragment_index = i + 1
|
| 117 |
if progress_callback:
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
past_keyframe_path = keyframe_paths[i - 1] if i > 0 else keyframe_paths[i]
|
| 121 |
start_keyframe_path = keyframe_paths[i]
|
|
@@ -166,14 +167,41 @@ class Deformes4DEngine:
|
|
| 166 |
|
| 167 |
logger.info(f"--- INICIANDO ESTÁGIO 2: Processando {len(latent_fragment_paths)} latentes ---")
|
| 168 |
final_video_clip_paths = []
|
| 169 |
-
num_chunks = -(-len(latent_fragment_paths) // LATENT_PROCESSING_CHUNK_SIZE)
|
| 170 |
for i in range(num_chunks):
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
if progress_callback: progress_callback(0.98, "Montando o filme final...")
|
|
|
|
| 175 |
final_video_path = os.path.join(self.workspace_dir, f"original_movie_{run_timestamp}.mp4")
|
| 176 |
-
video_encode_tool_singleton.concatenate_videos(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
logger.info(f"Processo completo! Vídeo original salvo em: {final_video_path}")
|
| 178 |
|
| 179 |
# 3. Empacota os resultados para o Orchestrator
|
|
@@ -189,8 +217,7 @@ class Deformes4DEngine:
|
|
| 189 |
"latent_paths": latent_fragment_paths,
|
| 190 |
"video_data": final_video_data_for_state
|
| 191 |
}
|
| 192 |
-
|
| 193 |
-
# --- MÉTODOS HELPER ---
|
| 194 |
def save_video_from_tensor(self, video_tensor: torch.Tensor, path: str, fps: int = 24):
|
| 195 |
if video_tensor is None or video_tensor.ndim != 5 or video_tensor.shape[2] == 0: return
|
| 196 |
video_tensor = video_tensor.squeeze(0).permute(1, 2, 3, 0)
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Versão 3.0.2 (Framework-Compliant com Lógica de Geração Restaurada)
|
| 6 |
#
|
| 7 |
# Este engenheiro implementa a Câmera (Ψ) e o Destilador (Δ) da arquitetura
|
| 8 |
# ADUC-SDR. Ele orquestra a geração sequencial de fragmentos de vídeo com base
|
|
|
|
| 115 |
for i in range(num_transitions_to_generate):
|
| 116 |
fragment_index = i + 1
|
| 117 |
if progress_callback:
|
| 118 |
+
progress_fraction = (i / num_transitions_to_generate) * 0.7 # Geração de latentes usa 70% do tempo
|
| 119 |
+
progress_callback(progress_fraction, f"Gerando Latente {fragment_index}/{num_transitions_to_generate}")
|
| 120 |
|
| 121 |
past_keyframe_path = keyframe_paths[i - 1] if i > 0 else keyframe_paths[i]
|
| 122 |
start_keyframe_path = keyframe_paths[i]
|
|
|
|
| 167 |
|
| 168 |
logger.info(f"--- INICIANDO ESTÁGIO 2: Processando {len(latent_fragment_paths)} latentes ---")
|
| 169 |
final_video_clip_paths = []
|
| 170 |
+
num_chunks = -(-len(latent_fragment_paths) // LATENT_PROCESSING_CHUNK_SIZE) if LATENT_PROCESSING_CHUNK_SIZE > 0 else 0
|
| 171 |
for i in range(num_chunks):
|
| 172 |
+
chunk_start_index = i * LATENT_PROCESSING_CHUNK_SIZE
|
| 173 |
+
chunk_end_index = chunk_start_index + LATENT_PROCESSING_CHUNK_SIZE
|
| 174 |
+
chunk_paths = latent_fragment_paths[chunk_start_index:chunk_end_index]
|
| 175 |
+
|
| 176 |
+
if progress_callback:
|
| 177 |
+
progress_fraction = 0.7 + (i / num_chunks * 0.28) # Decodificação usa 28% do tempo
|
| 178 |
+
progress_callback(progress_fraction, f"Processando & Decodificando Lote {i+1}/{num_chunks}")
|
| 179 |
+
|
| 180 |
+
tensors_in_chunk = [torch.load(p, map_location=self.device) for p in chunk_paths]
|
| 181 |
+
tensors_para_concatenar = [frag[:, :, :-1, :, :] if j < len(tensors_in_chunk) - 1 else frag for j, frag in enumerate(tensors_in_chunk)]
|
| 182 |
+
sub_group_latent = torch.cat(tensors_para_concatenar, dim=2)
|
| 183 |
+
del tensors_in_chunk, tensors_para_concatenar; gc.collect(); torch.cuda.empty_cache()
|
| 184 |
+
|
| 185 |
+
pixel_tensor = vae_manager_singleton.decode(sub_group_latent)
|
| 186 |
+
del sub_group_latent; gc.collect(); torch.cuda.empty_cache()
|
| 187 |
+
|
| 188 |
+
base_name = f"clip_{i:04d}_{run_timestamp}"
|
| 189 |
+
current_clip_path = os.path.join(temp_video_clips_dir, f"{base_name}.mp4")
|
| 190 |
+
self.save_video_from_tensor(pixel_tensor, current_clip_path, fps=FPS)
|
| 191 |
+
final_video_clip_paths.append(current_clip_path)
|
| 192 |
+
del pixel_tensor; gc.collect(); torch.cuda.empty_cache()
|
| 193 |
+
|
| 194 |
if progress_callback: progress_callback(0.98, "Montando o filme final...")
|
| 195 |
+
|
| 196 |
final_video_path = os.path.join(self.workspace_dir, f"original_movie_{run_timestamp}.mp4")
|
| 197 |
+
video_encode_tool_singleton.concatenate_videos(final_video_clip_paths, final_video_path, self.workspace_dir)
|
| 198 |
+
|
| 199 |
+
try:
|
| 200 |
+
shutil.rmtree(temp_video_clips_dir)
|
| 201 |
+
shutil.rmtree(temp_latent_dir)
|
| 202 |
+
except OSError as e:
|
| 203 |
+
logger.warning(f"Não foi possível remover diretórios temporários: {e}")
|
| 204 |
+
|
| 205 |
logger.info(f"Processo completo! Vídeo original salvo em: {final_video_path}")
|
| 206 |
|
| 207 |
# 3. Empacota os resultados para o Orchestrator
|
|
|
|
| 217 |
"latent_paths": latent_fragment_paths,
|
| 218 |
"video_data": final_video_data_for_state
|
| 219 |
}
|
| 220 |
+
|
|
|
|
| 221 |
def save_video_from_tensor(self, video_tensor: torch.Tensor, path: str, fps: int = 24):
|
| 222 |
if video_tensor is None or video_tensor.ndim != 5 or video_tensor.shape[2] == 0: return
|
| 223 |
video_tensor = video_tensor.squeeze(0).permute(1, 2, 3, 0)
|