使用重新编码与 FFMPEG 自动连接
Automated Concatenate with FFMPEG Using Re-Encode
我想使用 FFMPEG 连接相当大的视频列表。
另一个问题的以下答案高度相关:
。
我在下面解释为什么这对我来说还不够。
我正在使用 MP4
个文件。
我正在使用 Windows 10。我想写一个带参数的 bat
文件。然后我会从 Command Prompt
或 PowerShell
.
调用它
I want to automate Option 1 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.
中的选项 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。
我想使用 FFMPEG 连接相当大的视频列表。
另一个问题的以下答案高度相关:
。
我在下面解释为什么这对我来说还不够。
我正在使用 MP4
个文件。
我正在使用 Windows 10。我想写一个带参数的 bat
文件。然后我会从 Command Prompt
或 PowerShell
.
I want to automate Option 1 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
orpython3
is fine, which outputs a text string that I just copy+paste intocmd/PS
. Unfortunately, I'm not sure how to usepython
to get filenames.
中的选项 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。