Skip to content

Commit 5ee028b

Browse files
committed
支持设置VSF核心数和解码器
1 parent dd51981 commit 5ee028b

File tree

11 files changed

+78
-7
lines changed

11 files changed

+78
-7
lines changed

backend/config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from qfluentwidgets import (qconfig, ConfigItem, QConfig, OptionsValidator, BoolValidator, OptionsConfigItem,
55
EnumSerializer, RangeValidator, RangeConfigItem)
6-
from backend.tools.constant import SubtitleArea
6+
from backend.tools.constant import SubtitleArea, VideoSubFinderDecoder
77
import configparser
88

99
# 项目版本号
@@ -90,6 +90,10 @@ class Config(QConfig):
9090
hardwareAcceleration = ConfigItem("Main", "HardwareAcceleration", HARDWARD_ACCELERATION_OPTION, BoolValidator())
9191
# 启动时检查应用更新
9292
checkUpdateOnStartup = ConfigItem("Main", "CheckUpdateOnStartup", True, BoolValidator())
93+
# VideoSubFinder CPU核心数
94+
videoSubFinderCpuCores = RangeConfigItem("Main", "VideoSubFinderCpuCores", 0, RangeValidator(0, os.cpu_count()))
95+
# VideoSubFinder 视频解码组件
96+
videoSubFinderDecoder = OptionsConfigItem("Main", "VideoSubFinderDecoder", VideoSubFinderDecoder.OPENCV, OptionsValidator(VideoSubFinderDecoder), EnumSerializer(VideoSubFinderDecoder))
9397

9498
CONFIG_FILE = 'config/config.json'
9599
config = Config()

backend/interface/ch.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ProjectLinkDesc = 视频硬字幕提取,生成srt文件。无需申请第三
1010
BasicSetting = 基础设置
1111
AdvancedSetting = 高级设置
1212
DevSetting = 开发配置
13+
VideoSubFinderSetting = VideoSubFinder配置
1314
AboutSetting = 关于
1415
GenerateTxt = 生成TXT文本字幕
1516
WordSegmentation = 重新分词
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = 有可用更新
5051
UpdatesAvailableDesc = 发现新版本 {}, 是否更新?
5152
NoUpdatesAvailableTitle = 无可用更新
5253
NoUpdatesAvailableDesc = 软件已是最新版本
54+
VideoSubFinderCpuCores = CPU核心数
55+
VideoSubFinderCpuCoresDesc = 字幕提取时使用的CPU核心数,默认为0,即自动, 选择所有核心并不会变得快
56+
VideoSubFinderDecoder = 视频解码组件
57+
VideoSubFinderDecoderDesc = 用于针对不同视频兼容性需求, 默认为OpenCV(推荐), 当遇到无法正常提取时可以切换为FFmpeg(可能会造成时间轴细微偏移)
5358

5459
[SubtitleArea]
5560
LowerPart = 下半部分

backend/interface/chinese_cht.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ProjectLinkTitle = 字幕提取器
99
ProjectLinkDesc = 視頻硬字幕提取,生成srt文件。無需申請第三方API,本地實現文本識別。基於深度學習的視頻字幕提取框架,包含字幕區域檢測、字幕內容提取。
1010
BasicSetting = 基本設置
1111
AdvancedSetting = 高級設置
12+
VideoSubFinderSetting = VideoSubFinder設定
1213
DevSetting = 開發配置
1314
AboutSetting = 關於
1415
GenerateTxt = 生成TXT文本字幕
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = 有可用更新
5051
UpdatesAvailableDesc = 發現新版本 {},是否更新?
5152
NoUpdatesAvailableTitle = 無可用更新
5253
NoUpdatesAvailableDesc = 軟體已是最新版本
54+
VideoSubFinderCpuCores = CPU核心數
55+
VideoSubFinderCpuCoresDesc = 提取字幕時使用的CPU核心數,預設為0(自動),選擇所有核心不一定更快
56+
VideoSubFinderDecoder = 視頻解碼組件
57+
VideoSubFinderDecoderDesc = 用於不同影片相容性需求,預設為OpenCV(推薦),若無法正常提取可切換為FFmpeg(可能導致時間軸略有偏移)
5358

5459
[SubtitleArea]
5560
LowerPart = 下半部分

backend/interface/en.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ProjectLinkTitle = Subtitle Extractor
99
ProjectLinkDesc = Video hard subtitle extraction, generating srt files. No third-party API required, local text recognition. A video subtitle extraction framework based on deep learning, including subtitle area detection and subtitle content extraction.
1010
BasicSetting = Basic Settings
1111
AdvancedSetting = Advanced Settings
12+
VideoSubFinderSetting = VideoSubFinder Settings
1213
DevSetting = Development Settings
1314
AboutSetting = About
1415
GenerateTxt = Generate TXT Subtitles
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = Updates Available
5051
UpdatesAvailableDesc = New version {} found, update now?
5152
NoUpdatesAvailableTitle = No Updates Available
5253
NoUpdatesAvailableDesc = The software is up to date
54+
VideoSubFinderCpuCores = CPU Cores
55+
VideoSubFinderCpuCoresDesc = Number of CPU cores used for subtitle extraction. Default is 0 (auto). Using all cores may not be faster.
56+
VideoSubFinderDecoder = Video Decoder
57+
VideoSubFinderDecoderDesc = For different video compatibility needs. Default is OpenCV (recommended). Switch to FFmpeg if extraction fails (may cause slight timeline shift).
5358

