修复:添加lib文件夹
This commit is contained in:
parent
6afea795f8
commit
ffcf785353
|
|
@ -10,7 +10,6 @@ dist/
|
||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
|
||||||
lib64/
|
lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -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")
|
||||||
Binary file not shown.
Loading…
Reference in New Issue