Converting MKV to iTunes Compatible [m4v/mp4]

If your like me you like processing videos. I recently got a few MKV videos that are really awesome in quality and from what I can tell looks like the main format for Blu-ray videos. Now I am not saying that this post it aimed at converting videos illegally. You do what you want with this. I also am not giving you the end-all-be-all solution for every single MKV video. If your smart and work with this stuff then you will be able to figure out the videos that don't quite work by tinkering with the settings.

First thing first, I have an Ubuntu 9.04 system running in 64-bit. I installed my ffmpeg from my posts (search ffmpeg, last posting). I am using an Intel Core2 Dou (not that this should matter).

Ok let's get started. Let's say my video is called Transformers2.mkv (Again, this is just an example, I love this movie). Also I am doing everything on the DESKTOP [/home/USER/Desktop]

Step 1. Installing additional apps using apt-get
sudo apt-get install mkvtoolnix gpac hexedit mplayer
Step 2. Reading the MKV file to see what you have.
mkvinfo Transformers2.mkv
NOTE: write down the FRAME rate of the video it might be weird like 23.976 or whatever, you will need it at the end.

NOTE: When you run this command you will see which tracks the video has. Let's say in my case Track 1 is the h.264 portion and Track 2 is the audio.

Step 3. Separate the tracks. This will not eat up your CPU but your disk will run wildly.
mkvextract tracks Transformers2.mkv 1:video.h264 2:audio.ac3
Step 4. HEXEDIT the video file to be compatible with iTunes [m4v/mp4]
hexedit video.h264
On the first line you should see this number combination:
"67 64 00 33"
change this to:
"67 64 00 29"

NOTE: This might not be exactly what you see but close. In my case let's say it was already what it needed to be changed to.

Step 5. Converting the Audio to AAC3 compatible. MKV's typically encoded with audio that just won't work with iTunes so we need to convert it to the something that it will understand. I am going to use ffmpeg to convert the audio.
ffmpeg -i audio.ac3 -acodec libfaac -ar 48000 -ab 448k -ac 6 -threads 0 audio.m4a
Step 6. Combining the video and audio tracks. Now here is where you need the frame rate from above.
MP4Box -add video.h264 -add audio.m4a -fps 23.976 Transformers2.mp4
Now once this is finished you should have a compatible video that will drag and drop right into iTunes. The video will not be much smaller then the original MKV as we did not convert or shrink the video just the audio. Check the beginning of the video or sync of sound and then the end of the video. It took me a couple of tries to get it in sync and also sounding really good. Have fun and hope this helps everyone out there.

Just a reminder I do not endorse stealing movies or ripping them, I just like to solve puzzles.

Comments

Popular posts from this blog

Console over SSH (ONTAP)

Cacti Monitor Server Step by Step Ubuntu

Brocade Zone Setup