euiia commited on
Commit
d2de905
·
verified ·
1 Parent(s): b9d7aca

Update deformes4D_engine.py

Browse files
Files changed (1) hide show
  1. deformes4D_engine.py +48 -19
deformes4D_engine.py CHANGED
@@ -103,9 +103,22 @@ class Deformes4DEngine:
103
  DESTINATION_FRAME_TARGET = total_frames_brutos - 1
104
 
105
  base_ltx_params = {"guidance_scale": 2.0, "stg_scale": 0.025, "rescaling_scale": 0.15, "num_inference_steps": 20}
106
- keyframe_paths = [item if isinstance(item, str) else item.name for item in keyframes]
107
- story_history = ""
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  eco_latent_for_next_loop = None
110
  dejavu_latent_for_next_loop = None
111
  raw_latent_fragments = []
@@ -154,17 +167,9 @@ class Deformes4DEngine:
154
  if transition_type == "cut":
155
  eco_latent_for_next_loop, dejavu_latent_for_next_loop = None, None
156
 
157
- if use_upscaler:
158
- logger.info(f"fragmento {i+1} original: {latents_video.shape}")
159
- latents_video = self.upscale_latents(latents_video)
160
- logger.info(f"fragmento {i+1} upscaler: {latents_video.shape}")
161
-
162
- else:
163
- logger.info("Etapa de upscaler desativada.")
164
-
165
- logger.info(f"fragmento {i+1} adinado a lista global")
166
  raw_latent_fragments.append(latents_video)
167
 
 
168
  current_step += 1
169
  progress(current_step / TOTAL_STEPS, desc="Unificação Causal (Concatenação)...")
170
  tensors_on_main_device = [frag.to(self.device) for frag in raw_latent_fragments]
@@ -183,15 +188,37 @@ class Deformes4DEngine:
183
  else:
184
  logger.info("Etapa de refinamento desativada.")
185
 
186
- if use_audio:
187
- logger.warning("Geração de áudio solicitada, mas está desativada nesta versão do código.")
188
- else:
189
- logger.info("Etapa de sonoplastia desativada.")
 
 
 
 
 
190
 
191
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  final_video_path = os.path.join(self.workspace_dir, f"{base_name}_FINAL.mp4")
193
- final_pixel_tensor = self.latents_to_pixels(final_concatenated_latents)
194
- self.save_video_from_tensor(processed_latents, final_video_path, fps=24)
195
 
196
  if use_hd:
197
  current_step += 1
@@ -209,7 +236,9 @@ class Deformes4DEngine:
209
  logger.info("Etapa de masterização HD desativada.")
210
  os.rename(intermediate_video_path, final_video_path)
211
 
212
-
 
 
213
  logger.info(f"Processo concluído! Vídeo final salvo em: {final_video_path}")
214
  yield {"final_path": final_video_path}
215
 
 
103
  DESTINATION_FRAME_TARGET = total_frames_brutos - 1
104
 
105
  base_ltx_params = {"guidance_scale": 2.0, "stg_scale": 0.025, "rescaling_scale": 0.15, "num_inference_steps": 20}
 
 
106
 
107
+ # --- [INÍCIO DA CORREÇÃO] ---
108
+ # Lógica robusta para extrair caminhos de arquivo da lista de keyframes.
109
+ keyframe_paths = []
110
+ for item in keyframes:
111
+ if isinstance(item, str):
112
+ keyframe_paths.append(item)
113
+ elif isinstance(item, tuple) and len(item) > 0:
114
+ keyframe_paths.append(item[0]) # Assume que o caminho está no primeiro elemento da tupla
115
+ elif hasattr(item, 'name'):
116
+ keyframe_paths.append(item.name)
117
+ else:
118
+ logger.warning(f"Item na lista de keyframes com tipo inesperado e sem atributo '.name': {type(item)}")
119
+ # --- [FIM DA CORREÇÃO] ---
120
+
121
+ story_history = ""
122
  eco_latent_for_next_loop = None
123
  dejavu_latent_for_next_loop = None
124
  raw_latent_fragments = []
 
167
  if transition_type == "cut":
168
  eco_latent_for_next_loop, dejavu_latent_for_next_loop = None, None
169
 
 
 
 
 
 
 
 
 
 
170
  raw_latent_fragments.append(latents_video)
171
 
172
+ # --- ATO II: PÓS-PRODUÇÃO LATENTE GLOBAL (CONDICIONAL) ---
173
  current_step += 1
174
  progress(current_step / TOTAL_STEPS, desc="Unificação Causal (Concatenação)...")
175
  tensors_on_main_device = [frag.to(self.device) for frag in raw_latent_fragments]
 
188
  else:
189
  logger.info("Etapa de refinamento desativada.")
190
 
191
+ # --- ATO III: RENDERIZAÇÃO E FINALIZAÇÃO ---
192
+ base_name = f"movie_{int(time.time())}"
193
+ current_step += 1
194
+ progress(current_step / TOTAL_STEPS, desc="Renderização (em lotes)...")
195
+ intermediate_video_path = os.path.join(self.workspace_dir, f"{base_name}_intermediate.mp4")
196
+
197
+ with imageio.get_writer(intermediate_video_path, fps=FPS, codec='libx264', quality=8, output_params=['-pix_fmt', 'yuv420p']) as writer:
198
+ chunk_size = 15 if use_upscaler else 30
199
+ latent_chunks = torch.split(processed_latents, chunk_size, dim=2)
200
 
201
+ for i, latent_chunk in enumerate(latent_chunks):
202
+ logger.info(f"Processando e renderizando lote {i+1}/{len(latent_chunks)}...")
203
+
204
+ processed_chunk = self.upscale_latents(latent_chunk) if use_upscaler else latent_chunk
205
+ pixel_tensor_chunk = self.latents_to_pixels(processed_chunk)
206
+
207
+ pixel_tensor_chunk = pixel_tensor_chunk.squeeze(0).permute(1, 2, 3, 0)
208
+ pixel_tensor_chunk = (pixel_tensor_chunk.clamp(-1, 1) + 1) / 2.0
209
+ video_np_chunk = (pixel_tensor_chunk.detach().cpu().float().numpy() * 255).astype(np.uint8)
210
+
211
+ for frame in video_np_chunk:
212
+ writer.append_data(frame)
213
+
214
+ del latent_chunk, processed_chunk, pixel_tensor_chunk, video_np_chunk
215
+ gc.collect()
216
+ torch.cuda.empty_cache()
217
+
218
+ del processed_latents; gc.collect(); torch.cuda.empty_cache()
219
+ logger.info(f"Vídeo intermediário renderizado em: {intermediate_video_path}")
220
+
221
  final_video_path = os.path.join(self.workspace_dir, f"{base_name}_FINAL.mp4")
 
 
222
 
223
  if use_hd:
224
  current_step += 1
 
236
  logger.info("Etapa de masterização HD desativada.")
237
  os.rename(intermediate_video_path, final_video_path)
238
 
239
+ if use_audio:
240
+ logger.warning("Geração de áudio solicitada, mas está desativada nesta versão do código.")
241
+
242
  logger.info(f"Processo concluído! Vídeo final salvo em: {final_video_path}")
243
  yield {"final_path": final_video_path}
244