Converting (Remuxing) an x264 .mkv for Playback on the Xbox 360

May 11, 2008 – 2:18 am by \m/ike

Looking to play some of those HD .mkv files you’ve been collecting on your Xbox 360? Looking for the Linux equivalent to GotSent on Windows? This is the guide for you.

Don’t let yourself become overwhelmed with the seemingly large number of steps involved with this. Trust me when I tell you the results are more than worth it. This is a far preferable method to re-encoding the entire mkv to .mp4 because 1) it’s infinitely quicker (less than a half hour for a 4.4gb file) because we’re only converting the audio and remuxing the streams and 2) there is no loss in video quality because the stream is left untouched.

Acknowledgements: Uber, mega, ultra thanks go to jexxie, m3_del, and hansa56 on the Ubuntu Forums for all their work and research on this topic and for teaching me how to do this. This is essentially a compilation / re-organization / expansion of the info found in these two threads: one two.

Setup

Before starting, we need to get our needed applications installed. First up is a patched version of MP4Box that fixes a bug with files larger than 2gb. The following commands should get you downloaded, patched, compiled, and installed:

cd ~
sudo aptitude update && sudo aptitude install zlib1g-dev
wget http://downloads.sourceforge.net/gpac/gpac-0.4.4.tar.gz
tar -vzxf gpac-0.4.4.tar.gz
wget http://linuxlove.info/files/gpac.patch
patch -p0 < gpac.patch
cd gpac
chmod +x configure
./configure
make
sudo make install

We’re also going to need the Nero AAC encoder:

cd ~
wget http://linuxlove.info/files/neroAacEnc
sudo mv neroAacEnc /usr/bin/
sudo chmod +x /usr/bin/neroAacEnc

Finally, we’ll need some packages from the repos:

sudo aptitude update && sudo aptitude install bbe mkvtoolnix mplayer normalize-audio

File Size Limitation

Now that we have all the required apps installed, here is an important note regarding file sizes. Any mkv that is larger that 4gb will have to be split prior to be converted. This is a limitation of the Xbox 360’s current playback capabilities. More about this in a bit.

Compatable Audio Formats

This technique currently works best for mkvs with either AC3 or DTS audio. Some of the newer formats, such as EAC3, are not officially supported by mplayer yet. If you really need support for these formats (I don’t see many mkvs with them yet), I’m fairly sure it can probably be compiled into it. Google around for info.

Some Handy Time Saving Scripts

1. Jexxie has written a really excellent script with lots of auto-detecting features. While I have used parts of it to make my own script, I have not actually used it to convert anything, so your luck may vary. It can be found here. I’m pretty sure the script does not currently auto-split any files larger than 4gb, so you’ll have to do this manually before running them through the script:

mkvmerge -o output.mkv --split 2300M input.mkv

Now you can use the script on each half independently.

2. Another option is to use my far more simple and noobish script. I have borrowed some stuff from Jexxie’s as well as added my own twists and optimizations to some of his techniques. I have found that my script tends to be more compatible and forgiving of various audio formats and encodes (this lies in my mplayer commands). I have used this script to convert over 120 movies and I’m going strong ;]. I have created two versions of the script, happy360, which is intended for files over 4gb (it splits the files and handles them separately for you), and happy360s (s for small, does not implement a split), which is intended for files under 4gb. The following commands will get them installed on your system:

cd ~
wget http://linuxlove.info/files/happy360
wget http://linuxlove.info/files/happy360s
sudo mv happy360* /usr/bin/
sudo chmod +x /usr/bin/happy360*

Now, simply type:

happy360 <filename>
(larger than 4gb files but less than 8gb, the script will need some changes to accommodate > 8gb mkvs)

or

happy360s <filename>
(smaller than 4gb files)

And after anywhere from a few to about twenty minutes, you should have your finished .m4v(s) in the folder.

The Old Fashioned Way

Too hardcore for the scripts? Let’s get dirty:

We’ll need to run two informational commands first:

mplayer -frames 0 -identify -ao null -vo null input.mkv

Note the fps of the movie.

mkvmerge -i input.mkv

Note which track is the video track (usually the first). Next, if we have a larger than 4gb file, we’ll have to split it and then work with each half separately. If your file is less than 4gb, you’ll be able to work with it as is. A split can be achieved by a:

mkvmerge -o output.mkv --split 2300M input.mkv

For simplicity, the rest of the guide will assume you didn’t have to split, but remember that you’ll have to repeat the remaining steps for each half if you did split. Next is extracting the video stream from the mkv:

