Register Forum Rules FAQ Members List Social Groups Search Today's Posts Mark Forums Read

 AnimeSuki Forum MKV to MP4 Guide

 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
GHDpro

Join Date: Jan 2001
Location: Netherlands
Age: 37
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.

Write a AVS file that looks like this:
Quote:
 LoadPlugin("C:\Program Files\Combined Community Codec Pack\Filters\vsfilter.dll") DirectShowSource("C:\Anime\Hayate no Gotoku\[SS-Eclipse] Hayate no Gotoku! - 07 (1280x720 h264) [367A4C60].mkv") TextSub("C:\Anime\Hayate no Gotoku\[SS-Eclipse] Hayate no Gotoku! - 07 (1280x720 h264) [367A4C60]_Track3.ass")
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.

Last edited by GHDpro; 2007-05-17 at 14:50.

 2007-05-17, 19:39 Link #3 Nicholi King of Hosers   Join Date: Dec 2005 Age: 33 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.
 2007-05-18, 17:45 Link #4 Aegelward Junior Member   Join Date: Feb 2006 i've figured out a way to do this on the mac, it eats up a bit of disc space however. and it only works for files with one audio track. doing converts straight from viddyup sometimes resulted in stuttering files so... 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.
 2007-08-10, 14:25 Link #5 Hinosaki Junior Member   Join Date: Aug 2007 Hmm, I have a slight problem. I successfully converted one file to .MP4 and it played fine. However when I was working on my second one I get this problem. Spoiler for : Not sure what to do here. I rechecked the steps and redid everything but the same problem occurs. EDIT : Scratch that. I got it to work somehow. I guess I mistyped something. >_>. Last edited by Hinosaki; 2007-08-10 at 15:17. Reason: Figured it out.
 2007-08-11, 21:58 Link #6 kujoe from head to heel     Join Date: Jan 2004 Location: Vancouver, Canada Age: 34 Ok, I'm obviously a newbie at this... so, I have question if you guys don't mind me asking. Do any of the illustrated methods work for videos (.mkv) with multiple sound channels? I would like to convert something which has "AAC 48000Hz 6ch [Audio]." EDIT: Never mind. Figured it out for myself. Thanks for the guides. Last edited by kujoe; 2007-08-13 at 20:26.
 2007-12-01, 14:41 Link #7 Fleabitten8907 Loves stripes.   Join Date: Sep 2006 Age: 27 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
 2007-12-01, 21:10 Link #8 hobbes_fan You could say.....     Join Date: Apr 2007 I've put a link to this in my sig. I also request that this be stickied. It has become a once a week question. __________________ Before you ask "How do I convert fansubs to...." see the following MP4 - http://forums.animesuki.com/showthread.php?t=47693 Convert AVI/MKV/MP4 to DVD http://forums.animesuki.com/showthread.php?t=26308
martino
makes no files now

Join Date: May 2006
Quote:
 Originally Posted by Fleabitten8907 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"

 2007-12-21, 07:08 Link #10 zuka Junior Member     Join Date: Jul 2007 Location: Canada mp4mobile is probably the best choice if you are willing to pay for it http://www.videomobileconverter.com/mp4Mobile/
 2008-01-07, 05:55 Link #11 DuplicateGoose Junior Member     Join Date: Jan 2008 Location: Nottinghamshire, England Age: 25 Metroska (.mkv etc) to common Windows video file types 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.
 2008-01-14, 20:15 Link #12 hobbes_fan You could say.....     Join Date: Apr 2007 you realise that this product is a retail product. TMPENGC v4.0 is not a free product and any torrented version of it is pirated. It is sold for \$110USD http://forums.animesuki.com/faq.php?...#faq_rules_1_1 __________________ Before you ask "How do I convert fansubs to...." see the following MP4 - http://forums.animesuki.com/showthread.php?t=47693 Convert AVI/MKV/MP4 to DVD http://forums.animesuki.com/showthread.php?t=26308
 2008-01-14, 21:11 Link #13 Quarkboy Translator, Producer     Join Date: Nov 2003 Location: Tokyo, Japan Age: 36 I just noticed this thread... and came to gloat a bit. 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 love being right. __________________ New Project Coming 2017 Translator, Producer, Japan Media Export Expert Sam Pinansky
 2008-01-21, 23:38 Link #14 garra113 CaramellDansen!!!   Join Date: Apr 2006 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?
 2008-01-22, 10:30 Link #15 Salt the cynic     Join Date: Nov 2006 Location: Somewhere between life and death. Age: 34 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. __________________ De gustibus non est disputandum.
 2008-01-22, 12:09 Link #16 garra113 CaramellDansen!!!   Join Date: Apr 2006 Yeah but the whole point of encoding it to mp4 is for the softsubs though. Anyway to do it the way I said up my 1st post?
martino
makes no files now

Join Date: May 2006
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"

 2008-01-22, 18:42 Link #18 garra113 CaramellDansen!!!   Join Date: Apr 2006 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.
Salt
the cynic

Join Date: Nov 2006
Location: Somewhere between life and death.
Age: 34
Quote:
 Originally Posted by martino 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.
__________________
De gustibus non est disputandum.

martino
makes no files now

Join Date: May 2006
Quote:
 Originally Posted by garra113 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"

 Tags wiki candidate, tutorial, file conversion