euiia commited on
Commit
21b2ae3
·
verified ·
1 Parent(s): 612828a

Update deformes4D_engine.py

Browse files
Files changed (1) hide show
  1. deformes4D_engine.py +25 -51
deformes4D_engine.py CHANGED
@@ -190,62 +190,36 @@ class Deformes4DEngine:
190
  del tensors_para_concatenar; gc.collect(); torch.cuda.empty_cache()
191
 
192
  logger.info(f"Concatenação concluída. Shape do super-latente: {processed_latents.shape}")
193
-
194
- if use_refiner:
195
- progress(0.8, desc="Refinando continuidade visual...")
196
- # [REATORADO] Chamada para o novo especialista
197
- processed_latents = latent_enhancer_specialist_singleton.refine(processed_latents, **refine_ltx_params)
198
-
199
- logger.info("--- DIVIDINDO SUPER-LATENTE E PROCESSANDO FRAGMENTOS INDIVIDUALMENTE ---")
200
-
201
- adjusted_lengths = [l - 1 if i < len(latent_fragment_lengths) - 1 else l for i, l in enumerate(latent_fragment_lengths)]
202
-
203
- refined_fragments = torch.split(processed_latents, adjusted_lengths, dim=2)
204
- del processed_latents; gc.collect(); torch.cuda.empty_cache()
205
-
206
- final_video_paths = []
207
- num_final_fragments = len(refined_fragments)
208
-
209
- for i, fragment_latent in enumerate(refined_fragments):
210
- progress(0.85 + (0.1 * (i / num_final_fragments)), desc=f"Finalizando Clipe {i+1}/{num_final_fragments}")
211
-
212
- base_name = f"fragment_{i}_{int(time.time())}"
213
- current_path = os.path.join(self.workspace_dir, f"{base_name}_temp.mp4")
214
 
215
- if use_audio:
216
- current_path = self._generate_video_and_audio_from_latents(fragment_latent, global_prompt, base_name)
217
- else:
218
- pixel_tensor = self.latents_to_pixels(fragment_latent)
219
- self.save_video_from_tensor(pixel_tensor, current_path, fps=24)
220
- del pixel_tensor
221
-
222
- gc.collect(); torch.cuda.empty_cache()
223
 
224
- if use_hd:
225
- hd_output_path = os.path.join(self.workspace_dir, f"{base_name}_hd.mp4")
226
- try:
227
- hd_specialist_singleton.process_video(input_video_path=current_path, output_video_path=hd_output_path, prompt=" ")
228
- os.remove(current_path)
229
- final_video_paths.append(hd_output_path)
230
- except Exception as e:
231
- logger.error(f"Falha na masterização HD do fragmento {i+1}: {e}. Usando versão padrão.")
232
- os.rename(current_path, hd_output_path)
233
- final_video_paths.append(hd_output_path)
234
- else:
235
- final_video_paths.append(current_path)
236
 
237
- del refined_fragments; gc.collect(); torch.cuda.empty_cache()
238
-
239
- progress(0.98, desc="Montagem final...")
240
- final_movie_path = os.path.join(self.workspace_dir, f"movie_{int(time.time())}_FINAL.mp4")
241
- self.concatenate_videos_ffmpeg(final_video_paths, final_movie_path)
 
 
 
 
 
 
242
 
243
- for path in final_video_paths:
244
- if os.path.exists(path):
245
- os.remove(path)
246
 
247
- logger.info(f"Processo concluído! Vídeo final salvo em: {final_movie_path}")
248
- yield {"final_path": final_movie_path}
 
 
249
 
250
  def _generate_video_and_audio_from_latents(self, latent_tensor, audio_prompt, base_name):
251
  silent_video_path = os.path.join(self.workspace_dir, f"{base_name}_silent_for_audio.mp4")
 
190
  del tensors_para_concatenar; gc.collect(); torch.cuda.empty_cache()
191
 
192
  logger.info(f"Concatenação concluída. Shape do super-latente: {processed_latents.shape}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
+ base_name = f"fragment_{i}_{int(time.time())}"
195
+ current_path = os.path.join(self.workspace_dir, f"{base_name}_temp.mp4")
 
 
 
 
 
 
196
 
197
+ if use_audio:
198
+ current_path = self._generate_video_and_audio_from_latents(processed_latents, " ", base_name)
199
+ else:
200
+ current_path = self.latents_to_pixels(processed_latents)
201
+ self.save_video_from_tensor(pixel_tensor, current_path, fps=24)
202
+ del pixel_tensor
203
+
 
 
 
 
 
204
 
205
+ if use_hd:
206
+ current_path = os.path.join(self.workspace_dir, f"{base_name}_hd.mp4")
207
+ try:
208
+ hd_specialist_singleton.process_video(input_video_path=current_path, output_video_path=current_path, prompt=" ")
209
+ except Exception as e:
210
+ logger.error(f"Falha na masterização HD do fragmento {i+1}: {e}. Usando versão padrão.")
211
+
212
+ #if use_refiner:
213
+ # progress(0.8, desc="Refinando continuidade visual...")
214
+ # # [REATORADO] Chamada para o novo especialista
215
+ #
216
 
217
+
 
 
218
 
219
+ progress(0.98, desc="Montagem final...")
220
+
221
+ logger.info(f"Processo concluído! Vídeo final salvo em: {current_path}")
222
+ yield {"final_path": current_path}
223
 
224
  def _generate_video_and_audio_from_latents(self, latent_tensor, audio_prompt, base_name):
225
  silent_video_path = os.path.join(self.workspace_dir, f"{base_name}_silent_for_audio.mp4")