我目前正在尝试使用 ffmpeg 和 ffmpy 将多个视频文件与 python 脚本合并。正如ffmpeg concatenate wiki所建议的那样,文件的名称被写入文件列表。
在我的示例中,我只使用了两个文件,但实际上,会有几个 hundert 文件,这就是我选择文件列表方法的原因。
我当前的代码如下所示:
import os
import ffmpy
base_dir = "/path/to/the/files"
# where to seek the files
file_list = open("video_list.txt", "x")
# scan for the video files
for root, dirs, files in os.walk(base_dir):
for video_file in files:
if video_file.endswith(".avi"):
file_list.write("file './%s'\n" % video_file)
# merge the video files
ff = ffmpy.FFmpeg(
global_options={"-f",
"concat ",
"-safe",
"0"},
inputs={file_list: None},
outputs={"-c",
"copy",
"output.avi"},
)
ff.run()
所以我想用 ffmpy 运行的代码是
ffmpeg -f concat -safe 0 -i video_list.txt -c copy output.avi
但不幸的是,我的脚本不起作用,导致的错误是
Traceback (most recent call last):
File "concat.py", line 20, in <module>
"output.avi", }
File "/usr/lib/python3.7/site-packages/ffmpy.py", line 54, in __init__
self._cmd += _merge_args_opts(outputs)
File "/usr/lib/python3.7/site-packages/ffmpy.py", line 187, in _merge_args_opts
for arg, opt in args_opts_dict.items():
AttributeError: 'set' object has no attribute 'items'
任何提示为什么该命令没有按应有的方式工作?我是否遗漏了有关 ffmpy 的命令格式的内容?
谢谢你。