Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two H.264 encoded MPEG-4 files that I need to concatenate. I have been using MP4Box for this task by first ensuring the files are encoded identically (even went so far as to compare output from h264_parse on their video tracks) and then concatenating with this command:

MP4Box -cat file1.mp4 -cat file2.mp4 output_file.mp4

This works and the output file is playable, but on playback in Quicktime or VLC the second video's audio starts too soon, making the entire second part of the concatenated file out of sync.

I have tried reencoding the output through ffmpeg with -vcodec copy and -acodec copy but the sync issue persists.

I have also tried converting to MPEG-2 format first, concatenating with a simple cat file1.mpg file2.mpg > output.mpg and reencoding the result with ffmpeg. This was even worse.

I know that I can pass commands to MP4Box to adjust the start time of the audio track, but I am trying to do this programmatically for any input video (in the same encoding of course). I am looking for possible solutions that would not require human intervention / manual adjustments. Or, at least, an understanding of what is happening to make the second part of the concatenated video go out of sync.

share|improve this question
add comment

3 Answers 3

up vote 7 down vote accepted

I faced the same problem. For correct synchronization you have to write the MP4Box command as follows:

MP4Box -add file1.mp4 -cat file2.mp4 -new output_file.mp4

instead of using -cat use -add before the first video. The remaining options are correct and you can put -new before the output video parameter.

share|improve this answer
    
Thank you! I got a freeze frame where file1 ended and file2 began, but audio kept playing. After changing -cat … -cat to -add … -cat, I get both audio and video, though file2 is out of sync. –  Henrik N Jun 30 '12 at 19:26
add comment

Try using the Matroskra video container (MKV).

Firstly, you need mkvtoolnix. Download and install it, then you need to fire up mkvmerge GUI (unless you like command-line tools, which is fine by me - although you might want to look at the file linking section of the mkvmerge documentation).

Add your first file by clicking "add". Then, click on "append", and open your second file. Set the output file, hit "Start muxing" at the bottom, and away you go!

If the container is unsuitable for your needs, you can reencode it, or try to convert it to some other format... Although MKV is a very lovely container!

share|improve this answer
    
I had been having problems with MP4Box appending mp4 files. The audio was getting messed up. I tried mkvmerge.exe from this package and it worked great! –  cdavidyoung Aug 1 '12 at 22:00
    
»Try using the Makostra video container.« - Isn't it called Matroska, simplified writing for Matryoshka? –  Lumi Mar 27 '13 at 12:20
    
@Lumi good catch, thanks - post edited. –  Breakthrough Mar 27 '13 at 12:27
add comment

From the mkvtoolnix package use mkvmerge:

mkvmerge -o "output file" "input file" +"appended file"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.