Merge multiple mp4 files into a single video via the terminal [duplicate]

I used the following bash command in one of my old scripts, and I am sure it works, provided

  • all videos have absolutely same size, frame-per-second, and codec.
  • you have mencoder installed
  • you specify the variables ${FPS} etc. before running the command, for example:

    FPS=24

    videoX=640

    videoY=480

Here is the command:

mencoder -really-quiet -ovc lavc -lavcopts vcodec=mjpeg -mf fps=${FPS} -vf scale=${videoX}:${videoY} -o $output_video_file_name video_*.avi

Here I assumed you have your videos under files "video_001.avi" "video_blah.avi" etc.


Install package gpac

apt install gpac

That has a utility MP4Box that can concatenate:

MP4Box [-keepsys] -cat FILE1+FILE2+FILE3 out.mp4

Ubuntu 14.04 LTS ymmv.