diff --git a/.gitignore b/.gitignore index 9f93633..24320ee 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ dist/ downloads/ eggs/ .eggs/ -lib/ lib64/ parts/ sdist/ diff --git a/lib/caddy_windows_amd64.exe b/lib/caddy_windows_amd64.exe new file mode 100644 index 0000000..b88607c Binary files /dev/null and b/lib/caddy_windows_amd64.exe differ diff --git a/lib/convert.py b/lib/convert.py new file mode 100644 index 0000000..e0f7bfd --- /dev/null +++ b/lib/convert.py @@ -0,0 +1,56 @@ +import subprocess +from pathlib import Path + + +def convert_to_h264(input_path: str, output_path: str = None) -> str: + """ + 将视频文件转码为 H.264 编码格式 + + Args: + input_path: 输入视频文件路径(相对或绝对路径) + output_path: 输出视频文件路径(可选,默认为输入文件同名_h264.mp4) + + Returns: + 转码后的视频文件路径 + + Raises: + FileNotFoundError: 输入文件不存在 + subprocess.CalledProcessError: FFmpeg 转码失败 + """ + input_path_all = Path("input/" + input_path).resolve() + output_path_all = Path("vid_h264/" + input_path).resolve() + + if not input_path_all.exists(): + raise FileNotFoundError(f"输入文件不存在:{input_path}") + + print(f"开始转码:{input_path_all}") + # if output_path is None: + output_path = str(output_path_all.with_name(f"{input_path_all.stem}_h264.mp4")) + # else: + # output_path = Path(output_path).resolve() + + cmd = [ + "ffmpeg", + "-i", str(input_path_all), + "-c:v", "h264_nvenc", # NVIDIA 硬件编码 + "-c:a", "aac", + "-b:a", "128k", + "-y", + str(output_path) +] + + result = subprocess.run(cmd, capture_output=True, text=True) + + if result.returncode != 0: + raise subprocess.CalledProcessError( + result.returncode, + cmd, + result.stdout, + result.stderr + ) + print(f"转码完成:{output_path}") + return str(output_path) + +if __name__ == "__main__": + convert_to_h264("VID_20251104_085655_024.AVI", "vid_h264/VID_20251104_085655_024_h264.mp4") + # convert_to_h264("input/short.AVI", "vid_h264/short_h264.mp4") diff --git a/lib/ffmpeg.exe b/lib/ffmpeg.exe new file mode 100644 index 0000000..70cae46 Binary files /dev/null and b/lib/ffmpeg.exe differ