5459
[SubtitleArea]
5560
LowerPart = Lower Part

backend/interface/es.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CopyrightDesc = ©Derechos reservados 2020, YaoFANGUK, Jason Eric (UI), Versión
88
ProjectLinkTitle = Extractor de subtítulos
99
ProjectLinkDesc = Extracción de subtítulos incrustados en video, generando archivos srt. No requiere API de terceros, reconocimiento de texto local. Un marco de extracción de subtítulos de video basado en aprendizaje profundo, que incluye detección de área de subtítulos y extracción de contenido de subtítulos.
1010
BasicSetting = Configuración básica
11-
AdvancedSetting = Configuración avanzada
11+
AdvancedSetting = Configuración de avanzada
12+
VideoSubFinderSetting = Configuración de VideoSubFinder
1213
DevSetting = Configuración de desarrollo
1314
AboutSetting = Acerca de
1415
GenerateTxt = Generar subtítulos TXT
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = Actualizaciones disponibles
5051
UpdatesAvailableDesc = Se encontró una nueva versión {}, ¿actualizar ahora?
5152
NoUpdatesAvailableTitle = No hay actualizaciones disponibles
5253
NoUpdatesAvailableDesc = El software está actualizado
54+
VideoSubFinderCpuCores = Núcleos de CPU
55+
VideoSubFinderCpuCoresDesc = Núcleos de CPU usados para extraer subtítulos. Por defecto es 0 (automático). Usar todos los núcleos no siempre es más rápido.
56+
VideoSubFinderDecoder = Componente de decodificación de video
57+
VideoSubFinderDecoderDesc = Para diferentes necesidades de compatibilidad de video. Por defecto es OpenCV (recomendado). Cambia a FFmpeg si la extracción falla (puede causar un pequeño desfase en la línea de tiempo).
5358

5459
[SubtitleArea]
5560
LowerPart = Parte inferior

backend/interface/japan.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ProjectLinkTitle = 字幕抽出ツール
99
ProjectLinkDesc = 動画の硬字幕を抽出し、srtファイルを生成します。サードパーティAPIは不要で、ローカルでテキスト認識を実現。深層学習に基づく動画字幕抽出フレームワークで、字幕領域の検出と字幕内容の抽出を含みます。
1010
BasicSetting = 基本設定
1111
AdvancedSetting = 詳細設定
12+
VideoSubFinderSetting = VideoSubFinder設定
1213
DevSetting = 開発設定
1314
AboutSetting = について
1415
GenerateTxt = TXT字幕を生成
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = 利用可能なアップデート
5051
UpdatesAvailableDesc = 新しいバージョン{}が見つかりました。今すぐアップデートしますか?
5152
NoUpdatesAvailableTitle = 利用可能なアップデートはありません
5253
NoUpdatesAvailableDesc = ソフトウェアは最新バージョンです
54+
VideoSubFinderCpuCores = CPUコア数
55+
VideoSubFinderCpuCoresDesc = 字幕抽出に使用するCPUコア数。デフォルトは0(自動)。全コアを選択しても速くなるとは限りません。
56+
VideoSubFinderDecoder = ビデオデコーダー
57+
VideoSubFinderDecoderDesc = 異なる動画互換性のニーズに対応。デフォルトはOpenCV(推奨)。抽出できない場合はFFmpegに切り替えてください(タイムラインがわずかにずれる場合があります)。
5358

5459
[SubtitleArea]
5560
LowerPart = 下部

backend/interface/ko.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ProjectLinkTitle = 자막 추출기
99
ProjectLinkDesc = 비디오 하드 자막 추출, srt 파일 생성. 제3자 API가 필요 없으며, 로컬에서 텍스트 인식 구현. 딥러닝 기반 비디오 자막 추출 프레임워크로, 자막 영역 감지 및 자막 내용 추출 포함.
1010
BasicSetting = 기본 설정
1111
AdvancedSetting = 고급 설정
12+
VideoSubFinderSetting = VideoSubFinder 설정
1213
DevSetting = 개발 설정
1314
AboutSetting = 관한
1415
GenerateTxt = TXT 자막 생성
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = 사용 가능한 업데이트
5051
UpdatesAvailableDesc = 새 버전 {}이(가) 발견되었습니다. 지금 업데이트하시겠습니까?
5152
NoUpdatesAvailableTitle = 사용 가능한 업데이트 없음
5253
NoUpdatesAvailableDesc = 소프트웨어가 최신 버전입니다
54+
VideoSubFinderCpuCores = CPU 코어 수
55+
VideoSubFinderCpuCoresDesc = 자막 추출에 사용할 CPU 코어 수입니다. 기본값은 0(자동)이며, 모든 코어를 선택해도 더 빨라지지 않을 수 있습니다.
56+
VideoSubFinderDecoder = 비디오 디코더
57+
VideoSubFinderDecoderDesc = 다양한 비디오 호환성 요구에 사용. 기본값은 OpenCV(추천)이며, 추출이 실패할 경우 FFmpeg로 전환하세요(타임라인이 약간 어긋날 수 있음).
5358

