Python版-ts视频格式转换成mp4
- 电脑需要先安装ffmpeg
# 检查是否是否安装了ffmpeg
which ffmpeg
# 上一条命令执行后没有输出ffmpeg的路径,则执行安装ffmpeg
brew install ffmpeg
- Python代码
import subprocess
def convert_ts_to_mp4(input_file, output_file):
cmd = f'ffmpeg -i {input_file} -c:v copy -c:a copy {output_file}'
subprocess.call(cmd, shell=True)
print("ts视频文件已转换成mp4格式,请检查:{}".format(output_file))
input_file = '/Users/xxx/Downloads/第5节课.ts'
output_file = '/Users/xxx/Downloads/第6节课.mp4'
convert_ts_to_mp4(input_file, output_file)
- 输出入: