Trouble logging in?If you can't remember your password or are having trouble logging in, you will have to reset your password. If you have trouble resetting your password (for example, if you lost access to the original email address), please do not start posting with a new account, as this is against the forum rules. If you create a temporary account, please contact us right away via Forum Support, and send us any information you can about your original account, such as the account name and any email address that may have been associated with it.

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:

You have to take into account that Matroska (MKV) uses quite a few smart features which make it rather hard to convert. One of those would be the fact that it uses a timecode file on the video stream, to specify which sections/frames are played at what framerates. Even if you encode a stream at a constant framerate, for example 23.976 frames per second, it will end up applying a timecodes file to the stream. I don't know the exact specifics how it does this, and why exactly this happens (drops duplicate frames?). If someone who knows this well, feel free to explain it please. This fact makes it really hard to just switch containers just like that. Some tweaking is needed, whether you like it or not. Otherwise re-encoding the video stream is another possibility. Take a look at the next post where GHDpro has already started with a simpler guide than this one. You just have to note that by re-encoding the video you will lose quality. However if you want to add subtitles (which are found as softsubs in the MKV file) then it's the only way, unless the XBOX360/PS3 magically supports TTXT (no it doesn't, been confirmed). Where as in my complicated guide you are just switching containers.

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.

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.

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.

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.

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 11) 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 21) Same as step 1 and 2 from Type 1

Type 31) 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 14) It will ask for the AviSynth script filename, without the extension.5) Same as step 2 in Type 16) 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 41) Same as steps 1-8 in Type 3

---

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

Software List

CCCP
- If you'd like to avoid installing CCCP, which is not recommended, you can get the needed filters separately;

Some more software will be needed, depending on the type of file that you'd like to convert, but I'll get to that later on.

Installation Notes

Everything should be pretty straight forward, the only problem might be if you are not installing CCCP but are doing it the alternative way. In this case I won't provide any support and/or extended installation instructions. You're on your own.

Note 1: The MP4Box executable has to be in the same directory as YAMB.
Note 2: You have to set the path of where mkvtoolnix is located for MKVE Wizard under Settings in order to extract the streams.
Note 3: When downloading tc2mp4, you have to copy the Perl script (found in the 3rd post of the thread on Doom9) and save it in the same directory where you saved the executable file as tc2mp4.pl. You also have to copy the MP4Box executable into that directory, otherwise it won't work.
Note 4: MKVExtractGUI has to be in the same directory as mkvtoolnix if you downloaded it.

What type of MKV file do I have?

MKV supports many features, like softsubs. These cannot be added to an MP4 file, since they are not supported by the ISO standard. The same goes for Vorbis audio. So some precautions have to be take before you start. It also supports VFR (Variable Framerate), which is slightly trickier to convert into MP4. But I'll get to that later on.

I will group here the different types of MKV file that you can get, and assign different sections of this guide for them. The easiest way to find out basic information about the file is to open it in Media Player Classic and right-click on the video (or alternatively click on File in the Menu) -> Properties -> move to the Description tab and look in the box at the bottom.

1a) MKV with AAC/MP3 audio, H264/XviD video and no softsubs.

Spoiler:

This is the easiest one to convert. Move to section 1a for the steps.

1b) MKV with Vorbis audio, H264/XviD video and no softsubs.

Spoiler:

This is fundamentally the same as the above, the only difference is that it contains Vorbis audio, which is not supported by MP4, so it will have to be re-encoded to something like AAC. Move to section 1b for the steps.

Section 1a (no re-encoding needed, just some more relatively complex demuxing and muxing)

1) Firstly you will need to demux the video and audio track from the MKV file. I recommend using MKVE Wizard for the easy of use. I'm going to base this on the file that I used for the demonstration earlier on. So you find select the file that you would like to demux in the Input field, and use the Output field to find the location where you would like to demux the tracks from the MKV file. There's nothing important on this screen, so click Next. The next screen should look like the following (note that if the MKV did not have chapters to start with, they will not be listed since they can't be created from thin air and you won't be able to demux them):

Spoiler:

Now you should check the tracks that you would like to demux, which in most cases would be the video, audio and chapter (if available) track. Also leave the other options on the right side as they are, unless you know what you are doing. Now click Next and the tracks will get extracted into the specified directory. After the process is finished you can click Finish and close the wizard.

