-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.py
More file actions
56 lines (51 loc) · 1.74 KB
/
Copy pathworker.py
File metadata and controls
56 lines (51 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# gui/worker.py
# coding: utf-8
from PySide6.QtCore import QThread, Signal
from pathlib import Path
import threading
from core.transcoder import convert_video
class WorkerSignals:
"""信号占位,使用 QThread 自带的 signal 替代"""
progress = Signal(str, int, int)
finished = Signal(dict)
log = Signal(str)
class TranscodeWorker(QThread):
progress = Signal(str, int, int)
finished = Signal(dict)
log = Signal(str)
def __init__(self, file_path: Path, out_dir: Path, debug=False,
skip_validator=False, force_cpu=False, force_gpu=False):
super().__init__()
self.file_path = file_path
self.out_dir = out_dir
self.debug = debug
self.skip_validator = skip_validator
self.force_cpu = force_cpu
self.force_gpu = force_gpu
self.stop_event = threading.Event()
def run(self):
try:
result = convert_video(
self.file_path,
self.out_dir,
progress_callback=self.progress.emit,
debug=self.debug,
skip_validator=self.skip_validator,
force_cpu=self.force_cpu,
force_gpu=self.force_gpu,
stop_event=self.stop_event
)
self.finished.emit(result)
except Exception as e:
self.log.emit(f"[ERROR] {self.file_path.name}: {e}")
self.finished.emit({
"file": self.file_path.name,
"status": "FAILED",
"quality": None,
"retries": 0,
"method": "UNKNOWN",
"hdr": False
})
def stop(self):
"""外部调用以请求停止任务"""
self.stop_event.set()