5459
[SubtitleArea]
5560
LowerPart = 하단 부분

backend/interface/vi.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ProjectLinkTitle = Trích xuất phụ đề
99
ProjectLinkDesc = Trích xuất phụ đề cứng từ video, tạo file srt. Không cần API bên thứ ba, nhận dạng văn bản cục bộ. Một framework trích xuất phụ đề video dựa trên học sâu, bao gồm phát hiện vùng phụ đề và trích xuất nội dung phụ đề.
1010
BasicSetting = Cài đặt cơ bản
1111
AdvancedSetting = Cài đặt nâng cao
12+
VideoSubFinderSetting = Cài đặt VideoSubFinder
1213
DevSetting = Cài đặt phát triển
1314
AboutSetting = Liên quan đến
1415
GenerateTxt = Tạo phụ đề TXT
@@ -50,6 +51,10 @@ UpdatesAvailableTitle = Có bản cập nhật mới
5051
UpdatesAvailableDesc = Phát hiện phiên bản mới {}, cập nhật ngay bây giờ?
5152
NoUpdatesAvailableTitle = Không có bản cập nhật mới
5253
NoUpdatesAvailableDesc = Phần mềm đã là phiên bản mới nhất
54+
VideoSubFinderCpuCores = Số lõi CPU
55+
VideoSubFinderCpuCoresDesc = Số lõi CPU dùng để tách phụ đề. Mặc định là 0 (tự động). Dùng tất cả lõi không phải lúc nào cũng nhanh hơn.
56+
VideoSubFinderDecoder = Bộ giải mã video
57+
VideoSubFinderDecoderDesc = Dùng cho các nhu cầu tương thích video khác nhau. Mặc định là OpenCV (khuyến nghị). Chuyển sang FFmpeg nếu tách phụ đề thất bại (có thể lệch nhẹ thời gian).
5358

5459
[SubtitleArea]
5560
LowerPart = Phần dưới

backend/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,13 @@ def vsf_output(out, ):
488488
else:
489489
# 留2核心来给其他任务使用
490490
cpu_count = max(multiprocessing.cpu_count() - 2, 1)
491+
if config.videoSubFinderCpuCores.value > 0:
492+
cpu_count = config.videoSubFinderCpuCores.value
491493
if platform.system() == 'Windows':
492494
# 定义执行命令
493495
cmd = f"{path_vsf} --use_cuda -c -r -i \"{self.video_path}\" -o \"{self.temp_output_dir}\" -ces \"{self.vsf_subtitle}\" "
494-
cmd += f"-te {top_end} -be {bottom_end} -le {left_end} -re {right_end} -nthr {cpu_count} -nocrthr {cpu_count}"
496+
cmd += f"-te {top_end} -be {bottom_end} -le {left_end} -re {right_end} -nthr {cpu_count} -nocrthr {cpu_count} "
497+
cmd += f"--open_video_{config.videoSubFinderDecoder.value.value.lower()} "
495498
# 计算进度
496499
try:
497500
self.vsf_running = True
@@ -509,7 +512,8 @@ def vsf_output(out, ):
509512
cmd = f"{path_vsf} -c -r -i \"{self.video_path}\" -o \"{self.temp_output_dir}\" -ces \"{self.vsf_subtitle}\" "
510513
if self.hardware_accelerator.has_accelerator():
511514
cmd += "--use_cuda "
512-
cmd += f"-te {top_end} -be {bottom_end} -le {left_end} -re {right_end} -nthr {cpu_count} -dsi"
515+
cmd += f"-te {top_end} -be {bottom_end} -le {left_end} -re {right_end} -nthr {cpu_count} -dsi "
516+
cmd += f"--open_video_{config.videoSubFinderDecoder.value.value.lower()} "
513517
self.vsf_running = True
514518
try:
515519
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1,

backend/tools/constant.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class BackgroundColor(Enum):
2020
UNKNOWN = 2
2121

2222

23+
class VideoSubFinderDecoder(Enum):
24+
OPENCV = "OpenCV"
25+
FFMPEG = "FFmpeg"
26+
2327
BGR_COLOR_GREEN = (0, 0xff, 0)
2428
BGR_COLOR_BLUE = (0xff, 0, 0)
2529
BGR_COLOR_RED = (0, 0, 0xff)

0 commit comments

Comments
 (0)