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?
-
3Kinda funny this specifically states "via the terminal" yet all the answers in the supposed duplicate are GUI tools.– Tobias JMar 31, 2017 at 15:58
2 Answers
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.
-
1OK, 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.– MasoudJan 19, 2016 at 12:53 -
3This command worked for me:
mencoder -oac pcm -ovc copy -o output_file.mp4 input_file1.mp4 input_file2.mp4
– MuraliJul 1, 2017 at 16:38 -
This worked. mencoder -oac pcm -ovc copy -o output_file.mp4 input_*.mp4– AveeshOct 9, 2019 at 18:48
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.
-
At the end of the first video the image freezes yet the audio for the second continues to play..... not ideal Sep 8, 2015 at 11:02
-
1I 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"
– JdeHaanSep 8, 2015 at 11:05 -
1