Spaces:
Build error
Build error
Update renderer.py
Browse files- renderer.py +11 -9
renderer.py
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
import tempfile
|
| 3 |
import subprocess
|
| 4 |
import numpy as np
|
| 5 |
from PIL import Image, ImageDraw
|
| 6 |
-
|
| 7 |
-
from effects
|
| 8 |
-
from effects
|
| 9 |
-
from effects
|
|
|
|
| 10 |
|
| 11 |
class VideoRenderer:
|
| 12 |
def __init__(self, width, height, fps, base_texture, audio_features, user_settings):
|
|
@@ -16,26 +18,26 @@ class VideoRenderer:
|
|
| 16 |
self.base_texture = base_texture.resize((width, height), Image.LANCZOS)
|
| 17 |
self.audio_features = audio_features
|
| 18 |
self.settings = user_settings
|
| 19 |
-
|
| 20 |
self.effects = []
|
| 21 |
if self.settings['enable_particles']: self.effects.append(ParticleEffect(width, height))
|
| 22 |
if self.settings['enable_spectrum']: self.effects.append(SpectrumEffect(width, height))
|
| 23 |
text = f"{self.settings.get('artist', '')} - {self.settings.get('title', '')}".strip(" -")
|
| 24 |
if text: self.effects.append(ScrollingTextEffect(text, width, height))
|
| 25 |
-
|
| 26 |
self.camera_effect = AICameraEffect(width, height) if self.settings['enable_camera_effect'] else None
|
| 27 |
|
| 28 |
def render(self, audio_path):
|
| 29 |
duration = min(self.settings['duration'], self.audio_features['duration'])
|
| 30 |
total_frames = int(duration * self.fps)
|
| 31 |
-
|
| 32 |
video_path = tempfile.mktemp(suffix=".mp4")
|
| 33 |
out = cv2.VideoWriter(video_path, cv2.VideoWriter_fourcc(*'mp4v'), self.fps, (self.width, self.height))
|
| 34 |
|
| 35 |
for i in range(total_frames):
|
| 36 |
current_time = i / self.fps
|
| 37 |
frame = self.base_texture.copy().convert("RGBA")
|
| 38 |
-
|
| 39 |
if self.camera_effect:
|
| 40 |
frame = self.camera_effect.draw(frame, current_time, self.audio_features)
|
| 41 |
|
|
@@ -49,7 +51,7 @@ class VideoRenderer:
|
|
| 49 |
|
| 50 |
out.release()
|
| 51 |
print("Рендеринг видео завершен. Добавление аудио...")
|
| 52 |
-
|
| 53 |
final_video_path = self.mux_audio_video(video_path, audio_path, duration)
|
| 54 |
return final_video_path
|
| 55 |
|
|
|
|
| 1 |
+
# renderer.py
|
| 2 |
import cv2
|
| 3 |
import tempfile
|
| 4 |
import subprocess
|
| 5 |
import numpy as np
|
| 6 |
from PIL import Image, ImageDraw
|
| 7 |
+
# ИСПРАВЛЕНО: Заменены слэши на точки и убрана папка visualizer
|
| 8 |
+
from effects.particles import ParticleEffect
|
| 9 |
+
from effects.text import ScrollingTextEffect
|
| 10 |
+
from effects.spectrum import SpectrumEffect
|
| 11 |
+
from effects.camera import AICameraEffect
|
| 12 |
|
| 13 |
class VideoRenderer:
|
| 14 |
def __init__(self, width, height, fps, base_texture, audio_features, user_settings):
|
|
|
|
| 18 |
self.base_texture = base_texture.resize((width, height), Image.LANCZOS)
|
| 19 |
self.audio_features = audio_features
|
| 20 |
self.settings = user_settings
|
| 21 |
+
|
| 22 |
self.effects = []
|
| 23 |
if self.settings['enable_particles']: self.effects.append(ParticleEffect(width, height))
|
| 24 |
if self.settings['enable_spectrum']: self.effects.append(SpectrumEffect(width, height))
|
| 25 |
text = f"{self.settings.get('artist', '')} - {self.settings.get('title', '')}".strip(" -")
|
| 26 |
if text: self.effects.append(ScrollingTextEffect(text, width, height))
|
| 27 |
+
|
| 28 |
self.camera_effect = AICameraEffect(width, height) if self.settings['enable_camera_effect'] else None
|
| 29 |
|
| 30 |
def render(self, audio_path):
|
| 31 |
duration = min(self.settings['duration'], self.audio_features['duration'])
|
| 32 |
total_frames = int(duration * self.fps)
|
| 33 |
+
|
| 34 |
video_path = tempfile.mktemp(suffix=".mp4")
|
| 35 |
out = cv2.VideoWriter(video_path, cv2.VideoWriter_fourcc(*'mp4v'), self.fps, (self.width, self.height))
|
| 36 |
|
| 37 |
for i in range(total_frames):
|
| 38 |
current_time = i / self.fps
|
| 39 |
frame = self.base_texture.copy().convert("RGBA")
|
| 40 |
+
|
| 41 |
if self.camera_effect:
|
| 42 |
frame = self.camera_effect.draw(frame, current_time, self.audio_features)
|
| 43 |
|
|
|
|
| 51 |
|
| 52 |
out.release()
|
| 53 |
print("Рендеринг видео завершен. Добавление аудио...")
|
| 54 |
+
|
| 55 |
final_video_path = self.mux_audio_video(video_path, audio_path, duration)
|
| 56 |
return final_video_path
|
| 57 |
|