Convert an x264 .mkv to an Xbox360 Compatible .mp4

Come up with a useful post-processing script? Share it here!
Post Reply
adr3nal1n
Newbie
Newbie
Posts: 6
Joined: December 18th, 2008, 6:54 am

Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by adr3nal1n »

This windows script basically takes a downloaded x264 encoded HD .mkv file and turns it into an Xbox 360 compatible .mp4 (Video is untouched & re-contained and Audio is re-encoded to AAC stereo for 360 compatibility)

You will need XenonMkv installed and configured for this to work. Go here for Xenonmkv http://xenonmkv.ev98.net/


cd /d %1
:mkv
if exist *sample*.mkv del *sample*.mkv
ren *.mkv input.mkv
move input.mkv d:\
cd /d c:\program files\xenonmkv\
XenonMKV.exe -inputfile d:\input.mkv -outputfolder d:\
cd /d d:\
if exist input*1.mp4 ren input*1.mp4 %3-1.mp4
if exist input*2.mp4 ren input*2.mp4 %3-2.mp4
if exist input.mp4 ren input.mp4 %3.mp4
move d:\*.mp4 "d:\HD Movies"
del d:\input.mkv
cd /d d:\!completed
rd /s /q %1
exit


Just tweak the output folders etc accordingly to suit your needs.

Hope this helps someone out.
adr3nal1n
Newbie
Newbie
Posts: 6
Joined: December 18th, 2008, 6:54 am

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by adr3nal1n »

There is actually very little to configure within Xenonmkv as the default options work just fine. The only options you may need to tweak are temp folder locations etc within the GUI. Xenonmkv also requires that .NET framework 2 is installed.

From experience, Xenonmkv works better than an equivalent piece of software called Gotsent. (Which also re-contains video and re-encodes audio for 360 compatible mp4 movies)

One other limitiation of mp4's with the 360 is that there is a 4GB max file size limitation so if you put a 9GB mkv through Xenonmkv it will turn out 2 mp4 files (Part 1 and 2 of the movie). The script accounts for this.

Hope this helps.
relman
Release Testers
Release Testers
Posts: 46
Joined: September 30th, 2008, 2:42 am

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by relman »

This interests me as I have already made a script like this which is converting my divx tv shows into mp4 ipod video for my iphone. I am interested in now converting my MKVs for Xbox. Issue is mp4's can't be played via media centre, only WMV video. I understand that converting from MKV to MP4 doesn't really encode the video as you are just switching the containers. Where as I understand converting to WMV is a little more hassle. Anyone seen a command line way to convert to a WMV HD format? or VC-1 ?
pauleapo
Newbie
Newbie
Posts: 1
Joined: July 5th, 2009, 3:58 pm

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by pauleapo »

Thanx for this script, i have got this working, but have noticed that when all complete the file is named input.mp4 is there anyway to keep the original filename? as it was downloaded? also can someone help me when this operation is complete i want the file to be moved onto my NAS drive where i will have a folder called converted eg. Z:\Downloads\Converted  is where i want all converted files to end up

Sorry  for the noob questions but have no experience in scripting, so thanks in advance

;D
jayholler
Newbie
Newbie
Posts: 2
Joined: September 13th, 2009, 2:31 pm

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by jayholler »

I have one that almost always works for me running on Linux.  You'll need to compile ffmpeg with the x264 codec enabled:
### Transcode 720p H264 mkv files for the xbox 360

if [ -z $1 ]; then
    echo "Usage: `basename $0` filename"
    exit 0
fi

# Wait while any other ffmpeg processes are running
while [ -n "$(ps -ef | egrep "ffmpeg|HandBrakeCLI" | grep -v grep)" ];
do
        echo -e "\n[$(date +%b\ %d\ %Y:\ %H:%M:%S)]\nFound another instance of HandBrake or ffmpeg running, pausing 5 minutes..."
        sleep 300
done

# Get the beginning time from the date cmd.
START=$(date +%D\ %T)

# Email us that the next process has begun
echo -e "About to start transcoding $1 at $START" > /tmp/emailmessage.txt
/usr/local/bin/email.sh

