View Single Post
Old 2007-05-17, 10:15   Link #1
martino
makes no files now
 
 
Join Date: May 2006
MKV to MP4 Guide

Recently there has been an upsurge of people asking how to convert MKV to MP4 so that they can play it on their XBOX360 or PS3 (You have to note that the PS3 does not support the High profile yet, in which most fansubs are encoded, so it's very likely that those files will not play unless they are re-encoded to the supported profile). So I have decided to put something like this us since it will be easier than having dozens of threads which try to achieve the same purpose. Also, scroll down to the very bottom to read a bit more...


Before you even start...

Spoiler for boring stuff, read only if you actually want to know what you are getting yourself into:



What files do I need?
  • Firstly you need to grab the script itself from here. Save it as mkv2mp4.bat and it's version 1.03 at the moment. The next thing you need to do is unpack the bat script into some folder. Then create a new folder called "bin" inside it. Also make sure to have CCCP installed and fully working.
  • Now, the biggest requirement for this to work is to have mkvtoolnix, which is a tool that allows tracks to be removed from MKV files and put back in. You can download it from here. Install it as usual. Then navigate to the directory where you installed it and copy the following files into the bin directory that you created earlier on.
    Spoiler for list of files that need to be copied:
  • You need to download MP4Box which just simply muxes streams into the MP4 container, which is supported by both the PS3 and XBOX360. You can get it from here and copy the executable (and any *.dll file, if present) into the bin directory.
  • You will also need a little package that will do some pretty smart "magic". It's this what makes this whole remuxing process possible without having to add too much user required input. Get it from here and put all of its contents into the bin directory (if it requests a password for the package then use doom9.org).
  • You need to download and install AviSynth 2.5 for video frameserving since you might be re-encoding the video. You can get it from here.
  • You need to download the nero AAC encoder from here and place neroAacEnc.exe into the bin directory.
  • Same with BePipe, placing bepipe.exe into the bin directory.
  • Furthermore you will need to download x264, which is the H.264/AVC1 encoder application that might be used. It can be found here. The topmost *.7z file is what you'll be usually looking at getting and put x264.exe into the bin directory.
  • Lastly, you need a little tool that does some hex changing, I won't go into details, but it is needed because both Sony and Microsoft fail pretty hard. Get it from here and again place the executable into the bin directory.

All these tools should suffice for all the tasks in this script.


What do I do next then?

The batch script executes different commands based on what media file you have, since not all of them can be treated the same. In this section I will explain how to identify them.

The simplest approach would be to open the media file in Media Player Classic, right-click on the video and move to the Details tab. There you will see a basic description of the file.

Type 1
Video: MPEG4 Video (H264)
Audio: AAC
- just remuxing needed

Type 2
Video: MPEG4 Video (H264)
Audio: MPEG Audio Layer 3 (aka MP3), Vorbis, AC3 or any others
- audio transcoding to AAC needed, rest will be just remuxed

Type 3a
Video: XVID, DIVX or any others
Audio: AAC
- video transcoding needed, audio will be remuxed

Type 3b
Video: MPEG4 Video (H264), XVID, DIVX or any others
Audio: AAC
Subtitle: Advanced SubStation Alpha or any others
- video transcoding needed while hardsubbing subtitles, audio will be remuxed

Type 4a
Video: XVID, DIVX or any others
Audio: MPEG Audio Layer 3 (aka MP3), Vorbis, AC3 or any others
- video and audio transcoding needed

Type 4b
Video: MPEG4 Video (H264), XVID, DIVX or any others
Audio: MPEG Audio Layer 3 (aka MP3), Vorbis, AC3 or any others
Subtitle: Advanced SubStation Alpha or any others
- video and audio transcoding needed while hardsubbing subtitles


About the pixel aspect ratio

Since version 1.02 I had to introduce an option to specify the pixel aspect ratio in order to retain the correct look of the video. Unfortunately this currently cannot be automated and has to be set by the user.

First thing to do is to open once again the basic properties of a file in Media Player Classic as described in the previous section and look closely at the video part. If you see something like "Video: MPEG4 Video (H264) 704x480 (853:480) 23.98fps [Video]" or "Video: MPEG4 Video (H264) 720x480 (853:480) 23.98fps [Video]" or even "Video: MPEG4 Video (H264) 704x400 (711:400) 23.98fps [Video]" it means that there was a custom ratio set by the person who made the video file (for those interested the first resolution is the one at which the file was encoded and the second one, in brackets, is the one that it gets stretched to on playback). You need to make sure to do the same. If there is just one resolution listed it means that nothing was set and you should just choose "1:1" when the option appears.

I'll just simply list the most common possibilities and their respective pixel aspect ratios for ease of use.

704x480 (853:480) or 704x480 (16:9) - 40:33
720x480 (853:480) or 720x480 (16:9) - 32:27
704x400 (711:400) or 704x400 (16:9) - 100:99
704x480 (640:480) or 704x480 (4:3) - 10:11
720x480 (640:480) or 720x480 (4:3) - 8:9

For other non-common ones please contact me and I'll try to help you.


Getting it all down

Before starting the script, make sure to move the file that you would like to convert into the directory where you unpacked the mkv2mp4.bat script and where the bin subdirectory is located. Now run the script by double-clicking on it.

Firstly it will ask for the type of file that you would like to convert. You should have already determined that from the previous section. The possible choices are from 1 to 4.

A word of warning before I proceed to the next step. Please make sure that the files that you want to convert don't have any spaces in them. Best thing is to just replace them with underscores. Same goes for any other files that you may be using later on.

Depending on your choice it will ask for other inputs which I'll describe next;

Type 1
1) This one will ask next for the input filename of the file that you would like to convert without the extension.
2) Then it will ask for the output file, without the extension again, which is just the name of the file that it will create using the MP4 container. After that it should just work through all the lines in the script, delete all the intermediate files at the end and place the output into the directory where the script is found. And you're done.

Type 2
1) Same as step 1 and 2 from Type 1

Type 3
1) Firstly you need to change one setting in CCCP. Go into its Settings application, click Next and check "Autoload VSFilter" and Apply.
2) You need to create an AviSynth script. Place the MKV file into the directory where you unpacked the mkv2mp4.bat script, and create the script there as well. Here is a basic example of an AviSynth script;
Code:
DirectShowSource("C:\path\to\file.mkv")
3) Same as step 1 in Type 1
4) It will ask for the AviSynth script filename, without the extension.
5) Same as step 2 in Type 1
6) Now it will ask whether the video is standard or high definition. This just tells the script to use different encoding settings, since for once you don't really want to kill the encoding speed or playback too much, right?
7) Finally it will ask for the bitrate. Usually go with some value given in the recommendations range. It should give decent results.
8) Now just wait for it to do its job and spit out an MP4 video file.

Type 4
1) Same as steps 1-8 in Type 3


---

Spoiler for the old "manual" way (no longer updated):


Constructive feedback is of course welcome. (Hopefully I haven't missed anything important or made some silly mistake, since you could consider this as an intermediate version.)
__________________
"Light and shadow don't battle each other, because they're two sides of the same coin"

Last edited by martino; 2008-12-19 at 12:26. Reason: v1.03 update
martino is offline   Reply With Quote