SilverWav's Journal

The best is yet to come…

Note: Remuxing mkv to avi for the Xbox 360

with 2 comments

Thanks to Zeroshade, details here.

Packages Needed:

mkvmerge, mkvextract (package mkvtoolnix), bbe, mplayer, normalize-audio, neroAacEnc, and mp4creator

Install command:

sudo apt-get update && sudo apt-get install mkvtoolnix bbe mplayer normalize-audio mpeg4ip-server

Get neroAacEnc here.

Manual Install:

cd linux
sudo mv neroAacEnc /usr/bin
sudo chmod +x /usr/bin/neroAacEnc here.

Example Usage:

./ file1.mkv

# zeroshade's script for remuxing mkv to mp4


## remuxer to remux AVC mkv videos to mp4's that can be sent to xbox 360.
#  requires: mkvmerge, mkvextract (package mkvtoolnix), bbe, mplayer, normalize-audio
#            neroAacEnc (
#            mp4creator (package mpeg4ip-server)

if [ -z "$MKV" ]; then
   echo "Usage: `basename $0` <MKV>";
   exit 5
# using a tmp file allows for extensibility
# if desired, the script can be extended using the audio track
# and codec by uncommenting the lines below
mkvmerge -i "$MKV" > /tmp/info.$$.txt
VID=`grep "Track ID .: video" /tmp/info.$$.txt | awk '{ print sprintf("%d",$3) }'`
#AUDINF=`grep "Track ID .: audio"`/tmp/info.$$.txt`
#AUD=`echo $AUDINF | awk '{ print sprintf("%d",$3) }'`
#AEXT=`echo $AUDINF | awk '{ print $5 }' | sed 's/(A_\|)//g' | awk '{ print tolower($1) }'`
FPS=`mplayer -identify "$MKV" -vc null -ao null -vo null -frames 0 2>/dev/null | grep ^ID_VIDEO_FPS | sed -e 's/^.*=//'`

rm /tmp/info.$$.txt

echo "------Zeroshade's remux script. MKV to mp4 V.$VERSION"

if [ -z "$VID" ]; then
    echo "Error getting video track from mkvmerge."
    exit 5

if [ -z "$FPS" ]; then
    echo "Error getting framerate from mplayer"
    exit 5

BASE=`echo $MKV | sed 's/\.mkv//'`
echo "------Extracting video track-----------"
mkvextract tracks "$MKV" "$VID:$BASE.h264"

echo "------Changing Profile-----------------"
bbe -e "r 7 \41" --output="$BASE.tmp.h264" "$BASE.h264"
rm "$BASE.h264"

echo "------Extracting audio track-----------"
mplayer "$MKV" -novideo -vc null -vo null -ao pcm:fast:file="$BASE.wav" -channels 2

echo "------Normalizing audio----------------"
normalize-audio "$BASE.wav"

echo "------Encoding audio to m4a------------"
neroAacEnc -lc -ignorelength -q 0.50 -if "$BASE.wav" -of "$BASE.m4a"

echo "------Removing origingal audio dump----"
rm "$BASE.wav"

echo "------Converting m4a to aac"
mp4creator --extract=1 "$BASE.m4a" "$BASE.aac"

echo "------Cleaning up m4a------------------"
rm "$BASE.m4a"

echo "------Creating mp4 video---------------"
mp4creator --create="$BASE.tmp.h264" -rate=$FPS "$BASE.mp4"

echo "------Adding audio to the video--------"
mp4creator --create="$BASE.aac" -rate=$FPS "$BASE.mp4"

echo "------Removing h264 and aac------------"
rm "$BASE.tmp.h264" "$BASE.aac"

echo "------Done! Enjoy your video! =)-------"


*Ignore this*
Working example of WordPress sourcecode:


Written by SilverWav

April 18, 2010 at 10:40 pm

Posted in Notes

Tagged with , , , , , , ,

2 Responses

Subscribe to comments with RSS.

  1. Converted over but no sound on the mp4. The following is the error.

    ERROR: could not open WAV file
    ——Removing origingal audio dump—-
    rm: cannot remove `[Horribleremux] Strike Witches 2 – 01 [1280×720 x264].wav’: No such file or directory
    ——Converting m4a to aac
    mp4creator: can’t extract track in file that doesn’t exist
    ——Cleaning up m4a——————
    rm: cannot remove `[Horribleremux] Strike Witches 2 – 01 [1280×720 x264].m4a’: No such file or directory
    ——Creating mp4 video—————
    Error decoding sei message
    ——Adding audio to the video——–
    mp4creator: can’t open file [Horribleremux] Strike Witches 2 – 01 [1280×720 x264].aac: No such file or directory
    ——Removing h264 and aac————
    rm: cannot remove `[Horribleremux] Strike Witches 2 – 01 [1280×720 x264].aac’: No such file or directory
    ——Done! Enjoy your video! =)——-


    July 14, 2010 at 7:39 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: