refactor: en
This commit is contained in:
@@ -7,7 +7,7 @@ from pathlib import Path
|
||||
|
||||
from core import BaseTranscoder
|
||||
|
||||
# 将当前目录加入 path 以引入 core
|
||||
# Add current directory to path to import core
|
||||
sys.path.append(str(Path(__file__).resolve().parent))
|
||||
|
||||
VIDEO_DEFAULTS = {
|
||||
@@ -29,10 +29,10 @@ class MediaTranscoder(BaseTranscoder):
|
||||
super().__init__(args, VIDEO_DEFAULTS, AUDIO_DEFAULTS)
|
||||
|
||||
def execute(self):
|
||||
print(f"--- 初始化转码任务 ---")
|
||||
print(f"--- Initializing Transcode Task ---")
|
||||
self.orig_info = self.get_media_info(self.input_path)
|
||||
if not self.orig_info:
|
||||
raise ValueError("无法读取输入文件元数据。")
|
||||
raise ValueError("Failed to read input file metadata.")
|
||||
|
||||
start_time = time.time()
|
||||
try:
|
||||
@@ -42,8 +42,8 @@ class MediaTranscoder(BaseTranscoder):
|
||||
self._encode_standard()
|
||||
except subprocess.CalledProcessError as e:
|
||||
self._cleanup()
|
||||
self._send_notification(error=f"转码失败,退出码: {e.returncode}", extra_title="转码")
|
||||
sys.exit(f"\n转码失败,退出码: {e.returncode}")
|
||||
self._send_notification(error=f"Transcode failed, exit code: {e.returncode}", extra_title="Transcode ")
|
||||
sys.exit(f"\nTranscode failed, exit code: {e.returncode}")
|
||||
|
||||
self._cleanup()
|
||||
encode_time = time.time() - start_time
|
||||
@@ -62,13 +62,13 @@ class MediaTranscoder(BaseTranscoder):
|
||||
f.write(log_content)
|
||||
|
||||
self._send_notification(encode_time=encode_time, new_info=new_info,
|
||||
vmaf=vmaf_score, full_text=log_content, extra_title="转码")
|
||||
vmaf=vmaf_score, full_text=log_content, extra_title="Transcode ")
|
||||
|
||||
print(f"\n转码完成!耗时: {encode_time:.2f} 秒")
|
||||
print(f"输出文件: {self.output_path}")
|
||||
print(f"\nTranscode completed! Time elapsed: {encode_time:.2f} s")
|
||||
print(f"Output file: {self.output_path}")
|
||||
|
||||
def _encode_with_external_audio(self):
|
||||
print("\n[Audio] 提取音频流并使用外部 fdkaac 编码...")
|
||||
print("\n[Audio] Extracting audio stream and encoding with external fdkaac...")
|
||||
temp_wav = self.out_dir / f"temp_{self.input_path.stem}.wav"
|
||||
temp_m4a = self.out_dir / f"temp_{self.input_path.stem}.m4a"
|
||||
self.temp_files.extend([temp_wav, temp_m4a])
|
||||
@@ -76,7 +76,7 @@ class MediaTranscoder(BaseTranscoder):
|
||||
subprocess.run(["ffmpeg", "-y", "-i", str(self.input_path), "-vn", "-c:a", "pcm_s16le", str(temp_wav)], check=True)
|
||||
subprocess.run(["fdkaac"] + self.a_params + [str(temp_wav), "-o", str(temp_m4a)], check=True)
|
||||
|
||||
print("\n[Video] 编码视频并混流...")
|
||||
print("\n[Video] Encoding video and muxing...")
|
||||
cmd = [
|
||||
"ffmpeg", "-y", "-i", str(self.input_path), "-i", str(temp_m4a),
|
||||
"-map", "0:v:0", "-map", "1:a:0", "-c:v", self.vencoder,
|
||||
@@ -88,7 +88,7 @@ class MediaTranscoder(BaseTranscoder):
|
||||
subprocess.run(cmd, check=True)
|
||||
|
||||
def _encode_standard(self):
|
||||
print("\n[Transcode] 使用 ffmpeg 同时处理视音频...")
|
||||
print("\n[Transcode] Processing video and audio simultaneously with ffmpeg...")
|
||||
cmd = ["ffmpeg", "-y", "-i", str(self.input_path), "-c:v", self.vencoder]
|
||||
if self.vf_string:
|
||||
cmd.extend(["-vf", self.vf_string])
|
||||
@@ -99,23 +99,23 @@ class MediaTranscoder(BaseTranscoder):
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="可配置视频转码脚本")
|
||||
parser.add_argument("-i", "--input", required=True, help="输入视频文件")
|
||||
parser.add_argument("-d", "--outdir", help="指定输出目录 (默认与输入文件同目录)")
|
||||
parser.add_argument("-cv", "--vencoder", choices=VIDEO_DEFAULTS.keys(), default="libsvtav1", help="视频编码器 (默认 libsvtav1)")
|
||||
parser.add_argument("-ca", "--aencoder", choices=AUDIO_DEFAULTS.keys(), default="opus", help="音频编码器 (默认 opus)")
|
||||
parser.add_argument("--vargs", type=str, default="", help="覆盖默认视频编码参数")
|
||||
parser.add_argument("--aargs", type=str, default="", help="覆盖默认音频编码参数")
|
||||
parser.add_argument("--fps", type=str, default="", help="指定帧率 (例如 60, 30000/1001)")
|
||||
parser.add_argument("--res", type=str, default="", help="指定分辨率,格式与scale滤镜相同 (例如 1920:1080)")
|
||||
parser.add_argument("--metrics", action=argparse.BooleanOptionalAction, default=True, help="结束后运行 VMAF/PSNR")
|
||||
parser.add_argument("--notify", choices=["none", "mail", "notify"], default="mail", help="完成后的通知方式 (默认 mail)")
|
||||
parser = argparse.ArgumentParser(description="Configurable video transcoding script")
|
||||
parser.add_argument("-i", "--input", required=True, help="Input video file")
|
||||
parser.add_argument("-d", "--outdir", help="Output directory (default: same as input)")
|
||||
parser.add_argument("-cv", "--vencoder", choices=VIDEO_DEFAULTS.keys(), default="libsvtav1", help="Video encoder (default: libsvtav1)")
|
||||
parser.add_argument("-ca", "--aencoder", choices=AUDIO_DEFAULTS.keys(), default="opus", help="Audio encoder (default: opus)")
|
||||
parser.add_argument("--vargs", type=str, default="", help="Override default video encoding parameters")
|
||||
parser.add_argument("--aargs", type=str, default="", help="Override default audio encoding parameters")
|
||||
parser.add_argument("--fps", type=str, default="", help="Specify framerate (e.g., 60, 30000/1001)")
|
||||
parser.add_argument("--res", type=str, default="", help="Specify resolution, same format as scale filter (e.g., 1920:1080)")
|
||||
parser.add_argument("--metrics", action=argparse.BooleanOptionalAction, default=True, help="Run VMAF/PSNR after completion")
|
||||
parser.add_argument("--notify", choices=["none", "mail", "notify"], default="mail", help="Notification method after completion (default: mail)")
|
||||
|
||||
try:
|
||||
transcoder = MediaTranscoder(parser.parse_args())
|
||||
transcoder.execute()
|
||||
except Exception as e:
|
||||
sys.exit(f"发生错误: {e}")
|
||||
sys.exit(f"Error occurred: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user