Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
#1 | Link |
|
Registered User
Join Date: Jan 2007
Posts: 55
|
Guide: AVC video in MKV on PS3
I recently wanted to play some AVC Level 5.1 videos in MKV containers on my PS3. Searching through some of the recent threads on here gave me all the information I needed, and I was able to play the files perfectly.
Since the needed information is still a bit spread-out, I thought I'd summarize the steps I needed, both for the benefit of others looking to do the same thing and to see if anyone had any improvements to add to the process. ASSUMPTIONS 1. I've tested this procedure with a few dozen MKV files, but they were all in the same format: Video stream: H.264/MPEG-4 AVC (x264)2. My target was a Playstation 3 running version 2.01 3. I did not want to re-encoded the video 4. Audio was not as important: it may or may not be re-encoded (see below) 5. I get wordy in my explanations, so I hope you don't mind a little reading... INFORMATION SOURCES Here are some of the key forum threads that helped me put the process together: http://forum.doom9.org/showthread.php?t=120627 http://forum.doom9.org/showthread.php?t=131782 http://www.redkawa.com/forums/showthread.php?t=1906 TOOLS MKVINFO and MKVEXTRACT from the MKVToolnix package http://www.bunkus.org/videotools/mkvtoolnix/ Depending on which method you choose, you'll need some of these: H264Info http://sourceforge.net/projects/batchccews/ FFMPEG included in MPlayer http://www.mplayerhq.hu/ MP4BOX from the GPAC package http://gpac.sourceforge.net/ Nero AAC Encoder (NEROAACENC) http://www.nero.com/enu/nero-aac-codec.html EAC3TO http://forum.doom9.org/showthread.php?t=125966 http://madshi.net/eac3to.zip PROCEDURE SUMMARY Here are the steps. Look at PROCEDURE DETAIL if you want to know more. 1. Determine MKV Source Streams This tells you which MKV track is video and which is audio, and the video frame rate: Code:
mkvinfo.exe sourcefile.mkv Assuming track 1 is video and track 2 is audio: Code:
mkvextract tracks sourcefile.mkv 1:video.h264 2:audio.ac3 Method A: Use H264Info.exe from http://sourceforge.net/projects/batchccews/ Only change profile level to 4.1 (leave other fields blank) and write output to "video-changed.h264" Continue to step 4A Method B: Use a hex editor to change "0167640033" to "0167640029" at the beginning of "video.h264". Alternately, use BINREPLACE.EXE (attached here): Code:
binreplace video.h264 0167640033 0167640029 4A. Mux Video and Audio into VOB Replace "23.976" with frame rate from MKVINFO in step 1: Code:
ffmpeg.exe -r 23.976 -f h264 -i video-changed.h264 -f ac3 -i audio.ac3 -vcodec copy -acodec copy -f vob output.vob 4B. Convert AC3 to WAV Code:
eac3to.exe audio.ac3 audio.wav Code:
neroaacenc.exe -if audio.wav -of audio.aac Replace "23.976" with frame rate from MKVINFO in step 1: Code:
mp4box.exe -add video.h264 -fps 23.976 -add audio.aac -new output.mp4 You can change the extension to MPG or M2TS if you prefer - it won't make a difference. Multi-channel audio should work (assuming your receiver or TV does multi-channel). Trying to fast-forward or rewind during playback with break audio-video synchronization. Start playback from beginning to re-synch. 7B. Transfer File to PS3 Playback should work correctly, including fast-forward and rewind, but you won't get anything other than stereo audio unless your TV or receiver supports AAC natively. PROCEDURE DETAIL 1. Determine MKV Source Streams You need to know which stream is audio and which is video within the MKV file. MKVINFO.EXE (from the MKVtoolnix package) will tell you this. Code:
mkvinfo.exe sourcefile.mkv Code:
Default duration: 41.708ms (23.976 fps for a video track) 2. Demux the MKV Source File Since the PS3 doesn't presently know how to read MKV files, we'll "repackage" the audio and video streams it holds into something it does understand. We have to extract (or "demux") the streams first using MKVEXTRACT.EXE (which is also included in the MKVtoolnix package). Code:
mkvextract tracks sourcefile.mkv 1:video.h264 2:audio.ac3 If your video and audio tracks are not 1 and 2 respectively, then change those accordingly. For example, if MKVINFO.EXE told you that the first track is audio and the second is video, then just change the command to: Code:
mkvextract tracks sourcefile.mkv 1:audio.ac3 2:video.h264 3. Change MPEG-4 Profile Level You can skip this step entirely if the video in your source MKV file is already below profile level 5.1. You may want to keep reading if it's profile level 4.2, though. This step benefits from some explanation. If you're not interested in the background information, skip ahead to choose Method A or Method B. MPEG-4 players can handle different MPEG-4 profiles and levels. Basically, the higher the profile and level, the more horsepower is required to play the file back properly. As of version 2.01, the PS3 will officially play back MPEG-4 H.264/AVC High Profile streams up to Level 4.2. It turns-out the PS3 will actually play back Level 5.1 streams, though, if you simply trick it into thinking the stream you're playing is Level 4.2 or lower. It's quite likely it will fail to play some highly-demanding streams this way, but I haven't run into any so far. The PS3 will only check the beginning of the MPEG-4 file to see what profile and level it is. If it sees something above its officially supported rates, you'll see the dreaded "Unsupported Format" icon in the XMB. In my tests I found that, although the "Unsupported Format" icon went away when I changed my source files to High Profile - Level 4.2, the PS3 would show no video when I attempted to play back the file. Changing the file to High Profile - Level 4.1 resolved that problem, so that's what we're doing here. How do we change the MPEG-4 profile level without re-encoding the video? Since we're just going to trick the PS3 into thinking it's a Level 4.1 file, all we have to do is change the bits in the stream that tell the PS3 what level it is. We have a couple of options: Method A: H264INFO.EXE H264INFO.EXE lets you change various settings, not just the profile level. You can obtain the program here: http://sourceforge.net/projects/batchccews/ (as of this writing, the latest H264Info release is "Alpha 0.13"). Simply run the program, enter your source video stream, "video.h264", for the input file, "video-changed.h264" for the output file, and put 4.1 in the Level box. LEAVE EVERYTHING ELSE BLANK. When you hit the Start button, H264INFO will read the input file and create a new packet/block (I'm not sure which is the correct terminology for this) using the updated information you gave it. Because the program has to interpret each source packet and build each output packet, the processing can take some time. Also, you'll have to have enough disk space for both "video.h264" and "video-changed.h264", although you can delete "video.h264" as soon as this step is completed. Continue to step 4A. Method B: BYTE EDITING Instead of properly updating the profile level for every packet in the video stream, we can just update the first packet. This has the advantage of being very fast and not requiring disk space for a second copy of the "video.h264" file - we can just change the right byte in "video.h264" directly. There's a big "however" here, though: this only worked for me when using the MP4BOX.EXE method in the muxing step below. If you use this method and then mux the video and audio streams with something other than MP4BOX.EXE, you end-up with the ol' "Unsupported Format" icon on the PS3. I suspect MP4BOX.EXE reads the profile level in the first packet and writes that same level in all other packets as it does its muxing, while other tools write the profile level information from the source stream all the way through without change. Or something like that - a little more investigative work will reveal the details. So why not just always use MP4BOX.EXE for muxing? The reason is that MP4BOX.EXE only accepts audio in AAC or MP3 formats. If the audio in your MKV file is already in one of these formats or you don't mind converting it, then you're all set. I chose to convert the AC3 in my source file to AAC because the PS3 has an easier time playing it. Ok, so how do you edit the correct byte? You'll need a hex/binary editor for this (I use XVI32 - http://www.chmaas.handshake.de/delph...vi32/xvi32.htm - but it has the disadvantage of loading the entire file into memory, which will be a problem in many cases). Open "video.h264" in the hex editor. Right at the beginning of the file you should see: Code:
00 00 00 01 67 64 00 33 I wrote a little utility to change bytes like this. There are others out there, but I couldn't find one that you could ask to stop after it found and replaced the first match (you don't want it finding and replacing other "640033" further on in the file that may have nothing to do with the profile level). Here's how you use it: Code:
binreplace.exe video.h264 0167640033 0167640029 BINREPLACE.EXE works very quickly and can deal with files over 4GB in size. Continue to step 4B. Continued in next post Last edited by omf; 4th December 2007 at 09:24. |
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Jan 2007
Posts: 55
|
4A. Mux Video and Audio into VOB
We now have a video stream, "video-change.h264", in MPEG-4 AVC High Profile Level 4.1 (or lower) and an audio stream in AC3, "audio.ac3". The PS3 will play both of these formats, but we have to put the two together by combining or "muxing" them into one "container" file. The PS3 understands MPEG container formats. We're usually dealing with MP4 container files on the PS3, but MP4's only support AAC or MP3 audio in them, so we can't use an MP4 container for our AC3 audio. The PS3 is more flexible when it comes to other MPEG containers, though, so we're going to put our audio and video streams into a "VOB" file using FFMPEG: Code:
ffmpeg.exe -r 23.976 -f h264 -i video-changed.h264 -f ac3 -i audio.ac3 -vcodec copy -acodec copy -f vob output.vob This command just tells FFMPEG.EXE to take the contents of "video-changed.h264" and "audio.ac3" and create a VOB file named "output.vob" out of them. The "-f" options tell FFMPEG what format our input files are in so there's no guessing on its part. FFMPEG should go through this process quickly. Again, the speed of your hard disk(s) will determine how fast it gets done. Continue to step 7A 4B. Convert AC3 to WAV We're going to convert our AC3 audio into AAC because that's the accepted format for MP4 files. There are many ways to convert from AC3 to AAC. I chose this one because it seemed straightforward and created high-quality AAC files (I couldn't tell the difference between the resulting AAC and the source AC3). Using this method, we have to first decompress the audio from AC3 to WAV using EAC3TO.EXE - a utility created by a Doom9.org forum member (thanks, madshi!). You can find current documentation and a discussion thread here: http://forum.doom9.org/showthread.php?t=125966 madshi found that the AC3 decoder in the Nero package was the best sounding of several tested. EAC3TO.EXE will try to use this decoder if Nero is installed on your system. Check out his documentation for more details. The command is simple: Code:
eac3to.exe audio.ac3 audio.wav 5B. Convert WAV to AAC We'll now take the WAV file we created in the last step and convert it into an AAC file. Currently, the general consensus is that Nero's encoder produces the best output, so we'll use it. (Nero's encoder is free and available at http://www.nero.com/enu/nero-aac-codec.html - it is small and completely separate from any other Nero products.) Code:
neroaacenc.exe -if audio.wav -of audio.aac 6B. Mux Video and Audio into MP4 We now have a video stream, "video.h264", in MPEG-4 AVC High Profile Level 4.1 (or lower) and an audio stream in AAC, "audio.aac". The PS3 will play both of these formats, but we have to put the two together by combining or "muxing" them into one "container" file. MP4BOX.EXE will take individual streams like we have and combine them into a single MP4 file. Here's the command: Code:
mp4box.exe -add video.h264 -fps 23.976 -add audio.aac -new output.mp4 MP4BOX.EXE should go through this process quickly. Again, the speed of your hard disk(s) will determine how fast it gets done. 7A. Transfer File to PS3 "output.vob" is basically the content of your original MKV file, except that all the bits that said the video was profile level 5.1 now say it's profile level 4.1 (though we haven't actually changed any video) and it's all now in an MPEG container. The PS3 should play this file just as it is. You can change the extension to "MPG" or "M2TS", if you prefer - it won't make any difference to the playback. One problem you'll find is that trying to fast-forward or rewind during playback with break audio-video synchronization in weird ways. The only way to get it back in synch is to start the playback from the beginning again (stopping and starting where you left off won't fix it). There's no way I know of to fix this issue, which is why I opted to convert my audio from AC3 to AAC and create MP4 files instead. "Method B" tells you how to do this. 7B. Transfer File to PS3 "output.mp4" contains the original video from the MKV file (except that all the bits that said the video was profile level 5.1 now say it's profile level 4.1 - even though we haven't actually changed any video) and the audio converted in AAC format. Copy the file to the PS3 using whatever the easiest method for you is (I've tried both Memory Stick and files on a DVD-RW). Playback should work correctly, including fast-forward and rewind, but you won't get anything other than stereo audio unless your TV or receiver supports AAC natively. If you really want multi-channel audio and your receiver and TV don't have built-in support for AAC (currently most don't), then you'll have to use the AC3 method in "Method A". Last edited by omf; 8th December 2007 at 18:04. |
|
|
|
|
|
#3 | Link |
|
Registered User
Join Date: Oct 2001
Posts: 416
|
Nice tutorial, thanks!! Now how can we fool the PS3 into playing back VC1 encoded files from anything but a DVD/BD??
Can we change the bytes somehow?? Would be nice eh! Do you think sony will ever enable VC1 playback from USB HDD? I'm sure it's technically possible but I guess they don't want us to do that even though it works from a disc. Probably management telling engineers what to do
Last edited by tyee; 4th December 2007 at 07:35. |
|
|
|
|
|
#4 | Link | |
|
Registered User
Join Date: Jan 2007
Posts: 55
|
Quote:
I can't think of any purpose for VC1 playback on anything other than DVD/BD except for "ripped" Blu-ray or HD-DVD discs, so I'd be really surprised if anyone at Sony thinks it's a good idea.
|
|
|
|
|
|
|
#8 | Link | |
|
Caped Crusader
Join Date: Jul 2007
Posts: 247
|
Also I've found on the web and from personal experience the hex numbers can be different.
Quote:
Last edited by B4tm4n; 8th December 2007 at 16:09. |
|
|
|
|
|
|
#9 | Link |
|
Registered User
Join Date: Jan 2007
Posts: 55
|
Well, my assumption here was that you'd keep the same video filename if you were using the "byte editing" method. (Unlike the other method where you have to create a new file using H264INFO.EXE) I'll add a note about that in the guide - thanks.
|
|
|
|
|
|
#10 | Link | |
|
Registered User
Join Date: Jan 2007
Posts: 55
|
Quote:
Do you even need to change anything if the profile is anything other than "High Profile"? I was wondering if a Main or Baseline profile stream would play even if the Profile Level were left at 5.1 |
|
|
|
|
|
|
#11 | Link | |
|
Caped Crusader
Join Date: Jul 2007
Posts: 247
|
Quote:
|
|
|
|
|
|
|
#12 | Link | |
|
Registered User
Join Date: Jan 2002
Location: -
Posts: 115
|
Quote:
![]() I was getting confused with the A and B sections. |
|
|
|
|
|
|
#13 | Link |
|
masktools2 (ab)user
Join Date: Oct 2006
Location: PAL-I :(
Posts: 235
|
I have one (or two) question(s);
Level 5.1 does not support P4x4 macroblocks, right? And lets say that I have a file with this partition enabled, thus making the level unrestricted; would the whole hex modify step make it playable on the PS3? (Note that I don't have a PS3, asking out of curiosity and personal interest.) And what about the XBOX360? I know this probably isn't the best place to ask, and using search would probably prove to be quite useful, but in case anyone feels compelled enough to answer . How is it different to the PS3 in terms of AVC playback?Thanks |
|
|
|
|
|
#14 | Link | |
|
x264aholic
Join Date: Jul 2007
Location: New York
Posts: 1,752
|
Quote:
|
|
|
|
|
|
|
#17 | Link |
|
ангел смерти
![]() Join Date: Nov 2004
Location: Lost
Posts: 9,555
|
p4x4 is allowed in some but not all cases in levels >= 3.0. x264 doesn't enforce those restrictions, so its output may not be strictly conforming to the level, but on the other hand many decoders also aren't that strict and will play them fine. (Including PS3.)
|
|
|
|
|
|
#19 | Link | |
|
x264aholic
Join Date: Jul 2007
Location: New York
Posts: 1,752
|
Quote:
|
|
|
|
|
|
|
#20 | Link |
|
Registered User
Join Date: Sep 2003
Posts: 28
|
Nice tutorial, but imo pointless.
Sorry. You can achieve the same with red kawa's ps3 video mkv remux (just tweak the settings to re-encode instead of remux). Now, i know the goal was to not re-encode, but with all that messing about (just to end up with an mp4) i'd rather just set red kawa's prog up before going to bed, and in the morning i have an mp4. Surely the goal is still an avchd (IN sync) with 5.1. |
|
|
|
![]() |
|
|