Sometimes I need to concatenate several mp4 files together. ffmpeg is a good tool for this job.
On OSX, it's easy to install using Homebrew:
brew install ffmpeg
If you have MP4 files, these could be losslessly concatenated by first transcoding them to mpeg transport streams.
Source – https://trac.ffmpeg.org/wiki/Concatenate
Say we have 2 mp4 files to concatenate or join together, first we transcode each of these into an intermediate format:
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
After that we can concatenate these together using the following:
ffmpeg -i "concat:intermediate1.ts|intermediate2.ts" -c copy -bsf:a aac_adtstoasc output.mp4
For more files, just pipe separate the additional files here:
"concat:intermediate1.ts|intermediate2.ts"