mirror of
https://github.com/linyqh/NarratoAI.git
synced 2025-12-12 11:22:51 +00:00
feat(script): 添加帧间隔输入参数并更新相关逻辑
- 在 GenerateScriptRequest 和 ScriptGenerator 中新增 frame_interval_input 参数,默认为 5 - 更新 VideoProcessor 的 process_video_pipeline 方法,调整帧提取间隔逻辑 - 修改前端界面,增加帧间隔输入框并更新相关翻译文本 - 优化 generate_script_docu 函数,使用新的帧间隔参数进行视频处理
This commit is contained in:
parent
f6c3f1640b
commit
82823297f2
@ -6,6 +6,7 @@ class GenerateScriptRequest(BaseModel):
|
|||||||
video_path: str
|
video_path: str
|
||||||
video_theme: Optional[str] = ""
|
video_theme: Optional[str] = ""
|
||||||
custom_prompt: Optional[str] = ""
|
custom_prompt: Optional[str] = ""
|
||||||
|
frame_interval_input: Optional[int] = 5
|
||||||
skip_seconds: Optional[int] = 0
|
skip_seconds: Optional[int] = 0
|
||||||
threshold: Optional[int] = 30
|
threshold: Optional[int] = 30
|
||||||
vision_batch_size: Optional[int] = 5
|
vision_batch_size: Optional[int] = 5
|
||||||
|
|||||||
@ -22,6 +22,7 @@ class ScriptGenerator:
|
|||||||
video_path: str,
|
video_path: str,
|
||||||
video_theme: str = "",
|
video_theme: str = "",
|
||||||
custom_prompt: str = "",
|
custom_prompt: str = "",
|
||||||
|
frame_interval_input: int = 5,
|
||||||
skip_seconds: int = 0,
|
skip_seconds: int = 0,
|
||||||
threshold: int = 30,
|
threshold: int = 30,
|
||||||
vision_batch_size: int = 5,
|
vision_batch_size: int = 5,
|
||||||
|
|||||||
@ -292,10 +292,7 @@ class VideoProcessor:
|
|||||||
def process_video_pipeline(self,
|
def process_video_pipeline(self,
|
||||||
output_dir: str,
|
output_dir: str,
|
||||||
skip_seconds: float = 0.0,
|
skip_seconds: float = 0.0,
|
||||||
threshold: int = 20, # 此参数保留但不使用
|
interval_seconds: float = 5.0, # 帧提取间隔(秒)
|
||||||
compressed_width: int = 320, # 此参数保留但不使用
|
|
||||||
keep_temp: bool = False, # 此参数保留但不使用
|
|
||||||
interval_seconds: float = 5.0,
|
|
||||||
use_hw_accel: bool = True) -> None:
|
use_hw_accel: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
执行简化的视频处理流程,直接从原视频按固定时间间隔提取帧
|
执行简化的视频处理流程,直接从原视频按固定时间间隔提取帧
|
||||||
@ -303,9 +300,6 @@ class VideoProcessor:
|
|||||||
Args:
|
Args:
|
||||||
output_dir: 输出目录
|
output_dir: 输出目录
|
||||||
skip_seconds: 跳过视频开头的秒数
|
skip_seconds: 跳过视频开头的秒数
|
||||||
threshold: 保留参数,不使用
|
|
||||||
compressed_width: 保留参数,不使用
|
|
||||||
keep_temp: 保留参数,不使用
|
|
||||||
interval_seconds: 帧提取间隔(秒)
|
interval_seconds: 帧提取间隔(秒)
|
||||||
use_hw_accel: 是否使用硬件加速
|
use_hw_accel: 是否使用硬件加速
|
||||||
"""
|
"""
|
||||||
@ -314,7 +308,7 @@ class VideoProcessor:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 直接从原视频提取关键帧
|
# 直接从原视频提取关键帧
|
||||||
logger.info("从视频直接提取关键帧...")
|
logger.info(f"从视频间隔 {interval_seconds} 秒提取关键帧...")
|
||||||
self.extract_frames_by_interval(
|
self.extract_frames_by_interval(
|
||||||
output_dir,
|
output_dir,
|
||||||
interval_seconds=interval_seconds,
|
interval_seconds=interval_seconds,
|
||||||
|
|||||||
@ -47,7 +47,7 @@ def render_script_file(tr, params):
|
|||||||
(tr("None"), ""),
|
(tr("None"), ""),
|
||||||
(tr("Auto Generate"), "auto"),
|
(tr("Auto Generate"), "auto"),
|
||||||
(tr("Short Generate"), "short"),
|
(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":
|
if script_path != "short":
|
||||||
# 非短视频模式下显示原有的三个输入框
|
# 非短视频模式下显示原有的三个输入框
|
||||||
input_cols = st.columns(3)
|
input_cols = st.columns(2)
|
||||||
|
|
||||||
with input_cols[0]:
|
with input_cols[0]:
|
||||||
skip_seconds = st.number_input(
|
st.number_input(
|
||||||
"skip_seconds",
|
tr("Frame Interval (seconds)"),
|
||||||
min_value=0,
|
min_value=0,
|
||||||
value=st.session_state.get('skip_seconds', config.frames.get('skip_seconds', 0)),
|
value=st.session_state.get('frame_interval_input', config.frames.get('frame_interval_input', 5)),
|
||||||
help=tr("Skip the first few seconds"),
|
help=tr("Frame Interval (seconds) (More keyframes consume more tokens)"),
|
||||||
key="skip_seconds_input"
|
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":
|
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 st.button(button_name, key="script_action", disabled=not script_path):
|
||||||
if script_path == "auto":
|
if script_path == "auto":
|
||||||
generate_script_docu(tr, params)
|
# 执行纪录片视频脚本生成(视频无字幕无配音)
|
||||||
|
generate_script_docu(params)
|
||||||
elif script_path == "short":
|
elif script_path == "short":
|
||||||
# 获取自定义片段数量参数
|
# 获取自定义片段数量参数
|
||||||
custom_clips = st.session_state.get('custom_clips', 5)
|
custom_clips = st.session_state.get('custom_clips', 5)
|
||||||
|
|||||||
@ -85,6 +85,7 @@
|
|||||||
"TTS Provider": "TTS Provider",
|
"TTS Provider": "TTS Provider",
|
||||||
"Hide Log": "Hide Log",
|
"Hide Log": "Hide Log",
|
||||||
"Upload Local Files": "Upload Local Files",
|
"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)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,6 +192,8 @@
|
|||||||
"Generate Short Video Script": "AI生成短剧混剪脚本",
|
"Generate Short Video Script": "AI生成短剧混剪脚本",
|
||||||
"Adjust the volume of the original audio": "调整原始音频的音量",
|
"Adjust the volume of the original audio": "调整原始音频的音量",
|
||||||
"Original Volume": "视频音量",
|
"Original Volume": "视频音量",
|
||||||
"Auto Generate": "纪录片解说 (画面解说)"
|
"Auto Generate": "纪录片解说 (画面解说)",
|
||||||
|
"Frame Interval (seconds)": "帧间隔 (秒)",
|
||||||
|
"Frame Interval (seconds) (More keyframes consume more tokens)": "帧间隔 (秒) (更多关键帧消耗更多令牌)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
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)
|
progress_bar = st.progress(0)
|
||||||
status_text = st.empty()
|
status_text = st.empty()
|
||||||
@ -69,8 +71,7 @@ def generate_script_docu(tr, params):
|
|||||||
# 处理视频并提取关键帧
|
# 处理视频并提取关键帧
|
||||||
processor.process_video_pipeline(
|
processor.process_video_pipeline(
|
||||||
output_dir=video_keyframes_dir,
|
output_dir=video_keyframes_dir,
|
||||||
skip_seconds=st.session_state.get('skip_seconds'),
|
interval_seconds=st.session_state.get('frame_interval_input'),
|
||||||
threshold=st.session_state.get('threshold')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 获取所有关键文件路径
|
# 获取所有关键文件路径
|
||||||
@ -194,6 +195,7 @@ def generate_script_docu(tr, params):
|
|||||||
_, _, timestamp_range = get_batch_timestamps(batch_files, prev_batch_files)
|
_, _, timestamp_range = get_batch_timestamps(batch_files, prev_batch_files)
|
||||||
|
|
||||||
frame_content = {
|
frame_content = {
|
||||||
|
"_id": i + 1,
|
||||||
"timestamp": timestamp_range,
|
"timestamp": timestamp_range,
|
||||||
"picture": result['response'],
|
"picture": result['response'],
|
||||||
"narration": "",
|
"narration": "",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user