I have a folder with 20+ video files and I need to merge them to make one long video file. How can I achieve this using FFMPEG in Python?
I know the following command
ffmpeg -vcodec copy -isync -i \ "concat:file1.mp4|file2.mp4|...|fileN.mp4" \
outputfile.mp4
But I'd rather not type all the names of the 20+ files.
This is what I've ended up using...
find *.mp4 | sed 's:\ :\\\ :g'| sed 's/^/file /' > fl.txt; ffmpeg -f concat -i fl.txt -c copy output.mp4; rm fl.txt
It's ugliness pains me but it seems to work ok and it handles spaces in the file names. Also, not sure why OP was asking about python - no need to use something lovely like python when some dirty old bash/sed will do the trick! ;)
ps: I know this is an old post but if googling "ffmpeg concat" brought me here it will probably bring other poor souls here too. Note the above will probably only work if all your files have the same settings/codecs.
pps: @Stackdave says he managed to delete his video folder with this back in the day! I've really no idea how that could have happened and I've had no complaints since but as always when copying and pasting randomish snippets of bash you found on the internet Caveat Emptor!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With