refactor: en
This commit is contained in:
@@ -11,7 +11,7 @@ class BaseTranscoder:
|
||||
def __init__(self, args, video_defaults, audio_defaults):
|
||||
self.input_path = Path(args.input).resolve()
|
||||
if not self.input_path.exists():
|
||||
raise FileNotFoundError(f"输入文件不存在: {self.input_path}")
|
||||
raise FileNotFoundError(f"Input file not found: {self.input_path}")
|
||||
|
||||
self.vencoder = args.vencoder
|
||||
self.aencoder = args.aencoder
|
||||
@@ -95,7 +95,7 @@ class BaseTranscoder:
|
||||
fps = self.orig_info.get("fps_str", "0/1") if self.orig_info else "0/1"
|
||||
|
||||
print(
|
||||
f"\n[Metrics] 启动 VMAF/PSNR 测试 (采样间隔: {n_subsample}, 线程数: {threads}, 强制帧率: {fps})..."
|
||||
f"\n[Metrics] Starting VMAF/PSNR test (Subsample interval: {n_subsample}, Threads: {threads}, Forced fps: {fps})..."
|
||||
)
|
||||
|
||||
out_w = new_info.get("width") if new_info else None
|
||||
@@ -105,7 +105,7 @@ class BaseTranscoder:
|
||||
orig_fps = self.orig_info.get("fps_str", "0/1") if self.orig_info else "0/1"
|
||||
out_fps = new_info.get("fps_str", "0/1") if new_info else "0/1"
|
||||
|
||||
# 使用滤镜链对齐帧率、分辨率和首帧时间戳
|
||||
# Use filter chain to align framerate, resolution, and first frame PTS
|
||||
filters_0 = []
|
||||
if out_fps != orig_fps:
|
||||
filters_0.append(f"fps={orig_fps}")
|
||||
@@ -151,7 +151,7 @@ class BaseTranscoder:
|
||||
)
|
||||
return vmaf, psnr
|
||||
except Exception as e:
|
||||
print(f"[Metrics Error] 无法解析 VMAF 日志: {e}")
|
||||
print(f"[Metrics Error] Failed to parse VMAF log: {e}")
|
||||
return "N/A", "N/A"
|
||||
|
||||
def _generate_log_content(self, encode_time, new_info, vmaf, psnr, extra_info=""):
|
||||
@@ -159,18 +159,18 @@ class BaseTranscoder:
|
||||
self.output_path.stat().st_size / self.input_path.stat().st_size
|
||||
) * 100
|
||||
content = (
|
||||
f"时间: {time.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||
f"输入: {self.input_path}\n"
|
||||
f"输出: {self.output_path}\n"
|
||||
f"Time: {time.strftime('%Y-%m-%d %H:%M:%S')}\n"
|
||||
f"Input: {self.input_path}\n"
|
||||
f"Output: {self.output_path}\n"
|
||||
f"{extra_info}"
|
||||
f"视频编码器: {self.vencoder} ({' '.join(self.v_params)})\n"
|
||||
f"音频编码器: {self.aencoder} ({' '.join(self.a_params)})\n"
|
||||
f"耗时: {encode_time:.2f} s\n"
|
||||
f"[元数据] {self.orig_info.get('codec','') if self.orig_info else ''} -> {new_info.get('codec','') if new_info else ''} | {self.orig_info.get('bitrate_kbps',0) if self.orig_info else 0:.0f} kbps -> {new_info.get('bitrate_kbps',0) if new_info else 0:.0f} kbps\n"
|
||||
f"[体积比] {size_ratio:.1f}%\n"
|
||||
f"Video encoder: {self.vencoder} ({' '.join(self.v_params)})\n"
|
||||
f"Audio encoder: {self.aencoder} ({' '.join(self.a_params)})\n"
|
||||
f"Time elapsed: {encode_time:.2f} s\n"
|
||||
f"[Metadata] {self.orig_info.get('codec','') if self.orig_info else ''} -> {new_info.get('codec','') if new_info else ''} | {self.orig_info.get('bitrate_kbps',0) if self.orig_info else 0:.0f} kbps -> {new_info.get('bitrate_kbps',0) if new_info else 0:.0f} kbps\n"
|
||||
f"[Size ratio] {size_ratio:.1f}%\n"
|
||||
)
|
||||
if self.run_metrics:
|
||||
content += f"[质量] VMAF: {vmaf} | PSNR(Y): {psnr}\n"
|
||||
content += f"[Quality] VMAF: {vmaf} | PSNR(Y): {psnr}\n"
|
||||
content += "-" * 50 + "\n"
|
||||
return content
|
||||
|
||||
@@ -180,7 +180,7 @@ class BaseTranscoder:
|
||||
if self.notify_mode == "none":
|
||||
return
|
||||
|
||||
subject = f"{extra_title}任务{'失败' if error else '完成'}: {self.input_path.name}"
|
||||
subject = f"{extra_title}Task {'failed' if error else 'completed'}: {self.input_path.name}"
|
||||
|
||||
if self.notify_mode == "mail":
|
||||
body = error if error else full_text
|
||||
@@ -191,19 +191,19 @@ class BaseTranscoder:
|
||||
check=True,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"[Notify Error] 邮件发送失败: {e}")
|
||||
print(f"[Notify Error] Failed to send email: {e}")
|
||||
|
||||
elif self.notify_mode == "notify":
|
||||
if error:
|
||||
body = error
|
||||
else:
|
||||
body = f"编码器: {self.vencoder}\n耗时: {encode_time:.1f}s"
|
||||
body = f"Encoder: {self.vencoder}\nTime elapsed: {encode_time:.1f}s"
|
||||
if self.run_metrics:
|
||||
body += f"\nVMAF: {vmaf}"
|
||||
try:
|
||||
subprocess.run(["notify-send", subject, body], check=True)
|
||||
except Exception as e:
|
||||
print(f"[Notify Error] DBus 通知发送失败: {e}")
|
||||
print(f"[Notify Error] DBus Failed to send notification: {e}")
|
||||
|
||||
def _cleanup(self):
|
||||
for temp_file in self.temp_files:
|
||||
|
||||
Reference in New Issue
Block a user