diff --git a/tc-2pass.py b/tc-2pass.py index 13dd563..573b45d 100755 --- a/tc-2pass.py +++ b/tc-2pass.py @@ -5,8 +5,7 @@ import time import subprocess from pathlib import Path -sys.path.append(str(Path(__file__).resolve().parent)) -from transcode_core import BaseTranscoder +from core import BaseTranscoder VIDEO_DEFAULTS = { "libx265": ["-preset", "slow", "-pix_fmt", "yuv420p10le", "-x265-params", "aq-mode=3:aq-strength=0.8:psy-rd=1.0"], @@ -19,6 +18,7 @@ AUDIO_DEFAULTS = { "opus": ["-c:a", "libopus", "-b:a", "128k", "-vbr", "on"], } + class MediaTranscoder2Pass(BaseTranscoder): def __init__(self, args): super().__init__(args, VIDEO_DEFAULTS, AUDIO_DEFAULTS) @@ -59,7 +59,8 @@ class MediaTranscoder2Pass(BaseTranscoder): with open(self.log_path, "a", encoding="utf-8") as f: f.write(log_content) - self._send_notification(encode_time=encode_time, new_info=new_info, vmaf=vmaf_score, full_text=log_content, extra_title="2-Pass转码") + self._send_notification(encode_time=encode_time, new_info=new_info, vmaf=vmaf_score, + full_text=log_content, extra_title="2-Pass转码") print(f"\n转码完成!耗时: {encode_time:.2f} 秒") print(f"输出文件: {self.output_path}") @@ -111,6 +112,7 @@ class MediaTranscoder2Pass(BaseTranscoder): except Exception as e: print(f"[Cleanup Warning] 无法删除临时日志 {log_file.name}: {e}") + def main(): parser = argparse.ArgumentParser(description="2-Pass 可配置视频转码脚本") parser.add_argument("-i", "--input", required=True, help="输入视频文件") @@ -131,5 +133,6 @@ def main(): except Exception as e: sys.exit(f"发生错误: {e}") + if __name__ == "__main__": main() diff --git a/tc.py b/tc.py index a3d2dc6..38652cd 100755 --- a/tc.py +++ b/tc.py @@ -5,9 +5,10 @@ import time import subprocess from pathlib import Path +from core import BaseTranscoder + # 将当前目录加入 path 以引入 core sys.path.append(str(Path(__file__).resolve().parent)) -from transcode_core import BaseTranscoder VIDEO_DEFAULTS = { "hevc_nvenc": ["-preset", "p7", "-tune", "uhq", "-rc", "vbr_hq", "-cq", "24", "-spatial-aq", "1", "-multipass", "2", "-pix_fmt", "p010le"], @@ -22,6 +23,7 @@ AUDIO_DEFAULTS = { "opus": ["-c:a", "libopus", "-b:a", "128k", "-vbr", "on"], } + class MediaTranscoder(BaseTranscoder): def __init__(self, args): super().__init__(args, VIDEO_DEFAULTS, AUDIO_DEFAULTS) @@ -59,7 +61,8 @@ class MediaTranscoder(BaseTranscoder): with open(self.log_path, "a", encoding="utf-8") as f: f.write(log_content) - self._send_notification(encode_time=encode_time, new_info=new_info, vmaf=vmaf_score, full_text=log_content, extra_title="转码") + self._send_notification(encode_time=encode_time, new_info=new_info, + vmaf=vmaf_score, full_text=log_content, extra_title="转码") print(f"\n转码完成!耗时: {encode_time:.2f} 秒") print(f"输出文件: {self.output_path}") @@ -94,6 +97,7 @@ class MediaTranscoder(BaseTranscoder): cmd.extend([str(self.output_path)]) subprocess.run(cmd, check=True) + def main(): parser = argparse.ArgumentParser(description="可配置视频转码脚本") parser.add_argument("-i", "--input", required=True, help="输入视频文件") @@ -113,5 +117,6 @@ def main(): except Exception as e: sys.exit(f"发生错误: {e}") + if __name__ == "__main__": main()