使用 Python 将 ts 转换为 mp4 [英] Converting ts to mp4 with Python

查看:82
本文介绍了使用 Python 将 ts 转换为 mp4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过感觉像是一百万个 ffmpeg 包装器,但它们似乎都不起作用,所以我想我会在这里问.如何使用 Python 无损地将 .ts 文件转换为 .mp4?尽管 ffmpeg bin 和 .exe 都在 PATH 中并且遵循了每个安装步骤,但我尝试过的每个 ffmpeg 包装器都没有工作.我可以使用一个简单的包装器吗?我讨厌要求一步一步,但我一定做错了什么,对吗?

I've tried what feels like a million ffmpeg wrappers and none of them seem to work, so I thought I'd ask here. How would one go about losslessly converting .ts files to .mp4 with Python? Every ffmpeg wrapper I've tried has not worked despite both the ffmpeg bin and .exe being in the PATH and every installation step followed. Is there a simple wrapper that I can use? I hate to ask for a step-by-step, but I must be doing something wrong, right?

推荐答案

既然您的转换要求是特定的,为什么不直接从 Python 中调用 ffmpeg 并使用 subprocess.run() (Python >= 3.5) 或 subprocess.call() (Python<3.5)?

Since your conversion requirements are specific, why don't you just call ffmpeg directly from Python with subprocess.run() (Python >= 3.5) or subprocess.call() (Python < 3.5)?

import subprocess

infile = 'video.ts'
outfile = 'video.mp4'

subprocess.run(['ffmpeg', '-i', infile, outfile])

如果需要,您可以捕获输出.请参阅相关文档.

You can capture the output if wanted. Refer to the documentation for that.

这篇关于使用 Python 将 ts 转换为 mp4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