Spaces:
Running
Running
| import cv2 | |
| import numpy as np | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| from pydub import AudioSegment | |
| from modules.lut import apply_lut | |
| from modules.particles import Particle, apply_effect | |
| from modules.effects import apply_old_film, apply_heat_haze, apply_flame | |
| from modules.subtitles import draw_subtitle, draw_typewriter_subtitle | |
| from modules.titles import draw_title | |
| from modules.utils import get_chinese_font, fit_image_to_canvas, ken_burns_crop, apply_cinemascope | |
| from modules.audio_processor import process_audio | |
| def generate_video( | |
| image_paths: List[str] = None, | |
| video_path: str = None, | |
| audio_path: str = None, | |
| srt_text: str = "", | |
| bgm_path: Optional[str] = None, | |
| effect: str = "none", | |
| output_path: str = "", | |
| lut: str = "none", | |
| ken_burns: bool = False, | |
| typewriter: bool = False, | |
| cinemascope: bool = False, | |
| title_text: str = "", | |
| title_style: str = "3d", | |
| title_color: str = "white", | |
| title_animation: str = "fade_in", | |
| title_duration: float = 4.0, | |
| title_position: str = "center", | |
| title_start: float = 0.0, | |
| title_font_size: int = 0, | |
| typewriter_font_size: int = 0, | |
| typewriter_color: str = "white", | |
| subtitle_color: str = "white", | |
| subtitle_effect: str = "none", | |
| fps: int = 25, | |
| ): | |
| # θ§£ζεεΉ | |
| subtitle_segments = parse_srt(srt_text) if srt_text else [] | |
| # ε θ½½ι³ι’ | |
| audio = AudioSegment.from_file(audio_path) | |
| total_duration = len(audio) / 1000.0 | |
| total_frames = int(total_duration * fps) | |
| # ε€ηθΎε ₯ζΊοΌεΎηζθ§ι’οΌ | |
| # ... (ε€η¨εζ₯ηε€ηι»θΎ) | |
| # θ·εεδ½ | |
| font_path = get_chinese_font() | |
| # εε ₯εΈ§... | |
| for frame_idx in range(total_frames): | |
| # ... (εζηεΈ§ε€ηι»θΎ) | |
| # εΊη¨εεΉ | |
| if current_sub: | |
| if typewriter and seg_end > seg_start: | |
| # ... (ζεζΊι»θΎ) | |
| frame = draw_typewriter_subtitle(frame, current_sub, visible, font_path, out_w, out_h, | |
| typewriter_font_size, typewriter_color, | |
| subtitle_effect, frame_idx, fps) | |
| else: | |
| frame = draw_subtitle(frame, current_sub, font_path, out_w, out_h, | |
| typewriter_font_size, subtitle_color, | |
| subtitle_effect, frame_idx, fps) | |
| out.write(frame) | |
| # ι³ι’ε€ηεεζ | |
| # ... (εζηι³ι’ε€η) | |
| return output_path |