Spaces:
Running
Running
File size: 2,592 Bytes
ae4df5d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | 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 |