refactor(app): 优化视频剪辑功能和相关日志输出- 注释掉部分日志输出,减少冗余信息

- 修改视频脚本 ID 获取方式
- 优化视频路径获取逻辑
- 移除未使用的导入
- 增加异常日志输出,提高错误排查效率
This commit is contained in:
linyq 2025-05-08 00:13:19 +08:00
parent 0ccb019f88
commit ce01c110be
5 changed files with 12 additions and 9 deletions

View File

@ -446,7 +446,7 @@ def save_clip_video(timestamp: str, origin_video: str, save_dir: str = "") -> st
] ]
# 执行FFmpeg命令 # 执行FFmpeg命令
logger.info(f"裁剪视频片段: {timestamp} -> {ffmpeg_start_time}{ffmpeg_end_time}") # logger.info(f"裁剪视频片段: {timestamp} -> {ffmpeg_start_time}到{ffmpeg_end_time}")
# logger.debug(f"执行命令: {' '.join(ffmpeg_cmd)}") # logger.debug(f"执行命令: {' '.join(ffmpeg_cmd)}")
process = subprocess.run( process = subprocess.run(
@ -478,7 +478,7 @@ def save_clip_video(timestamp: str, origin_video: str, save_dir: str = "") -> st
if os.path.exists(video_path): if os.path.exists(video_path):
os.remove(video_path) os.remove(video_path)
return '' return ''
except Exception as e: except Exception as e:
logger.error(f"视频剪辑过程中发生错误: \n{str(traceback.format_exc())}") logger.error(f"视频剪辑过程中发生错误: \n{str(traceback.format_exc())}")
if os.path.exists(video_path): if os.path.exists(video_path):
@ -505,7 +505,6 @@ def clip_videos(task_id: str, timestamp_terms: List[str], origin_video: str, pro
try: try:
saved_video_path = save_clip_video(timestamp=item, origin_video=origin_video, save_dir=material_directory) saved_video_path = save_clip_video(timestamp=item, origin_video=origin_video, save_dir=material_directory)
if saved_video_path: if saved_video_path:
logger.info(f"video saved: {saved_video_path}")
video_paths.update({index+1:saved_video_path}) video_paths.update({index+1:saved_video_path})
# 更新进度 # 更新进度
@ -516,6 +515,7 @@ def clip_videos(task_id: str, timestamp_terms: List[str], origin_video: str, pro
return {} return {}
logger.success(f"裁剪 {len(video_paths)} videos") logger.success(f"裁剪 {len(video_paths)} videos")
# logger.debug(json.dumps(video_paths, indent=4, ensure_ascii=False))
return video_paths return video_paths

View File

@ -4,8 +4,6 @@ from loguru import logger
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
from app.services import material from app.services import material
from app.models.schema import VideoClipParams
from app.utils import utils
class VideoService: class VideoService:

View File

@ -1197,11 +1197,14 @@ def azure_tts_v2(text: str, voice_name: str, voice_file: str) -> Union[SubMaker,
def _format_text(text: str) -> str: def _format_text(text: str) -> str:
# text = text.replace("\n", " ") text = text.replace("\n", " ")
text = text.replace("\"", " ")
text = text.replace("[", " ") text = text.replace("[", " ")
text = text.replace("]", " ") text = text.replace("]", " ")
text = text.replace("(", " ") text = text.replace("(", " ")
text = text.replace(")", " ") text = text.replace(")", " ")
text = text.replace("", " ")
text = text.replace("", " ")
text = text.replace("{", " ") text = text.replace("{", " ")
text = text.replace("}", " ") text = text.replace("}", " ")
text = text.strip() text = text.strip()
@ -1394,8 +1397,10 @@ def create_subtitle(sub_maker: submaker.SubMaker, text: str, subtitle_file: str)
logger.error(f"failed, error: {str(e)}") logger.error(f"failed, error: {str(e)}")
os.remove(subtitle_file) os.remove(subtitle_file)
else: else:
logger.warning( logger.error(
f"字幕创建失败, 字幕长度: {len(sub_items)}, script_lines len: {len(script_lines)}" f"字幕创建失败, 字幕长度: {len(sub_items)}, script_lines len: {len(script_lines)}"
f"\nsub_items:{json.dumps(sub_items, indent=4, ensure_ascii=False)}"
f"\nscript_lines:{json.dumps(script_lines, indent=4, ensure_ascii=False)}"
) )
except Exception as e: except Exception as e:

View File

@ -506,7 +506,7 @@ def cut_video(params, progress_callback=None):
st.session_state['subclip_videos'] = subclip_videos st.session_state['subclip_videos'] = subclip_videos
for i, video_script in enumerate(video_script_list): for i, video_script in enumerate(video_script_list):
try: try:
video_script['path'] = subclip_videos[video_script['timestamp']] video_script['path'] = subclip_videos[i+1]
except KeyError as err: except KeyError as err:
logger.error(f"裁剪视频失败: {err}") logger.error(f"裁剪视频失败: {err}")

View File

@ -33,7 +33,7 @@ def render_video_item(tr, video_list, subclip_videos, index):
video_script = video_list[index] video_script = video_list[index]
# 显示时间戳 # 显示时间戳
timestamp = video_script.get('timestamp', '') timestamp = video_script.get('_id', '')
st.text_area( st.text_area(
tr("Timestamp"), tr("Timestamp"),
value=timestamp, value=timestamp,