2) Now you will have three files (or two if there was no chapter file) in the Output directory that you specified. It should be a *.h264 (for H264 video)/*.avi (for XviD video) and *.aac (for AAC audio)/*.mp3 (for MP3 audio) and *.txt (for the chapter file). Now you have all the files so you are ready for the next step.

3) This step is short. All you need is to obtain a plain video MP4 file from the *.h264 file. For this you will need to use YAMB. Please reference to step 6 for the instructions. But note that at this stage all you need is only video, nothing else.

4) Now you need to extract the timecodes file from the MKV (this step must not be skipped). This can be done by starting up the mkvextract executable from the mkvtoolnix package from the command prompt. So click on Start -> Run (or press the Windows Key + R on your keyboard for a shortcut) -> type in "cmd" (without the quotes of course) and click OK. Now you will have to start the executable from there, so type in "mkvextract", hit Enter on your keyboard and it will show all the options. Now to check for the timecodes;

Code:

mkvextract timecodes_v2 <inname> [TID1:out1 [TID2:out2 ...]]

Let's say that you have a file stored under "C:\Videos\Video01.mkv". You will have to type in

and it will extract the timecodes file into "C:\Videos\" named as "Video01_timecode.txt". Don't delete this file, you will need it in the next step. And for God's sake, don't even bother amending it.

5) Now comes the hard part. If you tried playing the file that you got from the previous step you might have noticed that it is shorter (or longer?) than the original MKV file. It depends on the source. This little step will fix that (or at least should). Open up the command prompt again, as explained in the previous step. Now you will have to do some navigating. First off you have to note down the full path of the directory where you saved tc2mp4. You will have to navigate to it now. In the command prompt window, type in "cd "C:\path\to\tc2mp4\"". Just substitute in the location where you saved tc2mp4 on your system. Then hit Enter and your current location should have moved there. Now you can type in "tc2mp4" and it will show up what the parameters for it are. On my computer it looks like the following;

Spoiler:

Now you are ready for the action. Let's say that the video MP4 file was saved under "C:\Videos\" named as "Video01.mp4", the command line will look like the following:

Now press Enter and the process will start. Make sure that you got the filepaths correct, otherwise it's not going to work and it will throw out an error (184 IIRC). This will take some time (a few minutes at most), depending on the video length and the timecode format. At the end it should throw out an MP4 file, of the same length as the MKV that you started with (if it is a second shorter or longer, then it might get corrected during the next stage. I'm not sure why this happens, so far I haven't done much testing to conclude whether this affects the final audio/video synchronisation by a noticeable margin).

6) Open YAMB, and click on the option to Mux or to Create an MP4 File. I will be basing this on the 2.0 Preview version of YAMB. So you select the appropriate choice and the following screen should look like:

Spoiler:

Now you are ready to drag & drop the extracted files in that window. Use the new MP4 file that you got from tc2mp4. I recommend adding the video first, then audio and finally the chapters file (in the end you can just move them up and down if needed). If you feel like having a play around with it then you can click on Properties and fill out the fields for each track, but I won't bother going into explaining it. It's quite simple and easy after all. Set the Output file and click Next and the file will get created. Afterwards click Finish to close YAMB. If you got to this step without any problems and the file plays correctly, then you should be a happy (and tired...and maybe even crazy) bunny. ^^

BePipe & SNG (BePipe is a tool which takes AviSynth audio output and feeds it into a WAV file; SNG is a GUI for the Nero Encoder)

Installation Notes:
Put the BePipe executable into the same directory where you placed the Nero encoder. Also, put the SNG executable in there too, so that you can use the GUI and all the features that it offers.

1) Follow steps 1 to 5 from section 1a to deal with the video stream.

Now you will need to re-encode the Vorbis audio to some other format. In here I will use AAC, however MP4 supports more formats like MP3 and who knows what else. In here I will use AviSynth to feed the audio through DirectShow, BePipe to convert the RAW output into WAV and then NeroEnc to encode it to AAC. It sounds complicated, but it's actually easier than you think. (Maybe there is an easier way, I do it like this so I never bothered looking up alternatives. If you know of something easier/better then please tell me so.)

2) Open up SNG (Simple NeroAaacEnc GUI). Click Add and find the Vorbis (*.ogg) file that you'd like to encode. Now move to the Encoder tab. Here you will find some settings. I really don't want to enforce any specific type of settings, but leave the Advanced features as they are. VBR mode should give better quality than CRB or ABR (though IIRC I read somewhere that ABR gives better results at lower bitrates). Either way you want preferably want to match the same bitrate as of the original Vorbis file to keep roughly the same filesize of the final MP4 file. I'm not really sure of any program that can give you a specific bitrate of a Vorbis file (I just use Winamp for it). So based on that you will have to decide what quality setting to use. Most likely it will be ABR 128kbps and higher (which is VBR quality 0.5? - not 100% sure here). You should leave the rest as it (just to be sure switch over to the Avisynth tab and make sure that Normalize is left unchecked) is and click Encode, which will open up a command prompt where you will be able to see the progress. At the end it will spit out the AAC audio file in an MP4 (or M4A if you checked the option; either way it's the same container just different extension) container.

3) Now you can mux it with the video using YAMB. Just follow step 6 in section 1a. One thing that needs to be noted is that when you drag the encoded AAC audio file to YAMB, more "streams" will appear. Just uncheck the ones that aren't reporting any details/data.

I know. It's somewhat complicated, and for now I don't really see a simpler solution (unless someone feels like writing a script for it). MKV is a bit of a sucker to convert. So I wouldn't recommend doing it either way, unless you really feel like it's worth the trouble and time (not everything can be done with a one-click magic application, that way it wouldn't be so much fun). The rest will be coming up sometime later (mind you I'm in the middle of my exams, right now with some spare time before my next one). Only this took me 5 hours to write up with some testing on my side. >_>

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"

Alternative Guide
This version is a bit easier. However, as the video will be re-encoded (even if the subtitles are already encoded into the video), the result will most likely be lower quality.

1. Required Software
- MKVExtractGUI
- mkvtoolnix
- VSFilter (part of CCCP, so you should have it already)
- PS3 Video 9 (similar tools might also work for other systems such as PSP or Wii)
- AviSynth (optional - also included in PS3 Video 9!)

The first three files are only necessary if the file you are trying to convert MKV files with soft subtitles.

2. Extracting the subtitles
If the file has soft subtitles, you need to extract the subtitles first using MKVExtractGUI. Make sure you put MKVExtractGUI in the same folder as mkvtoolnix (C:\Program Files\mkvtoolnix by default) btw.

The subtitle file (shown as S_TEXT/ASS for styled subtitles or S_TEXT/UTF8 for plain subtitles) will be put in the same folder as the video file.

Note: some MKV files also include fonts. You may need to extract and install the fonts (using the Control Panel) in order for the styled subtitles to look just the way they're supposed to look.

3. Write the AVS (AviSynth) file
This is the hard part: writing the AVS file. Actually the hard part is getting the folders and filenames just right (this could be tricky if the file has a complicated filename and is in a folder a few levels deep). Btw, an AVS file is simply a text file with a .AVS file extension.

Of course make sure all the paths and filenames are changed to whatever file you want to convert. TIP: right click and select "Rename" on the file you want the filename of, and then press CTRL-C to copy the filename to the clipboard. Then just press CTRL-V to paste the filename in Notepad.

If the MKV file you want to convert does not contain subtitles (in case they're already encoded in the video) leave out line 1 ("LoadPlugin") and line 3 ("TextSub") and keep just line 2 ("DirectShowSource").

Before converting, verify the AVS file works by opening it in MPC (Media Player Classic). If you get a AviSynth error message, you'll need to fix the AVS file.

4. Convert with PS3 Video 9
I'm not going to explain the usage of PS3 Video 9 here, as it's pretty simple. Also you'll need to test for yourself which conversion profile works best for you. But if you have followed the steps above, you should be able to convert the MKV file just like you would any AVI file.

If you need a hint: select "Convert", then "Current conversion" tab. Then just click the "Convert video" button and select the AVS file you just created.

Optional hint
If you go to Start -> Programs -> Combined Community Codec Pack -> Media Splitter Settings and then under the Options tab enable "Autoload VSFilter" (in Compatibility section), you might be able to skip the whole MKVExtractGUI phase! You probably still need to write the AVS file, but you can get away with just the "DirectShowSource" line (and leave out the others).

Disclaimer
I have neither a PS3 nor a Xbox 360, so I can't test this. But I did succesfully convert various files to PSP format (using PSP Video 9) this way.

Loading VSFilter within DirectShowSource (if you use Autoload VSFilter) might get flipped images and such depending, just be sure to preview before you hit encode.

Also specific note in terms of re-encoding while using the CCCP's ffdshow, you should turn on YV12 ouput in FFDShow Video Decoder Config under Outputs. Less colorspace conversions = more good for you. Next CCCP version will already have this on by default, but currently all past versions have used YUY2.

make sure you have perian 1.0 (beta) installed (http://perian.org/beta.html) and download viddy up (www.splasm.com) the unregistered version works fine, as we are only going to transfer it into a .mov (renaming won't work)

from there you can use isquint (www.isquint.org) or visualhub (£££) (http://www.techspansion.com/visualhub/) ... well, personally i just use the apple tv settings & h.264 - high or standard. some files i notice a noticable quality difference, some i don't. just depends on the original encode i guess.

- oh, directly converting from mkv using visualhub sometimes works, but this is a surefire way to make sure you get subtitles.

Question/concern~ So like, I'm using the alternate method since it looked more nub-friendly, and for some reason I'm having problems. When I get to the conversion process, it for some reason won't add to my iTunes library, and when I try to open it manually, it will only play audio in Winamp. However, using the exact same method, but using the 30second test option, it works perfectly.... What could be causing this? x_x

Question/concern~ So like, I'm using the alternate method since it looked more nub-friendly, and for some reason I'm having problems. When I get to the conversion process, it for some reason won't add to my iTunes library, and when I try to open it manually, it will only play audio in Winamp. However, using the exact same method, but using the 30second test option, it works perfectly.... What could be causing this? x_x

You shouldn't be really using Winamp to play the output file. It's meant to be for audio playback and its handling of video files just simply doesn't cut it. Not sure what iTunes has to do with this, maybe it's somehow interfaced with that xx Video 9 program. I've never run that program so I wouldn't know, sorry.

Also as an update I will attempt to write a script for ease of use, after my exams though. However I currently do have a batch script for converting any file that plays in DirectShow to XviD/MP3 in AVI. It's currently being tested... Just a heads up.

__________________

"Light and shadow don't battle each other, because they're two sides of the same coin"

I'm not sure I want to go into great detail explaining this but, I always managed to convert Metroska file containers to more common video file types like .wmv or MPEG2 using the Combined Community Codec Pack and the full version of TMPGEnc 4.0 Xpress. I'm new to the forum and joined because I found a great bunch of technical support threads through Google. I hope this has helped anybody who was hoping in not having to overheat their heads over the challenge and I'm sure you can pick up TMPGEnc Xpress through torrent searching.

Ah, I remember the days back in 2005 when I was ridiculed for switching to h.264 in mp4 in my group (one of, if not the first group to do so)... And now to see people actually requesting their mkvs be converted into mp4s, for exactly the reason I predicted (better hardware playback compatability) makes my day.

I have a question about this. Whenever I encode mkv to mp4 files, it will leave me too extract the fansubs and merge them back to the mp4 file. Question #1: Is it possible for a way to merge the Typesetting along with the subtitles into the newly encoded mp4 file? Question #2: If it don't work, then is there like another way for it to see it with typesetting using the fansub group typesetting?

If you are just converting for your PSP then there's also XviD4PSP, which contrarily to it's name, handles just about any file format. It seems to work OK.

It appears to uses FFdshow, so it your mkv has subtitles, you might want to go to FFdshow video decoder options to turn on subtitles and embedded subtitles. The subtitles will end up hardcoded to the resulting MP4 file.

MP4 does not support softsubs, ok maybe it does, but no device supports the TTXT format. Plus, you're not gaining anything by converting a softsubbed MKV to a softsubbed MP4, in terms of niceness and compatibility. It's just... pointless.

Quote:

Originally Posted by Salt

It appears to uses FFdshow, so it your mkv has subtitles, you might want to go to FFdshow video decoder options to turn on subtitles and embedded subtitles. The subtitles will end up hardcoded to the resulting MP4 file.

Hopefully not. It should be using VSFilter's rendering, and not FFDShow's which should be used just as the audio/video decoder. That is if it is using DirectShow output for frameserving.

Quote:

Originally Posted by garra113

I have a question about this. Whenever I encode mkv to mp4 files, it will leave me too extract the fansubs and merge them back to the mp4 file. Question #1: Is it possible for a way to merge the Typesetting along with the subtitles into the newly encoded mp4 file? Question #2: If it don't work, then is there like another way for it to see it with typesetting using the fansub group typesetting?

Merge? What do you mean by that... Is that like hadrsubbing it, or converting to TTXT?

__________________

"Light and shadow don't battle each other, because they're two sides of the same coin"

I wish to see the same typesetting as the fansub groups already provided in the mp4 BUT the mkvmerge doesn't allow you to merge the typesettings and only the subtitles. In other words, I wish to merge the typesettings but I don't know how loll.

Hopefully not. It should be using VSFilter's rendering, and not FFDShow's which should be used just as the audio/video decoder. That is if it is using DirectShow output for frameserving.

LOL. I have no idea what you are talking about.

I'm clueless as to what goes on behind the scenes (hence my using of a program with a relative simple GUI).

I had to fiddle around quite a bit to get subtitles to appear (hardcoded of course) in the resulting PSP compatible MP4 file. I tried adjusting DirectVobSub's setting, to no valid, then I read something about turning on the subtitles in FFDshow, and that did the trick.

I wish to see the same typesetting as the fansub groups already provided in the mp4 BUT the mkvmerge doesn't allow you to merge the typesettings and only the subtitles. In other words, I wish to merge the typesettings but I don't know how loll.

Typesetting is usually hadsubbed on the video, or softsubbed in the same track as the dialogue because you can't have two softsub tracks playing at the same time. Also, what are you trying to achieve? Softsub an MP4? For what point? It's totally pointless as I posted before...

__________________

"Light and shadow don't battle each other, because they're two sides of the same coin"