Update deformes4D_engine.py
Browse files- deformes4D_engine.py +7 -26
deformes4D_engine.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
-
# Version: 2.0.
|
| 6 |
#
|
| 7 |
# This file contains the Deformes4D Engine, which acts as the primary "Editor" or
|
| 8 |
# "Film Crew" specialist within the ADUC-SDR architecture. It implements the Camera (Ψ)
|
|
@@ -24,6 +24,7 @@ import subprocess
|
|
| 24 |
import gc
|
| 25 |
import shutil
|
| 26 |
from pathlib import Path
|
|
|
|
| 27 |
|
| 28 |
from ltx_manager_helpers import ltx_manager_singleton
|
| 29 |
from gemini_helpers import gemini_singleton
|
|
@@ -31,6 +32,7 @@ from latent_enhancer_specialist import latent_enhancer_specialist_singleton
|
|
| 31 |
from hd_specialist import hd_specialist_singleton
|
| 32 |
from ltx_video.models.autoencoders.vae_encode import vae_encode, vae_decode
|
| 33 |
from audio_specialist import audio_specialist_singleton
|
|
|
|
| 34 |
|
| 35 |
logger = logging.getLogger(__name__)
|
| 36 |
|
|
@@ -100,27 +102,6 @@ class Deformes4DEngine:
|
|
| 100 |
tensor = (tensor * 2.0) - 1.0
|
| 101 |
return self.pixels_to_latents(tensor)
|
| 102 |
|
| 103 |
-
def concatenate_videos_ffmpeg(self, video_paths: list[str], output_path: str):
|
| 104 |
-
"""Concatenates multiple video clips into a single file using FFmpeg."""
|
| 105 |
-
if not video_paths: raise gr.Error("No video fragments to assemble.")
|
| 106 |
-
list_file_path = os.path.join(self.workspace_dir, "concat_list.txt")
|
| 107 |
-
with open(list_file_path, 'w', encoding='utf-8') as f:
|
| 108 |
-
for path in video_paths: f.write(f"file '{os.path.abspath(path)}'\n")
|
| 109 |
-
|
| 110 |
-
cmd_list = ['ffmpeg', '-y', '-hwaccel', 'auto', '-f', 'concat', '-safe', '0', '-i', list_file_path, '-c', 'copy', output_path]
|
| 111 |
-
logger.info(f"Concatenating {len(video_paths)} video clips into {output_path}...")
|
| 112 |
-
try:
|
| 113 |
-
subprocess.run(cmd_list, check=True, capture_output=True, text=True)
|
| 114 |
-
except subprocess.CalledProcessError as e:
|
| 115 |
-
logger.error(f"FFmpeg error: {e.stderr}")
|
| 116 |
-
logger.info("Attempting concatenation again without hardware acceleration...")
|
| 117 |
-
cmd_list = ['ffmpeg', '-y', '-f', 'concat', '-safe', '0', '-i', list_file_path, '-c', 'copy', output_path]
|
| 118 |
-
try:
|
| 119 |
-
subprocess.run(cmd_list, check=True, capture_output=True, text=True)
|
| 120 |
-
except subprocess.CalledProcessError as e_fallback:
|
| 121 |
-
logger.error(f"FFmpeg error (fallback): {e_fallback.stderr}")
|
| 122 |
-
raise gr.Error(f"Failed to assemble the final video. Details: {e_fallback.stderr}")
|
| 123 |
-
|
| 124 |
# --- CORE ADUC-SDR LOGIC ---
|
| 125 |
|
| 126 |
def generate_original_movie(self, keyframes: list, global_prompt: str, storyboard: list,
|
|
@@ -222,7 +203,7 @@ class Deformes4DEngine:
|
|
| 222 |
|
| 223 |
progress(0.98, desc="Final assembly of clips...")
|
| 224 |
final_video_path = os.path.join(self.workspace_dir, f"original_movie_{run_timestamp}.mp4")
|
| 225 |
-
|
| 226 |
logger.info("Cleaning up temporary clip files...")
|
| 227 |
try:
|
| 228 |
shutil.rmtree(temp_video_clips_dir)
|
|
@@ -263,12 +244,10 @@ class Deformes4DEngine:
|
|
| 263 |
logger.info(f"Saved upscaled clip: {Path(current_clip_path).name}")
|
| 264 |
progress(0.98, desc="Assembling upscaled clips...")
|
| 265 |
final_video_path = os.path.join(self.workspace_dir, f"upscaled_movie_{run_timestamp}.mp4")
|
| 266 |
-
|
| 267 |
logger.info("Cleaning up temporary upscaled clip files...")
|
| 268 |
try:
|
| 269 |
shutil.rmtree(temp_upscaled_clips_dir)
|
| 270 |
-
concat_list_path = os.path.join(self.workspace_dir, "concat_list.txt")
|
| 271 |
-
if os.path.exists(concat_list_path): os.remove(concat_list_path)
|
| 272 |
except OSError as e:
|
| 273 |
logger.warning(f"Could not remove temporary upscaled clip directory: {e}")
|
| 274 |
logger.info(f"Latent upscaling complete! Final video at: {final_video_path}")
|
|
@@ -320,10 +299,12 @@ class Deformes4DEngine:
|
|
| 320 |
raise gr.Error(f"Audio generation failed. Details: {e}")
|
| 321 |
|
| 322 |
def _generate_latent_tensor_internal(self, conditioning_items, ltx_params, target_resolution, total_frames_to_generate):
|
|
|
|
| 323 |
final_ltx_params = {**ltx_params, 'width': target_resolution[0], 'height': target_resolution[1], 'video_total_frames': total_frames_to_generate, 'video_fps': 24, 'current_fragment_index': int(time.time()), 'conditioning_items_data': conditioning_items}
|
| 324 |
return self.ltx_manager.generate_latent_fragment(**final_ltx_params)
|
| 325 |
|
| 326 |
def _quantize_to_multiple(self, n, m):
|
|
|
|
| 327 |
if m == 0: return n
|
| 328 |
quantized = int(round(n / m) * m)
|
| 329 |
return m if n > 0 and quantized == 0 else quantized
|
|
|
|
| 2 |
#
|
| 3 |
# Copyright (C) August 4, 2025 Carlos Rodrigues dos Santos
|
| 4 |
#
|
| 5 |
+
# Version: 2.0.2
|
| 6 |
#
|
| 7 |
# This file contains the Deformes4D Engine, which acts as the primary "Editor" or
|
| 8 |
# "Film Crew" specialist within the ADUC-SDR architecture. It implements the Camera (Ψ)
|
|
|
|
| 24 |
import gc
|
| 25 |
import shutil
|
| 26 |
from pathlib import Path
|
| 27 |
+
from typing import List, Tuple, Generator, Dict, Any, Optional
|
| 28 |
|
| 29 |
from ltx_manager_helpers import ltx_manager_singleton
|
| 30 |
from gemini_helpers import gemini_singleton
|
|
|
|
| 32 |
from hd_specialist import hd_specialist_singleton
|
| 33 |
from ltx_video.models.autoencoders.vae_encode import vae_encode, vae_decode
|
| 34 |
from audio_specialist import audio_specialist_singleton
|
| 35 |
+
from tools.video_encode_tool import video_encode_tool_singleton
|
| 36 |
|
| 37 |
logger = logging.getLogger(__name__)
|
| 38 |
|
|
|
|
| 102 |
tensor = (tensor * 2.0) - 1.0
|
| 103 |
return self.pixels_to_latents(tensor)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# --- CORE ADUC-SDR LOGIC ---
|
| 106 |
|
| 107 |
def generate_original_movie(self, keyframes: list, global_prompt: str, storyboard: list,
|
|
|
|
| 203 |
|
| 204 |
progress(0.98, desc="Final assembly of clips...")
|
| 205 |
final_video_path = os.path.join(self.workspace_dir, f"original_movie_{run_timestamp}.mp4")
|
| 206 |
+
video_encode_tool_singleton.concatenate_videos(video_paths=final_video_clip_paths, output_path=final_video_path, workspace_dir=self.workspace_dir)
|
| 207 |
logger.info("Cleaning up temporary clip files...")
|
| 208 |
try:
|
| 209 |
shutil.rmtree(temp_video_clips_dir)
|
|
|
|
| 244 |
logger.info(f"Saved upscaled clip: {Path(current_clip_path).name}")
|
| 245 |
progress(0.98, desc="Assembling upscaled clips...")
|
| 246 |
final_video_path = os.path.join(self.workspace_dir, f"upscaled_movie_{run_timestamp}.mp4")
|
| 247 |
+
video_encode_tool_singleton.concatenate_videos(video_paths=final_upscaled_clip_paths, output_path=final_video_path, workspace_dir=self.workspace_dir)
|
| 248 |
logger.info("Cleaning up temporary upscaled clip files...")
|
| 249 |
try:
|
| 250 |
shutil.rmtree(temp_upscaled_clips_dir)
|
|
|
|
|
|
|
| 251 |
except OSError as e:
|
| 252 |
logger.warning(f"Could not remove temporary upscaled clip directory: {e}")
|
| 253 |
logger.info(f"Latent upscaling complete! Final video at: {final_video_path}")
|
|
|
|
| 299 |
raise gr.Error(f"Audio generation failed. Details: {e}")
|
| 300 |
|
| 301 |
def _generate_latent_tensor_internal(self, conditioning_items, ltx_params, target_resolution, total_frames_to_generate):
|
| 302 |
+
"""Internal helper to call the LTX manager."""
|
| 303 |
final_ltx_params = {**ltx_params, 'width': target_resolution[0], 'height': target_resolution[1], 'video_total_frames': total_frames_to_generate, 'video_fps': 24, 'current_fragment_index': int(time.time()), 'conditioning_items_data': conditioning_items}
|
| 304 |
return self.ltx_manager.generate_latent_fragment(**final_ltx_params)
|
| 305 |
|
| 306 |
def _quantize_to_multiple(self, n, m):
|
| 307 |
+
"""Helper to round n to the nearest multiple of m."""
|
| 308 |
if m == 0: return n
|
| 309 |
quantized = int(round(n / m) * m)
|
| 310 |
return m if n > 0 and quantized == 0 else quantized
|