Skip to content

Commit 1192e61

Browse files
committed
同步VSR对于任务列表带来的改进
以及支持停止任务, 重置任务状态
1 parent caa3316 commit 1192e61

File tree

15 files changed

+262
-151
lines changed

15 files changed

+262
-151
lines changed

backend/interface/ch.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = 所有文件
163163
Vertical = 垂直方向
164164
Horizontal = 水平方向
165165
Run = 运行
166+
Stop = 停止
166167
Setting = 设置
167168
OpenVideoSuccess = 成功打开视频
168169
OpenVideoFailed = 无法打开视频: {}, 格式不兼容或文件损坏
169170
OpenVideoFirst = 请先打开视频
170171
SubtitleArea = 字幕区域
171172
VideoPreview = 视频预览
173+
ErrorDuringProcessing = 处理过程中发生错误: {}
172174

173175
[Main]
174176
RecSubLang = 识别字幕语言
@@ -220,6 +222,7 @@ Progress = ⠀进度⠀
220222
Status = ㅤ状态ㅤ
221223
OpenVideoLocation = 打开视频位置
222224
OpenSubtitleLocation = 打开字幕位置
225+
ResetTaskStatus = 重置任务状态
223226
DeleteTask = 删除任务
224227
Warning = 警告
225228
UnableToLocateFile = 找不到文件,可能已被移动或删除

backend/interface/chinese_cht.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = 所有文件
163163
Vertical = 垂直方向
164164
Horizontal = 水平方向
165165
Run = 運行
166+
Stop = 停止
166167
Setting = 設置
167168
OpenVideoSuccess = 成功打開視頻
168169
OpenVideoFailed = 無法打開視頻: {},格式不相容或檔案損壞
169170
OpenVideoFirst = 請先打開視頻
170171
SubtitleArea = 字幕區域
171172
VideoPreview = 視頻預覽
173+
ErrorDuringProcessing = 處理過程中發生錯誤: {}
172174

173175
[Main]
174176
RecSubLang = 識別字幕語言
@@ -219,7 +221,8 @@ Name = 檔案
219221
Progress = ⠀進度⠀
220222
Status = ㅤ狀態ㅤ
221223
OpenVideoLocation = 開啟視頻位置
222-
OpenSubtitleLocation = 開啟字幕位置
224+
OpenSubtitleLocation = 開啟字幕位置
225+
ResetTaskStatus = 重設任務狀態
223226
DeleteTask = 刪除
224227
Warning = 警告
225228
UnableToLocateFile = 找不到檔案,可能已被移動或刪除

backend/interface/en.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,14 @@ AllFile = All Files
164164
Vertical = Vertical
165165
Horizontal = Horizontal
166166
Run = Run
167+
Stop = Stop
167168
Setting = Settings
168169
OpenVideoSuccess = Successfully Open Video
169170
OpenVideoFailed = Failed to open video: {}, incompatible format or file is corrupted
170171
OpenVideoFirst = Please Open Video First
171172
SubtitleArea = Subtitle Area
172173
VideoPreview = Video Preview
174+
ErrorDuringProcessing = Error during processing: {}
173175

174176
[Main]
175177
RecSubLang = Subtitle Language
@@ -220,7 +222,8 @@ Name = File
220222
Progress = Progress
221223
Status = Status
222224
OpenVideoLocation = Open Video Location
223-
OpenSubtitleLocation = Open Subtitle Location
225+
OpenSubtitleLocation = Open Subtitle Location
226+
ResetTaskStatus = Reset Task
224227
DeleteTask = Delete
225228
Warning = Warning
226229
UnableToLocateFile = File not found, it may have been moved or deleted

backend/interface/es.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = Todos los archivos
163163
Vertical = Vertical
164164
Horizontal = Horizontal
165165
Run = Ejecutar
166+
Stop = Detener
166167
Setting = Configuraciones
167168
OpenVideoSuccess = Se abrió el video exitosamente
168169
OpenVideoFailed = No se pudo abrir el video: {}, formato incompatible o archivo dañado
169170
OpenVideoFirst = Por favor, abra el video primero
170171
SubtitleArea = Área de subtítulos
171172
VideoPreview = Vista previa de video
173+
ErrorDuringProcessing = Error durante el procesamiento: {}
172174

173175
[Main]
174176
RecSubLang = Idioma de subtítulos
@@ -219,7 +221,8 @@ Name = Archivo
219221
Progress = Progreso
220222
Status = Estado
221223
OpenVideoLocation = Abrir ubicación del video
222-
OpenSubtitleLocation = Abrir ubicación del subtítulo
224+
OpenSubtitleLocation = Abrir ubicación del subtítulo
225+
ResetTaskStatus = Reiniciar tarea
223226
DeleteTask = Eliminar
224227
Warning = Advertencia
225228
UnableToLocateFile = Archivo no encontrado, puede haber sido movido o eliminado

