python - 在 python ffmpeg 上剪切、连接和转换

标签 python ffmpeg

我想在 python 中使用下面的命令行代码。它首先从视频中剪切部分,然后将它们组合起来。之后,它将视频格式 .ts 更改为 .mp4。如何在 python 代码中使用它?
命令行代码:

ffmpeg -i input.ts  \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/intro.ts && ffmpeg -i input.ts  \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/first.ts && ffmpeg -i input.ts \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/second.ts && ffmpeg -f concat -safe 0 -i Files/mylist.txt -c copy output.ts \
&& ffmpeg -i output.ts -c copy output.mp4

最佳答案

你可以尝试使用 python 来运行 cmd 命令。

import os

command = """ffmpeg -i input.ts  \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/intro.ts && ffmpeg -i input.ts  \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/first.ts && ffmpeg -i input.ts \
-ss 00:00:10 -to 00:00:20 \
-c:v copy -c:a copy Files/second.ts && ffmpeg -f concat -safe 0 -i Files/mylist.txt -c copy output.ts \
&& ffmpeg -i output.ts -c copy output.mp4"""
os.system(command)

关于python - 在 python ffmpeg 上剪切、连接和转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65981963/

相关文章:

php - 使用 FFMPEG 转换为具有最大浏览器兼容性的 MP4

python - 使用 for 循环改变 python 数组中的元素

python - 像素级多类分割,关于训练全零像素图像的问题

ffmpeg - qt-faststart 命令永远不会完成

video - 是否有从静止图像创建视频内容的编程方式?

php - Jw 播放器未播放 mime 类型为 "audio/x-mpeg"的 mp3

python - 如何模拟数据库的方法

python - 用户输入并陷入 while 循环

python - 错误 : unknown type name ‘class’ using SWIG

video - 了解ffmpeg输入流信息