I searched a *long* time on the net trying to find out how to convert a HD mkv file to an MP4 file for play on the PS3 without re-encoding on Mac OS X. Couldn’t find anything that didn’t cost any money which was rather irritating; lots of question, not really any answers.
But, what I did find was how to do it on Linux. Which was great because through MacPorts, we on OS X have access to many of the same tools. Unfortunately, I had to spend a significant amount of time to patch work the different tutorials and tweek them to work on OS X. So, hopefully this will save some other poor soul some frustration.
Disclaimer: Now, I’m not going to be citing my sources. If you want to see what I saw, just Google and you’ll see it. This isn’t to slight anyone, but because there are too many, over a good chunk of time, and it was a fair bit long ago, I actually can’t. I’m just mentioning this because I don’t want to take credit for what others figured out. My contributions were figuring out that the hexedit trick worked with mp4creator and which tools were the most appropriate to get the needed jobs done on OS X… after a lot of experimentation/time/frustration/etc. But, without further ado…
To do the below, you’ll obviously need some tools installed. They can be easily installed through MacPorts. So, if you haven’t already, go install it now.
Now that that’s done, here’s what to install through MacPorts:
hexedit
mpeg4ip
mkvtoolnix
Now the above can be installed with the default settings. But, we still need to install ffmpeg which needs some options set. I personally suggest installing it with all options. For convenience here’s the command as of this writing:
sudo port install ffmpeg +a52 +faac +faad +gpl +lame +libogg +postproc +theora +vorbis +x264 +xvid
That will probably take awhile…
There is a possibility (I’m not going to uninstall everything and re-install just to check this) that one of the above might require you to force install a package because two ports want to install a file of the same name. I did it have have yet to suffer for it. Though the reader should make up his/her own mind on that one if it happens.
Now that we have the needed tools installed, we can move onto getting at that file.
First we get info about the file:
mkvinfo file.mkv
Here we’re looking for a couple things:
1) What track is the video tracks
2) What is the framerate of the video track
3) What format the video track is in
To see if the video is encoded in the proper format, look for “Codec ID: V_MPEG4/ISO/AVC”. To get the framerate, in my version I the item is called “Default duration” and you can scan right of that to get the fps. We now extract the track:
mkvextract tracks file.mkv TrackNumber:video.h264
Next we get the audio. The PS3 has limited audio support for the MP4 container. But, because we’ll have to convert the audio anyway (yes, I know I said no re-encoding, but audio “usually” comes in ac3 format and audio takes zero time to convert compared to video anyway), we just do that in one step:
ffmpeg -i file.mkv -vn -acodec aac -ac 2 audio.aac
Now that we have the audio in a PS3 compatible format we need to get the video in one as well. Most video comes in 5.1 profile which the PS3 doesn’t understand. Luckily it’s very easy to change this. We open video.h264 in hexedit and notice on the first line:
67 4D 40 33
Which we change to:
67 4D 40 29
NOTE: The Sha has noted that (s)he ran into a different number combination than the above and upon closer inspection I have run into a couple new ones as well. The good news in this is that the 33 remains the same and is the one that you want to change. What you’re looking for in hexedit, is the 2nd distinct column grouping of numbers. The 33 will be on the top line and is the right most number in that 2nd grouping.
We then make a MP4 file with the video that we extracted specifying the video’s framerate:
mp4creator -create=video.h264 -rate=videoFramerate file.mp4
We also need a hint track in there for the video:
mp4creator -hint=1 file.mp4
To get the audio in, we do:
mp4creator -c audio.aac -interleave -optimize file.mp4
Next comes getting that file to the PS3 itself. Though there are several options available, I use MediaTomb. I just got the Portfile ready to submit and when doing so, found out that it’s already in MacPorts. So, just:
sudo port install mediatomb
That one command will install mediatomb and all its dependencies. Happy viewing!
For large file support, see my addendum.
For a GUI program that does specifically the tutorial written above, see here.
February 2, 2008 at 6:51 am
Thanks for the tutorial, I’m going to give it a quick try, and see if I can replicate it on linux since most the tools are the same, but was wondering what mime type do you have set in your MediaTomb config file to recognize mp4’s?
February 3, 2008 at 2:39 am
No problem. But, I believe that all of the tools are available on Linux. So, that shouldn’t be a problem. Also, if any of the above is ambiguous, please let me know so I can try to improve it.
Regarding the mime-type, I haven’t touched a thing from the default config aside from adding in some unrelated transcoding stuff. MediaTomb seems to handle MP4’s just fine on its own (I believe it uses libmagic or libextractor to do this).
But, if you have any problems with MediaTomb, that community is very helpful. There forums can be located through there sourceforge page:
http://sourceforge.net/projects/mediatomb
February 3, 2008 at 4:18 pm
Thanks again for the tutorial,
I actually tried it out, but had problems with the MP4 wrapper app, but was able to use MP4Box instead. The ffmpeg tip saved me tons of time, and I was able to create a simple script that now automatically remux’s on the fly, which after some testing will share. Only other difference I found is my videos is that they were using the hex code of 67 40 00 33 instead of what you posted above and now everything works great.
February 3, 2008 at 4:19 pm
Also, since I’m using a slightly older version of mediatomb and not the svn I had to add a video/mp4 mimetype to get the ps3 to recognize and play the files..
February 8, 2008 at 6:47 am
Thanks! I’ve updated the guide to accommodate this new info.
February 8, 2008 at 10:36 am
the command “ffmpeg -i file.mkv -sameq -vn -acodec aac -ac 2 audio.aac” didn’t work for me: Unknown encoder ‘aac’.
I had to use the option “-acodec libfaac”
February 8, 2008 at 6:15 pm
Different platforms (and/or ffmpeg versions?), for some unknown reason, require different codec names. Current, Mac OS X ffmpeg installed through MacPorts *as is specified in the guide* requires “-acodec aac”.
February 9, 2008 at 10:07 am
Any way to script this?
February 9, 2008 at 7:46 pm
Yes. But, I have no idea if/when I’ll get around to that.
February 11, 2008 at 9:21 pm
Hi, I have followed your guide which is great but I am getting error with mp4creator “Error decoding sei message” and I was just wondering if this is normal or am I doing something wrong??
February 11, 2008 at 10:45 pm
Hi, again carried on with the conversion I found that I can play the video.mp4 file on my PS3 fine but as soon as I add the audio the mp4 file my PS3 says “Corrupt Data”. I can play the file fine in Quicktime but when I show movie inspector the format show as VC Coding
February 12, 2008 at 12:02 am
@Gadget:
I get that mp4creator error as well. Doesn’t seem to effect anything.
On the video.mp4 file, could you please do:
mp4creator -list video.mp4
And post that. It’ll let us know exactly what tracks/encodings are in the file.
February 12, 2008 at 7:50 pm
I run the command and this what was produced.
1 video H264 Main@4.1, 5211.086 secs, 6564 kbps, 1280×528 @23.976000 fps
2 audio MPEG-4 AAC LC, 5211.008 secs, 61 kbps, 48000 Hz
I also found that when I added the “hint” to the video the PS3 would play the video.
February 12, 2008 at 8:44 pm
I have been doing some more research on the Internet and think it maybe to with the size of the mkv I am trying to convert it is 4.37GB ??
February 13, 2008 at 12:21 am
I believe that the 4G file size limit is only relevant to VOB files.
But, not having the hint track would mess up streaming the video (so the docs say). When you played the non-hint version, were you streaming it? If not, you just stumbled on another peculiarity of the PS3.
February 13, 2008 at 12:41 am
I’m not trying to stream it, but play it directly on the PS3. Do you have any ideas/settings/command lines on re-encode the video to make it smaller.
February 13, 2008 at 3:34 am
So, the PS3 requires a hint track even though it isn’t technically required by spec. Interesting.
I haven’t played around with the other supported a/v formats much. But, what I use for non-high-def stuff is DVD compatible output through MediaTomb’s transcoding features. The weird thing is that the output plays streaming from MediaTomb and once it’s copied over through MediaTomb. But, if I transcode on my computer and then try to view by either copying over or streaming that file, it doesn’t work. Just letting you know about the limitations. There are also other better codecs supported by the PS3 that you should check out elsewhere.
This is the sh script I use with MediaTomb’s transcoding feature:
#!/bin/sh
INPUT=”$1″
OUTPUT=”$2″
exec ffmpeg -i “${INPUT}” -f dvd -sameq -ac 2 – >”${OUTPUT}”
I don’t know if the file size will get smaller though. Just haven’t paid attention to that. At any rate, that’s something to start with. Hope that helps.
March 3, 2008 at 12:07 am
Fantastic work Odd Man. Just a few suggestions for ffmpeg options.
Still playing around with settings myself, but notice the default settings used by ffmpeg are terrible audio quality. It seems to default to 64kbps.
I use the following:
ffmpeg -i -sameq -vn -acodec libfaac -ac 2 -ar 48000 -ab 320k
Not sure -sameq actually does anything for us, the man page suggests this is a video option.
Note: my ffmpeg also wants “libfaac”, and that was a fresh install today.
I get the following errors trying to add a hint track, but it doesn’t seem to stop the movie from playing on the PS3 via Mediatomb:
MP4ERROR: MP4File::FindIntegerProperty: no such property – moov.trak[0].mdia.minf.stbl.stsd.*.esds.decConfigDescr.objectTypeId
MP4ERROR: MP4File::FindIntegerProperty: no such property – moov.trak[1].mdia.minf.stbl.stsd.*.esds.decConfigDescr.objectTypeId
March 3, 2008 at 12:10 am
Previous post has lost the file names, thanks to some tag parsing.
command line should be:
ffmpeg -i input-file.mkv -sameq -vn -acodec libfaac -ac2 -ar 48000 -ab 320k output-audio.aac
March 3, 2008 at 3:05 am
@Areodiver:
I get those errors to with no negative results.
What the bit rate for the audio will be on that command line will strongly depend on what the bit rate is on the input. For instance, specifying 320k is not going to help if the input is only 64k. Similarly for the sampling frequency. Though that -sameq is indeed for video only.
I’ll update the command to reflect that now, and the next time I convert a mkv I’ll add in the bit about the bit rate and sampling frequency. Thanks for pointing that out
Was your fresh install on OSX? Because I just tried to upgrade mine, but it gave me errors on the install.
March 3, 2008 at 10:55 pm
Yes was a fresh install on Leopard. Had problems with ffmpeg install. Currently an issue with portfile versions apparently. Googled and found you need to bump the ffmpeg portfile svn tag to 12276, see last post in this ticket:
http://www.nabble.com/-14492%3A-ffmpeg-fails-to-install-td15704134.html#a15704134
March 4, 2008 at 6:49 am
Can I set a display width and height while creating the mp4 file?
March 5, 2008 at 3:14 am
when i do the hint step, it seems to ruin my mp4 file. i can’t play back the video file in VLC any more.
also, after extracting the AAC file from the MKV file, should i be able to play it back in quicktime or VLC? the audio extraction process seemed to complete fine, but i get no playback from the output AAC file.
March 5, 2008 at 8:32 am
i should add the audio from the MKV file is DTS if that makes a difference. i was able to successfully extract the audio track as AC3, but apparently no luck with ACC.
March 10, 2008 at 12:24 am
OddManOut,
Thank you so much for taking the time to put this together. After spending about a month banging my head against a wall on this particular subject, I was almost there – the only thing remaining was to change the AVC level from 5.1 to 4.1.
Is anyone aware of a command-line utility which runs on a Mac that will take care of the AVC level conversion? I’m actually working to create a finder automation script which will accomplish all of this for you with a simple right-click.
PC users have the luxury of h264info – I wonder, is there something out there for Mac?
March 10, 2008 at 1:51 am
Sorry for the late replies. RL issues.
@Aerodiver:
Still haven’t gotten around to it. Probably within the next week.
@Cobiwan:
Not by this method. Look up methods of transcoding and you’ll find such thing. FFmpeg is capable of this. Though any method will take hours (at least) to complete the operation which is why conversion without transcoding is so sought after.
@gambit:
This tutorial is about getting an a/v file to play on a PS3 (can it?). Though it still should be able to be played in VLC. Perhaps you have one of those “special” files that don’t work (I’ve had this once before). Could be a codec problem as well. Not really sure without more info.
I don’t mean to side step this issue. But, blog comments aren’t exactly the best place to debug a problem. I’ve found that the people at macrumors.com are friendly and helpful. On your first post, I’d recommend posting the output of mkvinfo (of course removing info identifying what you have).
@phyber2004:
Glad I could help
mp4creator has a switch to force a level. But, I haven’t had any luck using it for lack of documentation and lack of time to go through the code and figure out acceptable values for that switch myself. Failing this, one could make a simple Python (it’s included in base OS X) script to do the job. It is, after all, just flipping a couple bytes in the video.h264 file. But again, I don’t have time to do that myself.
March 10, 2008 at 5:43 pm
Thanks oddmanout, great tutorial!
By the way I’m having 2 problems: first if the resulting file is greater than 4Gb mp4creator give an error and the resulting file will be unplayable. I’ve tried smaller files, like HD TV Shows for example and they work fine.
Second, i’m trying to convert the audio to AAC 6 channels instead of stereo using ffmpeg, but the resulting audio stream has mixed channles mapping, no matter how much I try. The center speaker is mapped on the the right one, and so on for the others. Looks like is a problem with ffmpeg, anyone has tried it? Because for now I have to use Quicktime to create an AAC 6 channel file, but the process is very long and boring, first I have to export the audio track to a aif sound, then convert it into mov with aac 6 channel, and then export to mp4 with passthrough.
March 10, 2008 at 6:21 pm
You’re welcome.
Problem #1: Never had that myself. But, if there is a problem with mp4creator, best contact them.
Problem #2: See 1. Also, I don’t think that the PS3 can handle 6 channels. Or at least I’ve not seen any reports stating that. Are you saying that 6 ch AAC works on the PS3?
March 12, 2008 at 2:22 am
I tried out your latest method on [ edit for legal reasons ].
Now to the problem. The resulting mp4 files plays on my PS3 but every few seconds there is a pause in the file and then it continues. It’s kind of like the file is stuttering. The funny thing is that I tried out playing the aac file on it’s own as well as the video only mp4 file (before we combine the audio to it) and both times there were no pauses or stuttering of any kind. However, when the 2 tracks are merged into the mp4 file, the result is this disturbing stutter.
Can you please help me with this since my searches on the net have yet to yield any results.
Thanks and great work.
March 12, 2008 at 9:22 pm
For Linux owners (this is tailored to GENTOO but thats only the packages) I have put together this script.
Read the top comments and get the software you need install 1st.
copy the text below to a file somewhere on your linux box. chmod 755 the file so you can execute it.
This does a 1.2Gb home video in 17 mins on a P4 3gz
syntax is ./ps3convert filename.mkv
[ Edit to remove script. Post scripts as files elsewhere and link to them. That is assuming that it runs on OS X as well (please respect the blog topic). ]
March 14, 2008 at 8:56 pm
Hey guys, wanted to confirm that the PS3 does support 6-channel AAC in an MP4 file. You can download HD Trailers from apple in H264/AAC5.1, use QTPro to move it from MOV to MP4 with passthrough A/V, and the resulting file plays just fine on the PS3. I watched the Happening 1080p trailer this way.
March 15, 2008 at 10:31 am
Sorry for the long time taken in the delay.
Yes, the ps3 can handle 6 aac channles, if it’s attached by HDMI to a capable receiver (like the onkyo sr-605), best thing is that otherwise it will demux to 2 channels stereo on the fly! I’ve tested it myself, and I can have full 6 channels in aac through the ps3!
Right now I can accomplish that by opening the original mkv in quicktime with Perian installed, export the movie to sound to aiff, this will create an aiff soundfile with 5.1 channels. After, open in quicktime the aiff file, export to quicktime movie, selecting AAC 5.1 in the audio decoding options. After that, open the resulting mov file in quicktime, export to mp4 with passthrough option, extract the audio track from the mp4 with mp4creator in an .aac file.
At last, mux the aac file to the mp4 file created with mp4creator.
I still can’t handle files larger than 4Gb with mp4creator, but it’s better than the bug with mp4box which can handle at least files under 1.4 gb.
March 28, 2008 at 4:34 am
@John:
It could be many things. The PS3 does have limitations with video playback. I think that it’s around a 20,000 bit-rate, though that should be checked. If your video is just below that then adding in the audio could put it into problem territory and thus the stuttering.
If you are streaming the file, then it might be a network issue.
It might also be errors in the a/v data.
Asking the people at macrumors.com would probably be more fruitful.
@MacShodan:
Thanks for the report! I’ve tried using ffmpeg for the same end, but had some issues. Not sure if that was because of the specific file(s) or not though. Will try again, but ffmpeg doesn’t seem to have much support for > 2 channel audio.
April 27, 2008 at 2:02 pm
I found this so useful, I wrote a program to automate the patching. Thanks for the guide, I hope people find the program useful. Feedback please!
Faye
April 27, 2008 at 2:16 pm
Oops, forgot to put that it operates on .mp4 files, so can be used with the output of Quicktime Pro too.
May 2, 2008 at 1:31 am
Thank you for the info. I’ve put together a little script that assumes source video in mkv is mp4.
If anyone knows how could subtitles be muxed, share this knowledge. Since 2.30 supports DIvX subtitles, and DIvX is also a container, there should be the way …
[ Edit to remove script. See above comment about posting inline scripts. ]
May 7, 2008 at 1:31 pm
I saw that an option on mp4creator could be used to create an 4.1 profile MP4 file.
mp4creator -create=video.h264 -rate=23.98 -mpeg4-video-profile=4.1 file.mp4
You does not need hexedit to change values on video.h264
Thanks for your posts. Help me a lot.
May 9, 2008 at 1:37 am
I have tested -mpeg4-video-profile=4.1 on a file I have and it did not work. I still ended up 5.1 profile mp4.
May 16, 2008 at 5:41 pm
I got all this working (except mediatomb, which has been compiling for hours on my crappy core solo mac mini), but ran into the mp4creator 4GB limit problem mentioned above. Is this the error everyone else got:
[hostname:/Volumes/Non-Bootables] user% sudo mp4creator -create=video.h264 -rate=23.98 file.mp4
Password:
Error decoding sei message
Assertion failed: ((m_size <= (u_int64_t)0xFFFFFFFF)), function FinishWrite, file mp4atom.cpp, line 738.
Abort
[hostname:/Volumes/Non-Bootables] user%
I was just wondering won’t ffmpeg mux the component files? (And hopefully not have a 4GB limit?)
I found this command elsewhere to make a VOB container for the file:
ffmpeg -r 23.976 -f h264 -i movie.h264 -f ac3 -i movie.ac3 -vcodec copy -acodec copy -f vob movie.vob
wondering if you can simply change -f vob to -f mp4? Probably not but if the VOB file works do we care?
May 16, 2008 at 6:16 pm
Boy was that easy…
forget ffmpegx, if you use the option -use64bits with mp4creator, everything works, even on my 7.29GB file
May 16, 2008 at 8:47 pm
or not. -use64bits creates a playable video, but when you try to add the hint, it fails and makes it unusable. If you start all over again and skip the hint, get back to the same video only file, and try to add audio, it also fails…
And after 4 hours of compiling and mediatomb and it’s 59 dependencies, it fails (using current mediatomb-0.11.0) on:
python translator.py
File ‘/sw/src/fink.build/root-doxygen-1.4.6-1003/sw/share/doc/doxygen/src/translator.h’ not found!
make[1]: *** [language.doc] Error 1
make: *** [install_docs] Error 2
### execution of make failed, exit code 2
I’ve got a headache
May 20, 2008 at 5:56 am
@Keppie:
The last several times that I’ve looked at Fink, it pretty much seems abandoned. Which is why I personally use MacPorts and use it in this tutorial.
I have also updated the tutorial a bit. Mediatomb is now in MacPorts and the command is listed above.
May 31, 2008 at 5:23 pm
Hi. I’m desperate to know how to mux subtitles inside mp4 container in order to play correctly on my PS3.
I’ve successfully demux a MKV file in its three main tracks: AVC video, AAC audio, and ASS subtitle. The ASS file is not recognized in most of the apps I’ve tried (Mac & WinXP) so I’ve being trying converting to SRT which is recognized but without succeed in playing the sub in the PS3.
I’ll appreciate any tip to make this done. Thanks.
June 1, 2008 at 1:29 am
@Gaston:
Just googling ‘mp4creator subtitle’ gave a few hits that may be helpful and macrumors.com has many helpful people there that may have already solved this. Though I haven’t checked that out myself.
If you can’t figure out how to do this on the fly, you might want to consider recoding the subtitles right into the video. I’m not sure exactly how to do this (ffmpeg probably has options along these lines), but I’ve come across many files that have the subtitles planted right in them. So, it is technically possible. Of course this will take some time, perhaps prohibitive, but it is an option.
June 7, 2008 at 5:51 am
[...] MKV (h264) File to PS3 MP4 This is pretty much an addendum to my previous tutorial on the [...]
June 14, 2008 at 5:38 am
I’m all for free speech, but I’m also against hijacking a blog posting(s comments) for someone else’s own end. Especially when it’s a *very* limited “solution.” That’s what *their* blog is for (or forum postings when it’s on topic). So, a little cleansing for the sake of this blog entry’s karma and to get rid of the hijacking.
June 15, 2008 at 6:42 pm
This is a great tutorial. I noticed a lot of people saying they’ve written scripts for this. Can anyone email their automated script at andyc@yopmail.com?
June 15, 2008 at 8:13 pm
I noticed this on my stats page as an incoming link:
http://technogrip.blogspot.com/2008/05/assuming-you-have-ps3-and-some-media.html
And if you click on Faye Pearson’s name above, you would end up here:
http://indy.zippysoft.com/~faye/264level.html
Haven’t tried either, but that should get you started. There’s also macrumors.com which would be able to provide more help.
June 15, 2008 at 11:27 pm
Thanks! The one from technogrip was just what I was looking for!
June 16, 2008 at 4:46 am
Actually, as a followup to my last post, I am noticing some syncing issues using the script at technogrip. The audio is just very slightly off from the video (but enough to drive me crazy). I did not notice this issue when I was using macshodan’s method to extract the audio (using quicktime pro). Anyone have any suggestions?
June 16, 2008 at 7:18 am
Follow the manual method or ask on macrumors.com.
July 2, 2008 at 1:46 pm
The one from techogrip is not quite OK, since it doesn’t check track types.. if e.g. track 1 is audio and not video…
July 2, 2008 at 9:14 pm
I got everything to work – also created a script that processes files for me – but when a mkv has DTS track, the sound gets static – is there a way around this?
July 2, 2008 at 9:20 pm
I haven’t had problems with that. Ask on macrumors.com.
December 8, 2008 at 5:42 am
[...] next step, however, is where I’m at a loss on how to proceed. In the guide(s) I used (found here and here), I’ve been instructed to use HEXEDIT to change some numbers in the h.264 video file [...]