backend/interface/japan.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = 全てのファイル
163163
Vertical = 垂直
164164
Horizontal = 水平
165165
Run = 実行
166+
Stop = 停止
166167
Setting = 設定
167168
OpenVideoSuccess = ビデオが正常に開きました
168169
OpenVideoFailed = ビデオを開けません: {}、フォーマットが非対応またはファイルが破損しています
169170
OpenVideoFirst = 最初にビデオを開いてください
170171
SubtitleArea = サブタイトル領域
171172
VideoPreview = ビデオプレビュー
173+
ErrorDuringProcessing = 処理中にエラーが発生しました: {}
172174

173175
[Main]
174176
RecSubLang = サブタイトル言語
@@ -220,6 +222,7 @@ Progress = ⠀進捗⠀
220222
Status = ㅤ状態ㅤ
221223
OpenVideoLocation = 動画の場所を開く
222224
OpenSubtitleLocation = 字幕の場所を開く
225+
ResetTaskStatus = タスク状態リセット
223226
DeleteTask = 削除
224227
Warning = 警告
225228
UnableToLocateFile = ファイルが見つかりません。移動または削除された可能性があります

backend/interface/ko.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = 모든 파일
163163
Vertical = 세로
164164
Horizontal = 가로
165165
Run = 실행
166+
Stop = 중지
166167
Setting = 설정
167168
OpenVideoSuccess = 비디오 열기 성공
168169
OpenVideoFailed = 비디오를 열 수 없습니다: {}, 형식이 호환되지 않거나 파일이 손상되었습니다
169170
OpenVideoFirst = 비디오을 먼저 열어주세요
170171
SubtitleArea = 자막 영역
171172
VideoPreview = 비디오 미리보기
173+
ErrorDuringProcessing = 처리 중 오류: {}
172174

173175
[Main]
174176
RecSubLang = 자막 언어 인식
@@ -220,6 +222,7 @@ Progress = ⠀진행⠀
220222
Status = ㅤ상태ㅤ
221223
OpenVideoLocation = 비디오 위치 열기
222224
OpenSubtitleLocation = 자막 위치 열기
225+
ResetTaskStatus = 작업 상태 재설정
223226
DeleteTask = 삭제
224227
Warning = 경고
225228
UnableToLocateFile = 파일을 찾을 수 없습니다. 이동되거나 삭제되었을 수 있습니다

backend/interface/vi.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ AllFile = Tất cả tệp
163163
Vertical = Thẳng đứng
164164
Horizontal = Ngang
165165
Run = Chạy
166+
Stop = Dừng
166167
Setting = Cài đặt
167168
OpenVideoSuccess = Mở video thành công
168169
OpenVideoFailed = Không thể mở video: {}, định dạng không tương thích hoặc tệp bị hỏng
169170
OpenVideoFirst = Xin mở video trước đã
170171
SubtitleArea = Khu vực phụ đề
171172
VideoPreview = Xem trước video
173+
ErrorDuringProcessing = Lỗi khi xử lý: {}
172174

173175
[Main]
174176
RecSubLang = Ngôn ngữ phụ đề
@@ -220,6 +222,7 @@ Progress = Tiến độ
220222
Status = Trạng thái
221223
OpenVideoLocation = Mở vị trí video
222224
OpenSubtitleLocation = Mở vị trí phụ đề
225+
ResetTaskStatus = Đặt lại trạng thái
223226
DeleteTask = Xóa
224227
Warning = Cảnh báo
225228
UnableToLocateFile = Không tìm thấy tệp, có thể đã bị di chuyển hoặc xóa

backend/main.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def __init__(self, vd_path, sub_area=None):
100100
self.vsf_subtitle = os.path.join(self.subtitle_output_dir, 'raw_vsf.srt')
101101
# 提取的原始字幕文本存储路径
102102
self.raw_subtitle_path = os.path.join(self.subtitle_output_dir, 'raw.txt')
103+
# 定义输出字幕文件路径
104+
self.subtitle_output_path = os.path.splitext(self.video_path)[0] + '.srt'
103105
# 自定义ocr对象
104106
self.ocr = None
105107
# 总处理进度
@@ -199,15 +201,15 @@ def run(self):
199201
# 如果未使用vsf提取字幕,则使用常规字幕生成方法
200202
self.generate_subtitle_file()
201203
if config.wordSegmentation.value:
202-
reformat.execute(os.path.join(os.path.splitext(self.video_path)[0] + '.srt'), config.language.value)
204+
reformat.execute(self.subtitle_output_path, config.language.value)
203205
self.append_output(tr['Main']['FinishGenerateSub'], f"{round(time.time() - start_time, 2)}s")
204206
self.update_progress(ocr=100, frame_extract=100)
205207
self.isFinished = True
206208
# 删除缓存文件
207209
self.empty_cache()
208210
self.lock.release()
209211
if config.generateTxt.value:
210-
self.srt2txt(os.path.join(os.path.splitext(self.video_path)[0] + '.srt'))
212+
self.srt2txt(self.subtitle_output_path)
211213