# ffmpeg cmd
ffmpeg -y -i $1 -threads 2 -s 1280x720 -aspect 1280:720 -r ntsc-film -vcodec libx264 -g 150 -qmin 8 -b 4500k -level 31 -loop 1 -sc_threshold 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -refs 2 -qmax 51 -maxrate 4500k -bf 1 -keyint_min 40 -async 1 -acodec libfaac -ar 48000 -ac 2 -ab 384k  $1.m4v

# Get the ending time of the transcode process from the date cmd.
END=$(date +%D\ %T)

# Inform us with an email that transcoding is completed
echo "Transcoding of $1 was started on $START and completed on $END." > /tmp/emailmessage.txt
/usr/local/bin/email.sh

# Move the original mkv file to the backup at /mkvs
mv -v $1 /mkvs

# Determine the appropriate place to move the file and do so
/usr/local/bin/moveMp4s.sh $1.m4v

exit 0
Then there is the email script:
#!/bin/bash
EMAILMESSAGE=`cat /tmp/emailmessage.txt`
DATE=`date +%A\ %B,\ %d\ %Y\ %r`
SUBJECT="Lunchbox notification: $(date +%A\ %B,\ %d\ %Y\ %r)"

#send an email using /bin/mail
echo $EMAILMESSAGE | /usr/bin/mail -a "From: Lunchbox " -s "$SUBJECT" [email protected]

#remove the old file, will this prevent duplicates from fsniper?
rm /tmp/emailmessage.txt
and finally moveMp4s.sh:
#!/bin/bash
#
#/usr/local/bin/moveMp4s.sh
#
# Jay Holler 09-10-2009
# Find *.m4v files in the Downloads directory and move them to
# the appropriate folder on the NFS share

storageDir=/storage/HDTV

cd /home/jayholler/Downloads

for i in *.m4v
do
myFile="$i"

if [[ "$myFile" =~ ([A-Za-z0-9\.]*)\.(S..E..).m4v ]] ; then
        File=${BASH_REMATCH[2]}.m4v
        PreShowName=${BASH_REMATCH[1]}
        ShowName=$(echo $PreShowName | sed 's/\./ /g')
        echo "[*] A new episode of $ShowName is ready for your enjoyment in HD!: $File" > /tmp/emailmessage.txt && sleep 2
        [ -d "$storageDir/$ShowName" ] || mkdir -v "$storageDir/$ShowName"
        mv -v $myFile "$storageDir/$ShowName/$File"
        wget http://localhost:49153/web/ushare.cgi?action=refresh -o /dev/null -P /dev/null
        /usr/local/bin/email.sh
else
        echo "[+] $myFile does not match our TV shows, pushing it to /storage/HD Movies on lunchbox" > /tmp/emailmessage.txt
        mv -v "$myFile" /storage/HD\ Movies/$myFile
        /usr/local/bin/email.sh
fi
done
exit 0
OneStepAhead
Newbie
Newbie
Posts: 11
Joined: January 31st, 2010, 1:09 pm

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by OneStepAhead »

your script is way more complex then it needs to be, not sure why you are renaming the input files and all that.. here is what i use that works perfectly (xenonmkv.exe needs to be in the path):

cd /d %1
IF NOT EXIST *.mkv GOTO NOMKV
del *sample*.*
del *.srr
del *.srt
del *.nfo
del *.nzb
IF EXIST *.mkv XenonMKV.exe -inputfolder %1 -outputfolder %1
cd /d %1
IF EXIST *.mp4 del *.mkv
:NOMKV
exit


ideally i wouldnt be using *.mp4 and *.mkv, havent gotten around to fixing that yet, works fine as is for me anyway. also, remove the del *.'s if you want
Last edited by OneStepAhead on April 13th, 2010, 11:53 am, edited 1 time in total.
VisualFace
Newbie
Newbie
Posts: 3
Joined: August 8th, 2010, 11:07 pm

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by VisualFace »

