Joining H264 *without* re-encoding

39

24

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.

jdmuys

Posted 2010-04-21T17:21:21.177

Reputation: 811

1Of 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. – Synetech – 2011-03-10T06:06:21.817

Answers

2

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):

  1. Open the two H264 videos in Quicktime 7. Let's suppose they are named video1.mp4 and video2.mp4.
  2. Working on video1.mp4, Select All, then Copy.
  3. 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.
  4. 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".
  5. 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.
  6. 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.
  7. 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.

jdmuys

Posted 2010-04-21T17:21:21.177

Reputation: 811

1Saving in mov I assume will need some form of re-encoding unfortunately. – Csaba Toth – 2016-11-08T08:13:45.637

41

ffmpeg -i q.mp4 -c copy -bsf h264_mp4toannexb q.ts

ffmpeg -i r.mp4 -c copy -bsf h264_mp4toannexb r.ts

ffmpeg -i "concat:q.ts|r.ts" -c copy -bsf aac_adtstoasc qr.mp4

How to concatenate flv file into one

Steven Penny

Posted 2010-04-21T17:21:21.177

Reputation: 7 294

2I left off -bsf aac_adtstoasc for the concat command – Csaba Toth – 2016-11-08T08:44:17.147

I needed to left off all -bsf arguments, then it worked for me. – KittMedia – 2017-11-09T18:36:15.480

Doing 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. – Jamie Cox – 2018-03-10T20:40:53.293

What if it is m4v (non-h264 mp4), what bsf should be used? – Edison – 2013-06-12T23:12:35.343

16

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.

thinkOfaNumber

Posted 2010-04-21T17:21:21.177

Reputation: 271

1Works 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 – guettli – 2015-11-05T14:54:28.363

0

Use mkvtoolnix . Then open "mkvtoolnix-gui.exe" (in windows 8.1 64bits it is located at : C:\Program Files\MKVToolNix\mkvtoolnix-gui.exe). Add the first file. Then select this first file and right click "append files" and select the file(s) that you want to merge. Maybe change the destination folder and filename. Then finally click on "start multiplexing".

Erb

Posted 2010-04-21T17:21:21.177

Reputation: 255

0

I think this should be possible, although the two parts might need to be the "same" certain ways (resolution, etc) in order for the join to work. This sounds like it will probably be the case with your situation.

You could try this tool: http://www.smlabs.net/tsmuxer_en.html ... I have not used it but it specifically lists joining files as part of its feature set and H.264 is one of the supported encodings.

Zac Thompson

Posted 2010-04-21T17:21:21.177

Reputation: 887

Thanks 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. – jdmuys – 2010-04-23T06:12:27.043

My apologies; I misread that bit on the site. Glad you found a simpler approach -- it did seem strange that it would be necessary to get a special tool for this. – Zac Thompson – 2010-04-23T07:24:51.640