How can I merge or concatenate two or more MP4 files creating another MP4 file? [duplicate]

Solution 1:

MP4Box can do this, though you might want to use a GUI for it like YAMB or My MP4Box GUI. (N.B.: It's not my program personally, that's just the name.) MP4Box binaries for Windows are available from this site.

Example:

MP4Box -tmp $HOME -add vid.01.m4v \
    -cat vid.02.m4v -cat vid.03.m4v vid-out.mp4

Solution 2:

I'd reccomend usind ffmpeg, which is available for Mac OS X, Linux and Windows.

Here's a good examaple on how to concatenate two movies: http://www.ffmpeg.org/faq.html#SEC27

In the last step, you just need to make sure you make an MP4 container, for the resulting file.

Solution 3:

You can try doing this with ffmpeg:

mkfifo temp0 temp1
ffmpeg -i input0.mp4 -c copy -bsf h264_mp4toannexb -f mpegts -y temp0 2> /dev/null & \
ffmpeg -i input1.mp4 -c copy -bsf h264_mp4toannexb -f mpegts -y temp1 2> /dev/null & \
ffmpeg -f mpegts -i "concat:temp0|temp1" -c copy -absf aac_adtstoasc output.mp4

This doesn't re-encode anything, it places them in a new transport stream container, which makes them more easy to concatenate, and then concatenates them back into an MP4. If output.mp4 already exists, the command will fail. The version above uses named pipes, it you're on a system that doesn't support those you'd have to use intermediate files:

ffmpeg -i input0.mp4 -c copy -bsf h264_mp4toannexb temp0.ts
ffmpeg -i input1.mp4 -c copy -bsf h264_mp4toannexb temp1.ts
ffmpeg -i "concat:temp0.ts|temp1.ts" -c copy -absf aac_adtstoasc output.mp4

Solution 4:

Update: Just checked avidemux as I had it installed, after reading that other answer. It’s what you are looking for (didn’t think it can do MP4 because of its name…).

I think VirtualDubMod is mp4-capable, I didn’t use it though so I dunno for sure.

You may want to check out MeGUI. It’s a rather complex and feature-rich app and tools.

The tool for embedding in a container (mp4 in your case) is called muxer, that one can probably not concatenate them though.

You can use it in combination with VirtualDub. Virtualdub to concatenate the video streams, and the muxer to make it an mp4 again (without having to reencode).

Solution 5:

I'm doing it with mencoder, after having converted them to avi with ffmpeg

here's a simple script, assuming you have 15 files, named 01.mp4 ... 15.mp4

#!/bin/bash
for j in `seq -w 1 15`;
do
    echo converting file $j.avi
    ffmpeg -i $j.mp4 $j.avi        

    echo adding file $j.avi to list
    z="$z $j.avi"
done 

echo doing append
mencoder -oac copy -ovc copy $z -o all.avi

cheers