Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG Concat protocol does not combine video files

Tags:

ffmpeg

So I've tried using the following command to combine 2 video files with the same codec:

ffmpeg -i "concat:/home/mike/downloads/a1.mp4|/home/mike/downloads/a2.mp4" -c copy "/home/mike/downloads/output.mp4"

The the result: output.mp4 only contains video from a1.mp4. I also tried 2 or more file but the result is the same. What could be the possible cause for this? Please help

Mike

like image 592
Michael Erwin Avatar asked Feb 10 '23 01:02

Michael Erwin


1 Answers

You cannot concatenate mp4 files directly with the concat protocol because the format doesn't support it. This is intended for mpg or mpeg-ts and similar.

You can do it if you pass by one of those formats:

ffmpeg -i input1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts
ffmpeg -i input2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2.ts
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4

The alternative is to use the concat demuxer which is more flexible (you still need the same codecs for the input files but it can use different containers):

ffmpeg -f concat -i mylist.txt -c copy output

Where mylist.txt is something like:

# this is a comment
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'

Documentation

like image 118
aergistal Avatar answered Mar 03 '23 19:03

aergistal