feat(script): 添加帧间隔输入参数并更新相关逻辑

- 在 GenerateScriptRequest 和 ScriptGenerator 中新增 frame_interval_input 参数,默认为 5
- 更新 VideoProcessor 的 process_video_pipeline 方法,调整帧提取间隔逻辑
- 修改前端界面,增加帧间隔输入框并更新相关翻译文本
- 优化 generate_script_docu 函数,使用新的帧间隔参数进行视频处理
This commit is contained in:
linyq 2025-05-07 16:43:00 +08:00
parent f6c3f1640b
commit 82823297f2
7 changed files with 23 additions and 43 deletions

View File

@ -6,6 +6,7 @@ class GenerateScriptRequest(BaseModel):
video_path: str
video_theme: Optional[str] = ""
custom_prompt: Optional[str] = ""
frame_interval_input: Optional[int] = 5
skip_seconds: Optional[int] = 0
threshold: Optional[int] = 30
vision_batch_size: Optional[int] = 5

View File

@ -22,6 +22,7 @@ class ScriptGenerator:
video_path: str,
video_theme: str = "",
custom_prompt: str = "",
frame_interval_input: int = 5,
skip_seconds: int = 0,
threshold: int = 30,
vision_batch_size: int = 5,

View File

@ -292,10 +292,7 @@ class VideoProcessor:
def process_video_pipeline(self,
output_dir: str,
skip_seconds: float = 0.0,
threshold: int = 20, # 此参数保留但不使用
compressed_width: int = 320, # 此参数保留但不使用
keep_temp: bool = False, # 此参数保留但不使用
interval_seconds: float = 5.0,
interval_seconds: float = 5.0, # 帧提取间隔(秒)
use_hw_accel: bool = True) -> None:
"""
执行简化的视频处理流程直接从原视频按固定时间间隔提取帧
@ -303,9 +300,6 @@ class VideoProcessor:
Args:
output_dir: 输出目录
skip_seconds: 跳过视频开头的秒数
threshold: 保留参数不使用
compressed_width: 保留参数不使用
keep_temp: 保留参数不使用
interval_seconds: 帧提取间隔
use_hw_accel: 是否使用硬件加速
"""
@ -314,7 +308,7 @@ class VideoProcessor:
try:
# 直接从原视频提取关键帧
logger.info("从视频直接提取关键帧...")
logger.info(f"从视频间隔 {interval_seconds}提取关键帧...")
self.extract_frames_by_interval(
output_dir,
interval_seconds=interval_seconds,

View File

@ -47,7 +47,7 @@ def render_script_file(tr, params):
(tr("None"), ""),
(tr("Auto Generate"), "auto"),
(tr("Short Generate"), "short"),
(tr("Upload Script"), "upload_script") # 新增上传脚本选项
(tr("Upload Script"), "upload_script")
]
# 获取已有脚本文件
@ -214,38 +214,16 @@ def render_script_buttons(tr, params):
# 根据脚本类型显示不同的设置
if script_path != "short":
# 非短视频模式下显示原有的三个输入框
input_cols = st.columns(3)
input_cols = st.columns(2)
with input_cols[0]:
skip_seconds = st.number_input(
"skip_seconds",
st.number_input(
tr("Frame Interval (seconds)"),
min_value=0,
value=st.session_state.get('skip_seconds', config.frames.get('skip_seconds', 0)),
help=tr("Skip the first few seconds"),
key="skip_seconds_input"
value=st.session_state.get('frame_interval_input', config.frames.get('frame_interval_input', 5)),
help=tr("Frame Interval (seconds) (More keyframes consume more tokens)"),
key="frame_interval_input"
)
st.session_state['skip_seconds'] = skip_seconds
with input_cols[1]:
threshold = st.number_input(
"threshold",
min_value=0,
value=st.session_state.get('threshold', config.frames.get('threshold', 30)),
help=tr("Difference threshold"),
key="threshold_input"
)
st.session_state['threshold'] = threshold
with input_cols[2]:
vision_batch_size = st.number_input(
"vision_batch_size",
min_value=1,
max_value=20,
value=st.session_state.get('vision_batch_size', config.frames.get('vision_batch_size', 5)),
help=tr("Vision processing batch size"),
key="vision_batch_size_input"
)
st.session_state['vision_batch_size'] = vision_batch_size
# 生成/加载按钮
if script_path == "auto":
@ -259,7 +237,8 @@ def render_script_buttons(tr, params):
if st.button(button_name, key="script_action", disabled=not script_path):
if script_path == "auto":
generate_script_docu(tr, params)
# 执行纪录片视频脚本生成(视频无字幕无配音)
generate_script_docu(params)
elif script_path == "short":
# 获取自定义片段数量参数
custom_clips = st.session_state.get('custom_clips', 5)

View File

@ -85,6 +85,7 @@
"TTS Provider": "TTS Provider",
"Hide Log": "Hide Log",
"Upload Local Files": "Upload Local Files",
"File Uploaded Successfully": "File Uploaded Successfully"
"File Uploaded Successfully": "File Uploaded Successfully",
"Frame Interval (seconds)": "Frame Interval (seconds) (More keyframes consume more tokens)"
}
}

View File

@ -192,6 +192,8 @@
"Generate Short Video Script": "AI生成短剧混剪脚本",
"Adjust the volume of the original audio": "调整原始音频的音量",
"Original Volume": "视频音量",
"Auto Generate": "纪录片解说 (画面解说)"
"Auto Generate": "纪录片解说 (画面解说)",
"Frame Interval (seconds)": "帧间隔 (秒)",
"Frame Interval (seconds) (More keyframes consume more tokens)": "帧间隔 (秒) (更多关键帧消耗更多令牌)"
}
}

View File

@ -17,9 +17,11 @@ from app.utils import utils, video_processor, qwenvl_analyzer
from webui.tools.base import create_vision_analyzer, get_batch_files, get_batch_timestamps, chekc_video_config
def generate_script_docu(tr, params):
def generate_script_docu(params):
"""
生成 纪录片 视频脚本
要求: 原视频无字幕无配音
适合场景: 纪录片动物搞笑解说荒野建造等
"""
progress_bar = st.progress(0)
status_text = st.empty()
@ -69,8 +71,7 @@ def generate_script_docu(tr, params):
# 处理视频并提取关键帧
processor.process_video_pipeline(
output_dir=video_keyframes_dir,
skip_seconds=st.session_state.get('skip_seconds'),
threshold=st.session_state.get('threshold')
interval_seconds=st.session_state.get('frame_interval_input'),
)
# 获取所有关键文件路径
@ -194,6 +195,7 @@ def generate_script_docu(tr, params):
_, _, timestamp_range = get_batch_timestamps(batch_files, prev_batch_files)
frame_content = {
"_id": i + 1,
"timestamp": timestamp_range,
"picture": result['response'],
"narration": "",