Joining H264 *without* re-encoding
Solution 1
The Quicktime MP4 Codec choice has a "pass through" mode.
Here is a full detailed recipe to join two MP4 H264 videos, using Quicktime. Note that Quicktime X is not advanced enough yet, so use Quicktime 7 (an optional install with Snow Leopard):
- Open the two H264 videos in Quicktime 7. Let's suppose they are named video1.mp4 and video2.mp4.
- Working on video1.mp4, Select All, then Copy.
- Switch to video2.mp4, make sure the "cursor" is at the beginning of the video, then Paste. This inserts the content of video1.mp4 at the front of video2.mp4.
- This step is probably optional. "Save As" the modified video2.mp4. You will be able to save in .mov format only. I saved as a self-contained movie, but I suppose a reference movie would work too. I used the filename "video.mov".
- Select "Export" in the file menu to export video.mov to the joined H264 file. The "Export" to select is "Movie to MPEG-4". The preset is not important, I chose "LAN/Intranet". The preset is not important because we override it in the next step.
- Click on "Options" to reach the settings dialog. In the Video pane, "Video Format" is selected to be "H.264". Click on the menu, select "Pass Through". As expected, all the other options will get disabled.
- Click OK, then Save, and watch your joined file be saved at the speed of your hard disk.
You could alternatively use SimpleMovieX, a shareware video editor which exactly advertises this as a feature.
Solution 2
ffmpeg -i f1.mp4 -c copy -bsf h264_mp4toannexb f1.ts
ffmpeg -i f2.mp4 -c copy -bsf h264_mp4toannexb f2.ts
ffmpeg -i 'concat:f1.ts|f2.ts' -c copy -bsf aac_adtstoasc f3.mp4
How to concatenate flv file into one
Solution 3
MP4Box will do this for you:
MP4Box -cat File01.m4v -cat File02.m4v File-joined.m4v
MP4Box is cross-platform and works on OSX, however I tried this on Ubuntu Linux with H264 videos created by Handbrake for the iPhone 4S.
This works quite fast as the files are not re-encoded.
Related videos on Youtube
jdmuys
Updated on September 17, 2022Comments
-
jdmuys over 1 year
I have two halves of a single show in two .MP4 files, encoded in H264. I would like to join them without re-encoding.
Is this possible?
I managed to create a joined video as a Quicktime file (.mov) using Quicktime Pro, but then Quicktime Pro will not convert it back to .MP4 without re-encoding. This may be because looking inside the .mov file, the two H264 videos are in there still separated as individual "objects".
I am also struggling with MPEG StreamClip without reaching a real solution. But I may have missed something.
Note that I do not have the same issue with MPEG2 files. I can export them to a .MPEG container or a .TS file for example, and then I can join them without re-encoding using MPEG Streamclip.
Any suggestion welcome, preferably using Mac software.
-
Synetech about 13 yearsOf course the videos need to have the same aspects to be joined without re-encoding (same size, bitrate, etc.). You should be able to do it in VirtualDubMOD: open the MP4, then Append Segment.
-
-
jdmuys about 14 yearsThanks for the link. I could not try it as the site says this program does not support Snow Leopard. Moreover, I just found a working solution using Quicktime only (see my answer). Also, though I don't know in this case, some tools advertise joining video file but do so with full re-encoding, which is at best misleading.
-
agackovka almost 11 yearsWhat if it is m4v (non-h264 mp4), what bsf should be used?
-
guettli over 8 yearsWorks great. Use
sudo apt-get install gpac
to install it. You can use this command line if you have many files to join:MP4Box $(for file in single*m4v; do echo -cat $file; done) joined.m4v
-
Csaba Toth over 7 yearsSaving in mov I assume will need some form of re-encoding unfortunately.
-
Csaba Toth over 7 yearsI left off
-bsf aac_adtstoasc
for the concat command -
KittMedia over 6 yearsI needed to left off all
-bsf
arguments, then it worked for me. -
Jamie Cox about 6 yearsDoing this on MacOS 10.13.3, I omitted all the
-bsf xxx
stuff with good results. However the 2nd time I tried it, the second half of the combined movie was corrupted. It turns out that, for unknown reasons, Handbrake had encoded the two halves with different widths (640 vs. 636). I had used the same preset in both cases. Anyway, I went back and used Handbrake again on the 1st half, which now matched the 2nd half. The re-combined movie was okay. Tip: exiftool will display everything about an mp4/m4v file. -
Vadzim over 3 yearsSee also stackoverflow.com/questions/28922352/… on batch joining all files in a directory.