mkvextract tracks input.mkv 1:video.h264

Where 1 is the track number of the video. Change accordingly if your mkv differs. We now have to change the profile level to 4.1 (note that this works on 90% of mkvs, some will still have blocky artifacts in the final product for some reason):

bbe -e “r 7 \41″ --output=videonew.h264 video.h264

You can remove your original video.h264 now if you like since we’ll be working with the new one. Next is extracting the audio from mkv:

mplayer input.mkv -novideo -ao pcm:fast:file=audiodump.wav -channels 2

This next step is optional but I highly recommend it. We can now normalize our dumped audio with a:

normalize-audio audiodump.wav

Next is converting the audio to 2 channel AAC LC:

neroAacEnc -lc -ignorelength -q 0.50 -if audiodump.wav -of audio.m4a

You can reduce the -q setting if you like for a smaller file but I find the output results with 0.50 to be real nice. Finally, we need to remux the new video and audio into the MP4 container:

MP4Box -new output.mp4 -add videonew.h264 -add audio.m4a -fps 23.976

Where 23.976 (fairly common for NTSC) is where the fps of the movie you noted earlier goes. This needs to be accurate or you will encounter nasty audio sync issues during playback.

That’s it! Get your file over to your 360 either by burning it to a dvd, sticking it on an external, or streaming it (more on this is a later guide) and enjoy your new method of acquiring HD content ;].

  1. 9 Responses to “Converting (Remuxing) an x264 .mkv for Playback on the Xbox 360”

  2. Thanks for the tut.
    However, it costs me to re-download the eps :)
    You shoulda warn user to not to run 2 conversion at the same time.
    It looks like you copied the original file to 1/ folder to process. And if you Ctrl+C out to convert the 2nd one, it’ll overwrite it.
    lol.
    If you can find a way to allow multiple conversion or perhap a queue method. Converting a collection one by one is no fun.
    I do appreciate your tut and other tut as well.
    :)
    Thanks.

    By bau on Jun 18, 2008

  3. I can’t tell you how many times I had to re-download things while developing the script and I do apologize for any inconvenience it may have brought you :P~.

    I don’t claim to be any expert whatsover in scripting (this is totally obvious just by viewing its source). I’m completely confident that someone could easily implement this in a much more friendly and effective way. This script is simply a strung together series of commands that worked for me, so I figured I’d share it with the world after seeing a few people interested in it too.

    This may sound stupid, but the way I get the script to convert multiple files is to create a text file that reads something like:

    happy360 input1.mkv
    happy360 input2.mkv

    When you ‘chmod +x’ it and then run it with ’sh [whatever]‘, it will go through one-by-one and convert. This may seem simple but it works for me. I’ll add a warning about CTRL-C and mention this simple queuing in a coming update.

    By \m/ike on Jun 18, 2008

  4. Thanks Mike, good to see some slightly more consise info on the subject. I’ll be writing a script that uses some other bits I picked up from various places to do this later on. I’ll be sure to post the results here if I have any success!

    By John Hunt on Jul 17, 2008

  5. Is the 4gb limit a problem for the fat32 filesystem rather than the actual media player?

    By iliketacos on Aug 9, 2008

  6. http://www.xbox.com/en-us/support/systemuse/xbox360/digitalmedia/videoplaybackfaq.htm#maxfilesize

    By \m/ike on Aug 10, 2008

  7. First of all I want to say thank you for the guide, but I have a problem. I can’t normalize the audiofile nor encode it with nero, because the audiofile is too big. The original mkv-file already contains mp4a/aac audiotrack, but it is 5.1 and not stereo:
    ID_AUDIO_FORMAT=MP4A
    ID_AUDIO_BITRATE=0
    ID_AUDIO_RATE=96000
    ID_AUDIO_NCH=6
    ID_LENGTH=7495.04
    The audiodump.wav is over 2gb big. Do I have to split the audiodump.wav or is there a possibility to extract the aac audiotrack and downsample it to stereo?

    By kara on Aug 16, 2008

  8. great guide, thanks a lot!

    By Mark on Aug 18, 2008

  1. 2 Trackback(s)

  2. May 13, 2008: LinuxLove.info » Blog Archive » Xbox 360 Media Sharing: Ushare and Fuppes
  3. Jul 17, 2008: John Hunt » Blog Archive » MKV (h.264) playback on XBOX360

Post a Comment