import argparse
import subprocess
import os
parser = argparse.ArgumentParser()
parser.add_argument("-i","--input", required=True , help="input video file")
args = parser.parse_args()
input_file = args.input
file_path, file_name = os.path.split(input_file)
input_name, ext = os.path.splitext(file_name)
if not input_name:
input_name = input_file
output_filename = "h264." + input_name + ".mp4"
output_file = os.path.join(file_path, output_filename)
ffmpeg_command = [
"ffmpeg",
"-i", input_file,
"-vcodec", "h264",
"-acodec", "aac",
"-strict", "-2",
output_file
]
result = subprocess.run(ffmpeg_command)
if result.returncode != 0:
print("ffmpeg failed with error:", result.stderr)
else:
print("ffmpeg succeeded")
ffmpeg转码
2023-07-27