euiia commited on
Commit
8cc88ac
·
verified ·
1 Parent(s): 9b750c3

Update deformes4D_engine.py

Browse files
Files changed (1) hide show
  1. deformes4D_engine.py +50 -0
deformes4D_engine.py CHANGED
@@ -250,7 +250,57 @@ class Deformes4DEngine:
250
  new_full_latents = self._generate_latent_tensor_internal(conditioning_items, current_ltx_params, target_resolution_tuple, total_frames_to_generate)
251
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
 
256
 
 
250
  new_full_latents = self._generate_latent_tensor_internal(conditioning_items, current_ltx_params, target_resolution_tuple, total_frames_to_generate)
251
 
252
 
253
+
254
+ # --- CÓDIGO ADICIONADO PARA ITERAR E CONTAR FRAMES ---
255
+ logger.info("Iniciando a contagem de frames para cada tensor latente individual.")
256
+ total_frames_from_latents = 0
257
+ for i in range(new_full_latents.shape[2]):
258
+ single_latent_tensor = new_full_latents[:, :, i:i+1, :, :]
259
+ temp_video_path = os.path.join(self.workspace_dir, f"temp_latent_video_{i}.mp4")
260
+
261
+ # Gerar um vídeo temporário para o tensor latente individual
262
+ pixel_tensor_single = self.latents_to_pixels(single_latent_tensor)
263
+ self.save_video_from_tensor(pixel_tensor_single, temp_video_path, fps=24)
264
+ del pixel_tensor_single
265
+ gc.collect()
266
 
267
+ # Contar os frames do vídeo temporário com ffprobe
268
+ try:
269
+ frame_count_result = subprocess.run(
270
+ ["ffprobe", "-v", "error", "-select_streams", "v:0", "-count_frames", "-show_entries", "stream=nb_read_frames", "-of", "default=noprint_wrappers=1:nokey=1", temp_video_path],
271
+ capture_output=True, text=True, check=True
272
+ )
273
+ frames = int(frame_count_result.stdout.strip())
274
+ logger.info(f"Latente {i}: Vídeo temporário gerado com {frames} frames.")
275
+ total_frames_from_latents += frames
276
+ except (subprocess.CalledProcessError, ValueError, FileNotFoundError) as e:
277
+ logger.error(f"Falha ao contar frames para o latente {i} com ffprobe: {e}")
278
+ finally:
279
+ if os.path.exists(temp_video_path):
280
+ os.remove(temp_video_path)
281
+
282
+ logger.info(f"Contagem total de frames a partir dos latentes individuais: {total_frames_from_latents}")
283
+
284
+ # Gerar e contar frames para o vídeo completo a partir do tensor latente inteiro
285
+ full_latent_video_path = os.path.join(self.workspace_dir, "temp_full_latent_video.mp4")
286
+ full_pixel_tensor = self.latents_to_pixels(new_full_latents)
287
+ self.save_video_from_tensor(full_pixel_tensor, full_latent_video_path, fps=24)
288
+ del full_pixel_tensor
289
+ gc.collect()
290
+
291
+ try:
292
+ full_frame_count_result = subprocess.run(
293
+ ["ffprobe", "-v", "error", "-select_streams", "v:0", "-count_frames", "-show_entries", "stream=nb_read_frames", "-of", "default=noprint_wrappers=1:nokey=1", full_latent_video_path],
294
+ capture_output=True, text=True, check=True
295
+ )
296
+ total_frames_full_video = int(full_frame_count_result.stdout.strip())
297
+ logger.info(f"Vídeo completo gerado a partir do tensor latente inteiro possui {total_frames_full_video} frames.")
298
+ except (subprocess.CalledProcessError, ValueError, FileNotFoundError) as e:
299
+ logger.error(f"Falha ao contar frames do vídeo completo com ffprobe: {e}")
300
+ finally:
301
+ if os.path.exists(full_latent_video_path):
302
+ os.remove(full_latent_video_path)
303
+ # --- FIM DO CÓDIGO ADICIONADO ---```
304
 
305
 
306