I'm currently trying to merge multiple video files with a python script using ffmpeg and ffmpy. The names of the files are being written into a file list, as suggested by the ffmpeg concatenate wiki.
In my example I'm only using two files, but in practice, there will be several hundert files, that's why I'm choosing the file list approach.
My current code looks like this:
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()
So the code I want to run with ffmpy is
ffmpeg -f concat -safe 0 -i video_list.txt -c copy output.avi
But unfortunately my script isn't working and the resulting error is
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'
Any hints why the command isn't working the way it should? Am I missing something regarding the command formatting for ffmpy?
Thank you.