euiia commited on
Commit
550bb82
·
verified ·
1 Parent(s): 98b590e

Update deformes4D_engine.py

Browse files
Files changed (1) hide show
  1. deformes4D_engine.py +8 -62
deformes4D_engine.py CHANGED
@@ -126,55 +126,7 @@ class Deformes4DEngine:
126
  raise gr.Error(f"Falha na montagem final do vídeo. Detalhes: {e.stderr}")
127
  return output_path
128
 
129
- # --- PIPELINE DE PÓS-PRODUÇÃO LATENTE ---
130
- def _render_and_post_process_latents(self,
131
- low_res_latents: torch.Tensor,
132
- base_name: str,
133
- motion_prompt_for_refine: str,
134
- final_resolution: tuple
135
- ) -> str:
136
- logger.info(f"--- INICIANDO PIPELINE DE PÓS-PRODUÇÃO PARA '{base_name}' ---")
137
-
138
- high_res_latents = upscaler_specialist_singleton.upscale(low_res_latents)
139
-
140
- _, _, _, refined_h_latent, refined_w_latent = high_res_latents.shape
141
- video_h = refined_h_latent * self.ltx_manager.workers[0].pipeline.vae_scale_factor
142
- video_w = refined_w_latent * self.ltx_manager.workers[0].pipeline.vae_scale_factor
143
- num_latent_frames = high_res_latents.shape[2]
144
- num_video_frames = num_latent_frames * self.ltx_manager.workers[0].pipeline.video_scale_factor
145
- if isinstance(self.vae, CausalVideoAutoencoder):
146
- num_video_frames -= 1
147
-
148
- refine_kwargs = {
149
- 'height': video_h, 'width': video_w, 'video_total_frames': num_video_frames, 'video_fps': 24,
150
- 'current_fragment_index': int(time.time()), 'motion_prompt': motion_prompt_for_refine,
151
- 'conditioning_items_data': [],
152
- 'denoise_strength': 0.4, 'refine_steps': 10
153
- }
154
-
155
- final_latents, _ = self.ltx_manager.refine_latents(high_res_latents, **refine_kwargs)
156
-
157
- untrimmed_video_path = os.path.join(self.workspace_dir, f"{base_name}_untrimmed.mp4")
158
- trimmed_video_path = os.path.join(self.workspace_dir, f"{base_name}.mp4")
159
-
160
- pixel_tensor = self.latents_to_pixels(final_latents)
161
-
162
- logger.info(f"Redimensionando vídeo final de {pixel_tensor.shape[-2:]} para {final_resolution}")
163
- pixel_tensor_resized = torch.nn.functional.interpolate(
164
- pixel_tensor.squeeze(0), size=final_resolution, mode='bilinear', align_corners=False
165
- ).unsqueeze(0)
166
-
167
- self.save_video_from_tensor(pixel_tensor_resized, untrimmed_video_path, fps=24)
168
- del pixel_tensor, final_latents, high_res_latents, pixel_tensor_resized
169
- gc.collect()
170
- torch.cuda.empty_cache()
171
-
172
- success = self._trim_last_frame_ffmpeg(untrimmed_video_path, trimmed_video_path)
173
-
174
- if os.path.exists(untrimmed_video_path):
175
- os.remove(untrimmed_video_path)
176
-
177
- return trimmed_video_path if success else untrimmed_video_path
178
 
179
  def _generate_video_and_audio(self, silent_video_path: str, audio_prompt: str, base_name: str) -> str:
180
  try:
@@ -283,21 +235,15 @@ class Deformes4DEngine:
283
 
284
  progress((num_transitions_to_generate + 1) / (num_transitions_to_generate + 2), desc="Pós-produção (Upscale e Refinamento)...")
285
  base_name = f"final_movie_hq_{int(time.time())}"
286
- silent_video_path = self._render_and_post_process_latents(
287
- low_res_latents=final_concatenated_latents,
288
- base_name=base_name,
289
- motion_prompt_for_refine=global_prompt,
290
- final_resolution=final_resolution_tuple
 
291
  )
292
-
293
- #progress((num_transitions_to_generate + 1.5) / (num_transitions_to_generate + 2), desc="Gerando paisagem sonora...")
294
- #video_with_audio_path = self._generate_video_and_audio(
295
- # silent_video_path=silent_video_path,
296
- # audio_prompt=global_prompt,
297
- # base_name=base_name
298
- #)
299
 
300
- yield {"final_path": silent_video_path}
301
 
302
  def _generate_latent_tensor_internal(self, conditioning_items, ltx_params, target_resolution, total_frames_to_generate):
303
  kwargs = {
 
126
  raise gr.Error(f"Falha na montagem final do vídeo. Detalhes: {e.stderr}")
127
  return output_path
128
 
129
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  def _generate_video_and_audio(self, silent_video_path: str, audio_prompt: str, base_name: str) -> str:
132
  try:
 
235
 
236
  progress((num_transitions_to_generate + 1) / (num_transitions_to_generate + 2), desc="Pós-produção (Upscale e Refinamento)...")
237
  base_name = f"final_movie_hq_{int(time.time())}"
238
+
239
+ progress((num_transitions_to_generate + 1.5) / (num_transitions_to_generate + 2), desc="Gerando paisagem sonora...")
240
+ video_with_audio_path = self._generate_video_and_audio(
241
+ silent_video_path=silent_video_path,
242
+ audio_prompt=global_prompt,
243
+ base_name=base_name
244
  )
 
 
 
 
 
 
 
245
 
246
+ yield {"final_path": video_with_audio_path}
247
 
248
  def _generate_latent_tensor_internal(self, conditioning_items, ltx_params, target_resolution, total_frames_to_generate):
249
  kwargs = {