How to merge mp4 files without re-encoding?
January 5, 2009 4:40 PM   Subscribe

How can I merge mp4's with out re-encoding, or losslessly?

I have 21 minute TV shows, divided up in to 3 clips seven minutes each. I need to merge them or join them into one large clip in mp4 format, the three clips are mp4 format. I tried Mediacoder, but that re-encodes them so it takes about a half hour.. I have 50 shows so thats not possible..
I need to merge the clips losslessly so it should be quick. I know YAMB can do this, but when I try, part 1's audio shows with video from part 2. I don't know how to fix it.
posted by ptsampras14 to Computers & Internet (13 answers total) 2 users marked this as a favorite
What kind of computer you have?
posted by rhizome at 5:20 PM on January 5, 2009

Response by poster: Windows Vista laptop
posted by ptsampras14 at 5:26 PM on January 5, 2009

MP4Box, specifically a frontend for it such as YAMB, should be able to do the job.
posted by zsazsa at 5:48 PM on January 5, 2009

YAMB can do this. If you're still stuck with YAMB, try Avidemux, and append the files as you would a series of AVI segments.
posted by Inspector.Gadget at 6:38 PM on January 5, 2009

Response by poster: Thanks alot Inspector.Gadget
That Avidemux works well it seems. I open the first mp4. Append the next to that. Append the third part. It says my files use B frames and makes me use this H.264 thing...but when I export the file, and I have to put a .mp4 extension on it (??), then I only get the audio,... idk why?
posted by ptsampras14 at 8:34 PM on January 5, 2009

I don't know if this works for video, but I do this all the time with mp3 audio: literally glue the files together using the DOS "copy" command.

Open a command prompt and type:

copy /b file1.ext + file2.ext + file3.ext + file4.ext filetotal.ext

... obviously inserting the filenames (e.g. yourvideo1.mp4) in place of file1.ext et al. Observe the "+" insertion carefully, noting in particular the LACK of one near the end.

Then trying playing the resulting file, you may be surprised to see it Just Works. MPEG framing is awesome that way.
posted by intermod at 9:25 PM on January 5, 2009

There's 2 issues at play here...

Firstly, mp4 ain't mp4. There's 2 different things that get called mp4.
  • Firstly, there's the container format ".mp4". Think of it like a mailing tube; you can put certain things in it that fit (e.g. posters), but not things that don't (e.g. books).
  • Secondly, there's the mp4 compression format. Think of it as the poster from the first point; it's been designed to be carried around in a mailing tube - but, for convenience, often gets carried around in something else like a generic folio case (e.g. .avi, .mkv).
Now, that out of the way, we can ignore the first one, the container type, for the time being.

That leaves us with mp4, the compression format. It's not just a single format, but rather a description of the ways various things can be compressed. To take the poster example further: posters can be various sizes, use various colours, be on different papers, have different borders, etc. These correspond to all the different options you have when creating mp4-compressed video - different image sizes, framerates, frame types, methods and limitations of arranging those frames, etc, etc. As well as all these options, there are some standard "pre-defined" options, e.g. MP4 ASP, MP4 AVC, etc - again, using the poster analogy, you could consider these to be like standard poster sizes, e.g. A3, A2, A1.

The real problem comes when it's time to put these all together. As far as I'm aware, the mp4 container can hold multiple videos, just like a mailing tube - but, unlike a mailing tube, they must all be created using exactly the same parameters*. Imagine a mailing tube that can hold several posters - but only if they're exactly the same size, use exactly the same colours, printed on exactly the same paper, etc. That's what the mp4 container is like.

For some reason, your videos aren't exactly the same. Even using the exact same codec with the exact same settings for each video won't necessarily guarantee videos that are exactly the same in the ways needed for them to be joined together. YAMP/MP4box is trying to jam everything into the one container, one after another, and is probably succeeding in some way - but the result is undefined. Video from one with audio from another, or audio with no video at all, seem to indicate this is the case.

At a guess, one or more of your videos has a different number of B-frames, or different B-frame packing, to the others. If the latter, you may be able to change the B-frame packing order across videos to match, but I suspect you're going to have to end up re-encoding all the videos.


