Files
video-subtitle-remover/backend/tools/subtitle_remover_remote_call.py
Jason f78e985e1c 使用PySide6-Fluent-Widgets重构整套UI
添加任务列表组件并优化视频加载逻辑
支持可视化显示字幕区域
整理所有模型, 分别为STTN智能擦除, STTN字幕检测, LAMA, ProPainter, OpenCV
提高处理性能
新增CPU运行模式并优化多语言支持
修复Propainter模式部分视频报错

本次提交新增了CPU运行模式,适用于无GPU加速的场景。同时,优化了多语言支持,新增了日语、韩语、越南语等语言配置文件,并更新了README文档以反映新的运行模式和多语言支持。此外,修复了部分代码逻辑,提升了系统的稳定性和兼容性。
2025-05-22 08:41:59 +08:00

75 lines
2.2 KiB
Python

import multiprocessing
import threading
from enum import Enum
class Command(Enum):
FINISH = 0,
PROGRESS = 1,
LOG = 2,
MANAGE_PROCESS = 3,
ERROR = 4,
UPDATE_PREVIEW_WITH_COMP = 5,
class SubtitleRemoverRemoteCall:
"""
远程回调函数类,用于在多进程环境中传递回调函数
"""
def __init__(self):
self.queue = multiprocessing.Queue()
self.callbacks = {}
self.running = True
threading.Thread(target=self.run, daemon=True).start()
def run(self):
try:
while self.running:
cmd, args = self.queue.get(block=True)
if cmd == Command.FINISH:
break
callback = self.callbacks.get(cmd)
if callback:
callback(*args)
finally:
self.running = False
def stop(self):
self.running = False
def register_update_progress_callback(self, callback):
self.callbacks[Command.PROGRESS] = callback
def register_log_callback(self, callback):
self.callbacks[Command.LOG] = callback
def register_manage_process_callback(self, callback):
self.callbacks[Command.MANAGE_PROCESS] = callback
def register_update_preview_with_comp_callback(self, callback):
self.callbacks[Command.UPDATE_PREVIEW_WITH_COMP] = callback
def register_error_callback(self, callback):
self.callbacks[Command.ERROR] = callback
@staticmethod
def remote_call_update_progress(queue, progress, isFinished):
queue.put((Command.PROGRESS, (progress, isFinished,)))
@staticmethod
def remote_call_append_log(queue, *args):
queue.put((Command.LOG, (*args,)))
@staticmethod
def remote_call_finish(queue, *args):
queue.put((Command.FINISH, (None,)))
@staticmethod
def remote_call_catch_error(queue, e):
queue.put((Command.ERROR, (e,)))
@staticmethod
def remote_call_manage_process(queue, pid):
queue.put((Command.MANAGE_PROCESS, (pid,)))
@staticmethod
def remote_call_update_preview_with_comp(queue, *args):
queue.put((Command.UPDATE_PREVIEW_WITH_COMP, (*args,)))