212214
def capture_frame_with_subtitle_area(self):
213215
"""
@@ -632,10 +634,9 @@ def generate_subtitle_file(self):
632634
"""
633635
if not self.use_vsf:
634636
subtitle_content = self._remove_duplicate_subtitle()
635-
srt_filename = os.path.join(os.path.splitext(self.video_path)[0] + '.srt')
636637
# 保存持续时间不足1秒的字幕行,用于后续处理
637638
post_process_subtitle = []
638-
with open(srt_filename, mode='w', encoding='utf-8') as f:
639+
with open(self.subtitle_output_path, mode='w', encoding='utf-8') as f:
639640
for index, content in enumerate(subtitle_content):
640641
line_code = index + 1
641642
frame_start = self._frame_to_timecode(int(content[0]))
@@ -648,7 +649,7 @@ def generate_subtitle_file(self):
648649
frame_content = content[2]
649650
subtitle_line = f'{line_code}\n{frame_start} --> {frame_end}\n{frame_content}\n'
650651
f.write(subtitle_line)
651-
self.append_output(f"[NO-VSF]{tr['Main']['SubLocation']} {srt_filename}")
652+
self.append_output(f"[NO-VSF]{tr['Main']['SubLocation']} {self.subtitle_output_path}")
652653
# 返回持续时间低于1s的字幕行
653654
return post_process_subtitle
654655

@@ -681,9 +682,8 @@ def generate_subtitle_file_vsf(self):
681682
final_subtitles.append(sub)
682683
continue
683684

684-
srt_filename = os.path.join(os.path.splitext(self.video_path)[0] + '.srt')
685-
pysrt.SubRipFile(final_subtitles).save(srt_filename, encoding='utf-8')
686-
self.append_output(f"[VSF]{tr['Main']['SubLocation']} {srt_filename}")
685+
pysrt.SubRipFile(final_subtitles).save(self.subtitle_output_path, encoding='utf-8')
686+
self.append_output(f"[VSF]{tr['Main']['SubLocation']} {self.subtitle_output_path}")
687687

688688
def _detect_watermark_area(self):
689689
"""
@@ -1047,6 +1047,8 @@ def get_ocr_progress():
10471047
'HARDWARD_ACCELERATOR': self.hardware_accelerator,
10481048
}
10491049
process, task_queue, progress_queue = subtitle_ocr.async_start(self.video_path, self.raw_subtitle_path, self.sub_area, options)
1050+
ProcessManager.instance().add_process(process)
1051+
self.manage_process(process.pid)
10501052
self.subtitle_ocr_task_queue = task_queue
10511053
self.subtitle_ocr_progress_queue = progress_queue
10521054
# 开启线程负责更新OCR进度

backend/tools/subtitle_extractor_remote_call.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Command(Enum):
77
PROGRESS = 1,
88
LOG = 2,
99
MANAGE_PROCESS = 3,
10+
ERROR = 4,
1011

1112
class SubtitleExtractorRemoteCall:
1213
"""
@@ -42,6 +43,9 @@ def register_log_callback(self, callback):
4243
def register_manage_process_callback(self, callback):
4344
self.callbacks[Command.MANAGE_PROCESS] = callback
4445

46+
def register_error_callback(self, callback):
47+
self.callbacks[Command.ERROR] = callback
48+
4549
@staticmethod
4650
def remote_call_update_progress(queue, progress, isFinished):
4751
queue.put((Command.PROGRESS, (progress, isFinished,)))
@@ -53,6 +57,10 @@ def remote_call_append_log(queue, *args):
5357
@staticmethod
5458
def remote_call_finish(queue, *args):
5559
queue.put((Command.FINISH, (None,)))
60+
61+
@staticmethod
62+
def remote_call_catch_error(queue, e):
63+
queue.put((Command.ERROR, (e,)))
5664

5765
@staticmethod
5866
def remote_call_manage_process(queue, pid):

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ shapely==2.0.7
1414
six==1.17.0
1515
setuptools==75.8.0
1616
paddleocr==2.10.0
17-
show-in-file-manager==1.1.5
17+
je-showinfilemanager==1.1.6a4

0 commit comments

Comments
 (0)