On preview: intermod, I think you mean "the ability of players to handle broken MPEG framing is awesome that way" ;-)

(* OK, that's not quite true - afaik, it's possible to store them in the mp4 container as multiple video tracks, with switching from the end of one to the start of the next. In practice, I don't know of a player - hardware, or software - that implements this reliably.)
posted by Pinback at 9:38 PM on January 5, 2009

It says my files use B frames and makes me use this H.264 thing...but when I export the file, and I have to put a .mp4 extension on it (??), then I only get the audio,... idk why?

Editing with B-frames in H.264 is tricky. It's OK for you to choose the mode that doesn't have frame accuracy because all you're doing is appending files which have separate groups of pictures (GOPs); since you're not altering any data within each, frame accuracy is irrelevant. If you can't playback the file, make sure you've set MP4 as the output format and also saved to an MP4 extension AND that you have a H.264 Directshow decoder installed or are using VLC media player. You have an MP4 splitter and AAC audio decoder installed, as evidenced by the fact that you can hear audio from the files. As a last resort, post a sample or two somewhere and I'll try to find what the problem is.
posted by Inspector.Gadget at 10:52 AM on January 6, 2009

Response by poster: Thanks alot inspector gadget. I will private message you some information. If you can solve it, ill poste the answer here.
posted by ptsampras14 at 1:56 PM on January 6, 2009

Best answer: I was able to join the files provided using YAMB. Note that the second video file duplicates a few seconds from the end of the first, so that a brief part of the final scene is repeated. Here's what I did:

1) Open YAMB, click the "Editing" button in the sidebar, and double click "Click to join supported files".
2) Drag "1.mp4" and "2.mp4" into the main window in that order, leaving all streams enabled. Set the output to the same directory as "3.mp4", and click next. Wait for the process to complete and the lowermost-rightmost button to say "Finish".
3) At this point, you have a fully functional MP4 file ("3.mp4") with original audio sync and no video issues.

Avidemux will not produce a good result with this file because the audio was muxed with a delay. It cut the video and audio without difficulty, but it didn't detect the muxing delay in the original files and would have required manual adjustment of the audio delay to find an acceptable muxing delay value for the audio stream in the merged file. Without that annoying manual step, only joining the files with YAMB will reproduce an acceptable sync.

Finally, you should be able to see video in the new file if you can in the original files. The output parameters are fine for an H.264 file with AAC audio and will be accepted by CoreAVC, ffdshow, etc.
posted by Inspector.Gadget at 7:15 PM on January 6, 2009

Response by poster: I have MP4 Box. I have YAMB, I followed exactly your steps. It's not working for me.
posted by ptsampras14 at 5:49 PM on January 7, 2009

Are you joining the same files you used as a sample?
Try deleting the "YAMB.cfg" file in the YAMB directory and re-doing the process, and make sure you're using the latest YAMB.
posted by Inspector.Gadget at 1:41 PM on January 8, 2009

I am also have a lot of trouble concatonating my mp4 video files (taken with a Flip mino HD camera) into a single file. I have 12 snippets I want to string into a single file.
Following your suggestions, I tried the Dos Copy command with two files. The file grew to the size of the sum of the two, so I had hope, but the combined video stopped at the end of the first one. So . . .

I downloaded the latest YAMB (Yamb beta 2) and followed your instructions exactly, experimenting with only 2 of my 12 files, both with and without YAMB.cfg. Both ways, when I play the new combined file, instead of playing back to back in a single window, two windows open simulataneously playing both of the original files simultaneously!

I found your site after having a similar experience earlier in the evening muxing them with mkvmerge GUI v2.9.7 using their "add" function. Using their append function, I received an error that the files are not the same size, which you touched on.

The second window frame (and third when I combine 3 files) has the heading "VLC (hardward YUV DirectX output)" while the first has my newly created file name in the window frame heading.

Any ideas? Thank you!
posted by LeeAnnK at 11:05 PM on August 6, 2009

« Older How do I make those insulated patio covers?   |   XBMC + Xbox360 + Vista: Help me build a DVR. Newer »
This thread is closed to new comments.