4

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

1 Answer 1

9

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.