gpt4 book ai didi

python - 使用重新编码与 FFMPEG 自动连接

转载 作者:行者123 更新时间:2023-12-04 22:47:56 27 4
gpt4 key购买 nike

我想使用 FFMPEG 连接相当大的视频列表。
另一个问题的以下答案非常相关:
https://stackoverflow.com/a/11175851/5065462 .
我在下面解释为什么它对我来说还不够。
我正在使用 MP4文件。
我正在使用 Windows 10。我想写一个 bat带参数的文件。然后我将通过 Command Prompt 调用此电话。或 PowerShell .

I want to automate Option 1 https://stackoverflow.com/a/11175851/5065462 to take as input a txt (or similar) file containing the filepaths for the videos to be concatenated.I'm happy with all the default [#:v] [#:a] options.


An alternative option is just to write a small program, either in Command Prompt or python3 is fine, which outputs a text string that I just copy+paste into cmd/PS.Unfortunately, I'm not sure how to use python to get filenames.



https://stackoverflow.com/a/11175851/5065462 中的选项 2看起来很棒。不幸的是,流编码与我的 mp4 有问题文件。我发现它们是通过在链接答案中使用选项 1 来修复的。但是,我不想每次都输入每个文件名。

最佳答案

以下 python 脚本将生成选项 1 中描述的命令。
要运行,请使用 python3 script_file.py video_directory output.mkv .video_directory应该只包含视频文件。

import argparse
import os

parser = argparse.ArgumentParser()
parser.add_argument("dir", help="the directory to the videos")
parser.add_argument("output", help="the name of the output file")
args = parser.parse_args()

files = os.listdir(args.dir)
cmd = "ffmpeg "
for file in files:
cmd += f"-i {file} "
cmd += '-filter_complex "'
for i in range(len(files)):
cmd += f"[{i}:v] [{i}:a] "
cmd += f'concat=n={len(files)}:v=1:a=1 [v] [a]" '
cmd += f'-map "[v]" -map "[a]" {args.output}'
print(cmd)
注意:用 os.system(cmd) 替换最后一行将直接从 python 运行命令。

关于python - 使用重新编码与 FFMPEG 自动连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67860006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com