From 82823297f2e293823f18d24e2dad00b97e7ef6c4 Mon Sep 17 00:00:00 2001 From: linyq Date: Wed, 7 May 2025 16:43:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(script):=20=E6=B7=BB=E5=8A=A0=E5=B8=A7?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E8=BE=93=E5=85=A5=E5=8F=82=E6=95=B0=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 GenerateScriptRequest 和 ScriptGenerator 中新增 frame_interval_input 参数,默认为 5 - 更新 VideoProcessor 的 process_video_pipeline 方法,调整帧提取间隔逻辑 - 修改前端界面,增加帧间隔输入框并更新相关翻译文本 - 优化 generate_script_docu 函数,使用新的帧间隔参数进行视频处理 --- app/models/schema_v2.py | 1 + app/services/script_service.py | 1 + app/utils/video_processor.py | 10 ++------ webui/components/script_settings.py | 39 +++++++---------------------- webui/i18n/en.json | 3 ++- webui/i18n/zh.json | 4 ++- webui/tools/generate_script_docu.py | 8 +++--- 7 files changed, 23 insertions(+), 43 deletions(-) diff --git a/app/models/schema_v2.py b/app/models/schema_v2.py index 1611a3b..8584c75 100644 --- a/app/models/schema_v2.py +++ b/app/models/schema_v2.py @@ -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 diff --git a/app/services/script_service.py b/app/services/script_service.py index f4a6f95..461978b 100644 --- a/app/services/script_service.py +++ b/app/services/script_service.py @@ -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, diff --git a/app/utils/video_processor.py b/app/utils/video_processor.py index a754d50..d10f8a7 100644 --- a/app/utils/video_processor.py +++ b/app/utils/video_processor.py @@ -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, diff --git a/webui/components/script_settings.py b/webui/components/script_settings.py index ac5c76e..1e681b3 100644 --- a/webui/components/script_settings.py +++ b/webui/components/script_settings.py @@ -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) diff --git a/webui/i18n/en.json b/webui/i18n/en.json index e0f2900..63a2c36 100644 --- a/webui/i18n/en.json +++ b/webui/i18n/en.json @@ -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)" } } \ No newline at end of file diff --git a/webui/i18n/zh.json b/webui/i18n/zh.json index beb48ec..7a7a387 100644 --- a/webui/i18n/zh.json +++ b/webui/i18n/zh.json @@ -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)": "帧间隔 (秒) (更多关键帧消耗更多令牌)" } } diff --git a/webui/tools/generate_script_docu.py b/webui/tools/generate_script_docu.py index a580f64..7069215 100644 --- a/webui/tools/generate_script_docu.py +++ b/webui/tools/generate_script_docu.py @@ -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": "",