Merge/Join MP4 Videos

Using cat on the Linux command line for a radically simple merge of multiple MPEG4 files, will not work. You can check VLC on the result, which will stop after the first part.

But this is not really surprising, the header is originating from the first file and still contains the information about the single file.

You can use mencoder to merge multiple MPEG4 files into a new MPEG4 container named complete.mp4 using the following shell script:


if [ -s "complete.mp4" ]; then
  echo "$0: complete.mp4 exists... bailing out."
  exit 1
exec mencoder "$@" -ovc copy -oac copy -of lavf -lavfopts format=mp4 -o complete.mp4

This script will deny to overwrite an existing non-empty complete.mp4. So drop a pre-existing file of that name first.

The copy “codec” for audio and video indicate, that these is no re-encoding, but just a re-wrapping into a new MPEG4 container file. No surprise that this cal to mencoder is only I/O bound and does not consume CPU time.