Turning mkv into mp4 for the PS3 [UPDATED]
Quite a lot of acronyms there don’t ya think?
Anyway… The PS3 is fantastic. I think most people with half a brain will agree on that. It does however have it’s shortcomings and one of them is that it doesn’t play mkv-files. So whenever I stumble upon something in that format I have to perform some sort of black magic on it in order to turn it into an mp4 that the PS3 agrees with.
The easy way to go is to just flush it through HandBrake. That works but then it will be decoded and re-encoded which potentially causes quality degradation and takes foreeeeeever. So that’s not really an option I’m happy with.
However, decoding and re-encoding is actually unnecessary since what’s wrong is the container and not the contents. Luckily unpacking and repackaging the mkv as mp4 can all be done with a bunch of free and open source tools. It’s still a bit of a hassle though so today I spent a couple of hours putting together a script that makes it semi-automatic and a lot easier.
One thing that proved to be a bit more work than I expected was turning DTS 5.1 audio into AAC 5.1. What I came up with should work, but I haven’t been able to verify it since my receiver doesn’t support AAC 5.1. If yours does, please let me know if it works or not. For this reason in my personal version of the script I turn DTS 5.1 into AAC stereo instead (using the last part of the if-elif-else statement), which is OK even if it’s not quite as nice as 5.1 sound would have been.
All of the tools I used are open source software and available for most Linux-flavors (I use Fedora 12), except Nero AAC Encoder which is just free as in beer.
So that nobody else has to suffer through the process of putting a script like this together; here’s the script. It’s fairly self-explanatory and I even commented the code a bit so it shouldn’t be that hard to understand what it does and why. Enjoy!
While putting together the script I found this article very useful for deciphering the mess that is audio codecs. I would also like to give a shout-out to one of my co-workers who introduced me to several of the tools and how they work.
UPDATE:
In further experimenting I found that my original script contained a couple of bugs. I believe I’ve sorted those out now and I’ve updated the code above. I’m still not claiming this script to be bug-free so if you find anything that’s not working, please let me know.


I’m pretty sure that your receiver supports DTS audio (DTS-HD is backwards compatible). You should be able to mux in DTS audio in you MPEG4 file. I mean they do it in Blu-Ray. MP4Box may go nuts with DTS audio but give it a shot. You may have to trick it with some parameters but it should work. Transcoding DTS to AAC may be nice but should be totally unnecessary.
Keep experimenting and sharing.