Video-Gen / modules /video_processor.py
jacky3102's picture
Create modules/video_processor.py
ae4df5d verified
Raw
History Blame Contribute Delete
2.59 kB
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