How do you get around Win 7 UAC popping up every time the script tries to launch xenonmkv? I've gone into the properties section and checked off "Run this program as admin" also did the same in the compatibility for all users section and still nothing.
soopahfly
Newbie
Newbie
Posts: 5
Joined: September 7th, 2010, 5:41 am
Location: Sheffield

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by soopahfly »

I'm using the last script posted by OneStepAhead (Thanks!) but I'm not too clued up on my batch files anymore!

I'm wanting to move the converted file to my NAS on Drive T:\ once the XenonMKV Script has run.
Any idea how I could do that?
Last edited by soopahfly on December 15th, 2010, 1:33 pm, edited 1 time in total.
chmod
Newbie
Newbie
Posts: 1
Joined: January 23rd, 2011, 11:59 am

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by chmod »

I made a simple script to put in sabnzb's script directory.  It's simple and has worked for all of my downloaded mkv's so far, just edit to suit your requirements.  You can change to .mp4 if you want, just that for me ushare doesn't like mp4 extensions.

-------------------------

#!/bin/sh                                                                                                           
# script to convert an mkv to m4v                                                                                   
# Tools needed: mkvtoolnix, ffmpeg, normalize, neroaac (or faac), MP4Box (gpac).                                     
                                                                                                                     
cd "$1"                                                                                                             
                                                                                                                     
i=`ls *.mkv`                                                                                                         
filename=`basename "$i" .mkv`                                                                                       
fps=`mkvinfo "$filename".mkv|grep "Default duration"|head -n 1|cut -d'(' -f2|cut -c 1-6`                             
#sfreq=`mkvinfo "$filename".mkv|grep "Sampling frequency"|head -n 1|cut -d':' -f2|cut -c 2-6`                       
                                                                                                                     
mkvextract tracks "$filename".mkv 1:video.h264 > /dev/null                                                           
                                                                                                                     
ffmpeg -i "$filename".mkv -vn -acodec pcm_s16le -ac 2 audio.wav > /dev/null                                         
                                                                                                                     
normalize-audio -q audio.wav                                                                                         
                                                                                                                     
#faac -c $sfreq audio.wav                                                                                           
neroAacEnc -br 128000 -lc -if audio.wav -of audio.aac > /dev/null                                                   
                                                                                                                     
MP4Box -quiet -fps $fps -add video.h264 -add audio.aac "$filename".m4v                                               
                                                                                                                     
if [ $? -eq 0 ]; then                                                                                               
rm audio.aac audio.wav video.h264 *.nfo                                                                             
mv "$filename".mkv /data2/downloads/sabnzbd/mkv_storage/                                                             
#killall -HUP ushare                                                                                                 
fi

-------------------------------

Here's a modified one i made for use as command line.

-------------------------------

#!/bin/bash
# script to convert an mkv to m4v

if [ "$1" -a "$2" ];
then

filename=`basename "$1" .mkv`
fps=`mkvinfo "$filename".mkv|grep "Default duration"|head -n 1|cut -d'(' -f2|cut -c 1-6`
#sfreq=`mkvinfo "$filename".mkv|grep "Sampling frequency"|head -n 1|cut -d':' -f2|cut -c 2-6`

mkvextract tracks "$filename".mkv 1:video.h264

ffmpeg -i "$filename".mkv -vn -acodec pcm_s16le -ac 2 audio.wav

normalize-audio audio.wav

#faac -c $sfreq audio.wav
neroAacEnc -br $2 -lc -if audio.wav -of audio.aac

MP4Box -fps $fps -add video.h264 -add audio.aac "$filename".m4v

if [ $? -eq 0 ]; then
rm audio.aac audio.wav video.h264
echo "All Done!"
fi

else
echo "Usage: mkv2m4v.sh {filename} {target audio bitrate (eg: 128000)}"
fi

-------------------------------
sonicman
Newbie
Newbie
Posts: 4
Joined: December 16th, 2010, 2:04 am

Re: Convert an x264 .mkv to an Xbox360 Compatible .mp4

Post by sonicman »

Thanks! great script it works for both pal and ntsc files




sonicman
Last edited by sonicman on May 24th, 2011, 5:29 am, edited 1 time in total.
Post Reply