Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge all the videos in a folder to make a single video file using FFMPEG

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.

like image 439
X_1 Avatar asked Mar 08 '15 02:03

X_1


1 Answers

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!

like image 113
Roger Heathcote Avatar answered Sep 19 '22 13:09

Roger Heathcote