8

I am trying to concatenate a directory full of .mp4 files into a single video through the terminal. I have found plenty of methods that say they can do this but either require FFmpeg (which, to the best of my knowledge, is no longer supported) or they simple do not work. Is it still possible to do this and if so how might I go about doing it?

  • 3
    Kinda funny this specifically states "via the terminal" yet all the answers in the supposed duplicate are GUI tools. – Tobias J Mar 31 '17 at 15:58
3

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.

|improve this answer|||||
  • 1
    OK, now I see that there was a lot of bloat in my answer above. This is the bare minimum you need to merge multiple videos: mencoder -c copy video_*.avi -o final.avi The input videos are sorted alphabetically. If you want a particular order, change the names to (for example) 01.avi 02.avi etc. to make sure you get the desired order. – Masoud Jan 19 '16 at 12:53
  • 2
    This command worked for me: mencoder -oac pcm -ovc copy -o output_file.mp4 input_file1.mp4 input_file2.mp4 – Murali Jul 1 '17 at 16:38
  • This worked. mencoder -oac pcm -ovc copy -o output_file.mp4 input_*.mp4 – Aveesh Oct 9 '19 at 18:48
4

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.

|improve this answer|||||
  • At the end of the first video the image freezes yet the audio for the second continues to play..... not ideal – Blunderchips Sep 8 '15 at 11:02
  • 1
    I have the following "guaranteed to work"(tm), but that requires converting mp4 to ts: avconv -ss 0 -i "INPUT.mp4" -vcodec libx264 -acodec aac -bsf:v h264_mp4toannexb -f mpegts -strict experimental -y "OUTPUT.ts" avconv -i concat:"OUTPUT1.ts|OUTPUT2.ts" -c copy -bsf:a aac_adtstoasc -y "FINAL.mp4" – JdeHaan Sep 8 '15 at 11:05
  • 1
    MP4Box -add file1.mp4 -cat file2.mp4 output.mp4 – joan16v May 29 '19 at 10:31

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