Tuesday, September 11, 2012

Joining Mp4 Files

The following parts are independent.

PROCEDURE 1

Try the simple one first. Just copy the video and the audio stream.

mencoder file1.mp4 file2.mp4 -ovc copy -oac copy -of lavf format=mp4 -o output.mp4

Sometimes this might not work. Many times the audio copy would fail with the errors like.


Audio format 0x4134504d is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.


In these cases it is better to re-encode the audio with lame.


mencoder file1.mp4 file2.mp4 -ovc copy -oac mp3lame -of lavf format=mp4 -o output.mp4


If we want free format encoding we could also use FAAC encoder (Freeware Advanced Audio Coder.). In this example the video codec used in also a free format to encode to H.264 HD format.

mencoder video1.mp4 video2.mp4 -o video3.mp4 -of lavf -lavfopts format=mp4 -vf harddup -oac lavc -ovc lavc -lavcopts acodec=libfaac:vcodec=libx264

PROCEDURE 2


MP4Box -add file1.mp4 -add file2.mp4 output.mp4



PROCEDURE 3


If your mp4 files are in a standard codec you might be able to get the free avidemux to join them without reencoding. To join them you open first file, then append every other file you want to join to it.
If the files are in the mkv codec, then you might need "total video converter" I had to use this program to convert the files to xvid then use avidemux to join them, but it kept the audio in sync and the quality loss was minimal.

avidemux has excellent editing and cropping tools for working on avi's.

http://fixounet.free.fr/avidemux/screenshots.html


PROCEDURE 4

To merge subtitles into an MP4 video file, you need to download two very useful tools: MP4Box and its GUI interface called Yamb.http://beans.seartipy.com/2008/01/11/step-3b-merginghardcoding-subtitles-with-mp4-files-using-yambmp4box/
I am making this post in response to one of the comments left on my previous post explaining how to hard-code (or merge) the subtitles into an AVI(DivX/XviD) video file. I was asked what tools can be used to merge subtitles with MP4 video files and below is the complete procedure to do the merging using MP4Box and Yamb.

To merge subtitles into an MP4 video file, you need to download two very useful tools: MP4Box and its GUI interface called Yamb.

Download MP4Box

Download Yamb

Both the tools can be extracted to any location of your preference. I have extracted the contents of Yamb-2.0.0.8.zip to H:\PortableApps\Yamb and have extracted and copied MP4Box.exe too to the same folder. This is how it looks on my computer:

Next thing you need to do is to tell Yamb where MP4Box is located. To do that, run Yamb from its folder, click on the Settings icon, double-click on the entry that starts with “Advanced settings for Yamb…”.

Enter the path where you have extracted the MP4Box executable in the Location: text box. In my example, it looks like this:

Click Next.

Now you are ready to try merging subtitles into an MP4 file. Select the Creation icon this time and double-click on the first entry that starts with “Click to create and MP4…”.

Click the Add button first time to add the MP4 file and then click the Add button a second time to select the subtitle file. The window should like something like this:

Remember to change the output file name(like I did) in the Output text box located at the bottom of the window if you don’t want to overwrite your input file with the merged output file. Click Next.
The following screenshot shows Yamb processing your request. It took less than 2 minutes on my computer to finish the job of merging subtitles into a 40 minute MP4 video file.

Click Finish when done to quit Yamb or click Back if you want to do more merging operations. The produced MP4 output file with merged subtitles:


End Notes

You can use the MP4Box directly from the command line if you wish: the command syntax is really very simple, and you can actually do a lot more stuff using this tool. So do explore more about it over the Internet.

PROCEDURE 5

Install gpac packages to install MP4Box tools.
sudo apt-get install gpac
Once you’ve done it, you can use the Mp4Box command to concatenate the files together:

MP4Box -cat file_01.m4v -cat file_02.m4v -cat file_03.m4v -new final.m4v

This will create a merged m4v file ready do be used.
http://ukumars.wordpress.com/2009/12/31/how-to-joinmerge-mp4-files-in-ubuntu/


PROCEDURE 6

ls -x

This will list files sequentially in a single block (which might spill over several lines depending on the size of the terminal window).

 file1.mp4 file2.mp4  file3.mp4 file4.mp4  file5.mp4 file6.mp4  file7.mp4 file8.mp4  ....

Just select and middle click paste them after the cat command.

cat file1.mp4 file2.mp4 ... > joined.mp4

The joined file would play fine in mplayer but the timeline would be all wrong and the subtitles would get screwed up. Fix this by running fix index with mencoder or vlc.


mencoder -idx joined.mp4 outpufile.mp4



See also http://kheyali.blogspot.com/2012/04/split-and-merge-files.html

1 comment:

keithservick said...

I use iDealshare VideoGo to join MP4 files, I like its join video without re-encoding feature.
Step by step guide at http://www.idealshare.net/mp4-joiner-merge-mp4-files-on-mac-windows.html

It also helps to:
Join other video formats like join AVI, VOB, MOV, RMVB, FLV, MKV, MPG, 3GP, MPEG, M2TS, MTS, WMV, ASF, etc as well as MP4.
Join audio files like join MP3, WMA, FLAC, AAC, OGG, WAV, M4A, AIFF, MP2 and etc

OK GOOGLE on Samsung Galaxy S7 doesn’t work

To make Ok Google detection work on Galaxy S7 (Galaxy series phones) we need to perform a couple of steps. 1. As long as Samsung S vo...