mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-06-06 00:01:54 +08:00
fix: 性能优化、前端转写器配置、任务进度丢失及 MLX Whisper 回退问题修复
### 性能优化 - 后端任务执行从串行锁改为 ThreadPoolExecutor 并发执行(默认3线程) - 添加 GZipMiddleware 响应压缩 + Nginx gzip 配置 - 数据库连接池参数优化(pool_size=10, max_overflow=20) - 视频帧提取并行化(ThreadPoolExecutor) - LLM 重试配置缓存到实例,避免每次请求读 env var - 前端路由级代码拆分(React.lazy + Suspense) - Vite manualChunks 拆分 markdown/markmap/vendor - MarkdownViewer 用 React.memo + useMemo 减少不必要渲染 - NoteHistory Fuse.js 实例 useMemo 缓存 - useTaskPolling 无待处理任务时跳过轮询 - 移除 antd 依赖(NoteForm Alert、modelForm Tag),改用 shadcn/ui ### 前端转写器配置(新功能) - 新增 TranscriberConfigManager(JSON 文件存储,替代环境变量) - 新增 GET/POST /transcriber_config API 端点 - 新增 GET /transcriber_models_status 模型下载状态查询 - 新增 POST /transcriber_download 后台模型下载触发 - 前端转写器设置页面:引擎选择、模型大小选择、模型下载管理 - deploy_status 端点同步从配置文件读取 ### Bug 修复 - 修复任务进行中切换页面后进度丢失:Home.tsx status 派生逻辑补全中间状态 - 修复 MLX Whisper 静默回退 fast-whisper:移除环境变量门控,macOS 下自动尝试导入 - MLX Whisper 不可用时抛出 RuntimeError 而非静默回退 - 前端展示 MLX Whisper 可用性状态,不可用时禁用保存 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import hashlib
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
import ffmpeg
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
@@ -54,6 +55,18 @@ class VideoReader:
|
||||
return mm * 60 + ss
|
||||
return float('inf')
|
||||
|
||||
def _extract_single_frame(self, ts: int) -> str | None:
|
||||
"""提取单帧,返回输出路径或 None(失败时)。"""
|
||||
time_label = self.format_time(ts)
|
||||
output_path = os.path.join(self.frame_dir, f"frame_{time_label}.jpg")
|
||||
cmd = ["ffmpeg", "-ss", str(ts), "-i", self.video_path, "-frames:v", "1", "-q:v", "2", "-y", output_path,
|
||||
"-hide_banner", "-loglevel", "error"]
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
return output_path
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
def extract_frames(self, max_frames=1000) -> list[str]:
|
||||
|
||||
try:
|
||||
@@ -61,14 +74,22 @@ class VideoReader:
|
||||
duration = float(ffmpeg.probe(self.video_path)["format"]["duration"])
|
||||
timestamps = [i for i in range(0, int(duration), self.frame_interval)][:max_frames]
|
||||
|
||||
# 并行提取帧
|
||||
max_workers = min(os.cpu_count() or 4, 8, len(timestamps))
|
||||
frame_results: dict[int, str | None] = {}
|
||||
with ThreadPoolExecutor(max_workers=max_workers) as pool:
|
||||
futures = {pool.submit(self._extract_single_frame, ts): ts for ts in timestamps}
|
||||
for future in as_completed(futures):
|
||||
ts = futures[future]
|
||||
frame_results[ts] = future.result()
|
||||
|
||||
# 按时间戳顺序整理结果,并进行去重
|
||||
image_paths = []
|
||||
last_hash = None
|
||||
for ts in timestamps:
|
||||
time_label = self.format_time(ts)
|
||||
output_path = os.path.join(self.frame_dir, f"frame_{time_label}.jpg")
|
||||
cmd = ["ffmpeg", "-ss", str(ts), "-i", self.video_path, "-frames:v", "1", "-q:v", "2", "-y", output_path,
|
||||
"-hide_banner", "-loglevel", "error"]
|
||||
subprocess.run(cmd, check=True)
|
||||
output_path = frame_results.get(ts)
|
||||
if not output_path or not os.path.exists(output_path):
|
||||
continue
|
||||
|
||||
if self.dedupe_enabled:
|
||||
frame_hash = self._calculate_file_md5(output_path)
|
||||
|
||||
Reference in New Issue
Block a user