This is a rough how to solution of how I convert mts/m2ts (h264) files from an HD Camcorder into mp4 video files that are playable on the xBox 360. The source mts/m2ts files are from a Canon HD Camcorder.
The Basics for this process are:
- Build/compile all of the libraries & binaries to do the video conversion on a linux system
- Use mencoder to de-compress the mts/m2ts video file into a (mostly) uncompressed avi file.
- Then use ffmpeg to re-compress the avi file using the x264 library back into a small HD file that the xBox 360 can understand & play
Step 1) I just used a spare computer, turning it into linux system (I have a decent working knowledge of linux, mostly in some sort of server capacity though). For this video conversion system I started with the desktop version of Ubuntu 9.10, and followed this thread in order to build the required video binaries:
http://ubuntuforums.org/showthread.php?t=786095
It worked well for the most part, but I ended up having to manually create symlinks (ln -s) in /usr/lib for the x264 lib:
/usr/lib/libx264.so -> /usr/local/lib/libx264.so
/usr/lib/libx264.so.88 -> /usr/local/lib/libx264.so.88
After doing this, ffmpeg finally saw the libx264 files, and would link to them when compiling.
Step 2) Once all the ffmpeg / mplayer / libx264 programs and libs were installed and configured properly. mencoder (mplayer) needed to be setup to uncompress the mts/m2ts files.
WARNING: These uncompressed video files are HUGE!
The following command was used to uncompress the mts/m2ts files, and was taken from here:
http://www.avsforum.com/avs-vb/showthread.php?t=789775&page=6
mencoder HD_Camcorder_file.mts -fps 60000/1001 -noskip -mc 0 -oac pcm -demuxer lavf -vf pullup,softskip -ofps 24000/1001 -ovc lavc -lavcopts vcodec=ffvhuff:format=YV12:vstrict=-1:aspect=16/9 -o UNCompressed_Video.avi
It should be noted that a couple of the mencoder options are used specifically for the Canon “pulldown” removal (more information about that is in the avsforum thread).
Also note that the -ofps option is set for 24,000/1001 to best decode the “24FP” fps recording option on the camcorder. There are circumstances where this needs to be changed to 30000/1001 which seems to be for the “60i” fps recording option. The final script below shows how this is auto-detected, and can automatically be adjusted for as needed.
Step 3) The final step is to re-encode the uncompressed avi video using the x264 library and an ffmpeg command:
ffmpeg -y -i UNCompressed_Video.avi -acodec libfaac -vcodec libx264 -vpre xbox360 -ab 192kb -b 17000k -v 0 -f mp4 xBox_HD_Video.mp4 </dev/null
As you can see this ffmpeg command requires that a special “predefined” encoding profile is used. Which is named “xbox360″. This ffmpeg profile is stored in the appropriate ./shared/ directory on the linux system, on my system the full path to the file is:
/usr/local/share/ffmpeg/libx264-xbox360.ffpreset
And the contents of this ffmpeg “predefined” profile uses these parameters:
coder=1
flags=+loop
cmp=+chroma
partitions=+parti8x8+parti4x4+partp8x8+partb8x8
subq=5
me_range=16
g=250
keyint_min=25
sc_threshold=40
i_qfactor=0.71
rc_eq=blurCplx^(1-qComp)
qcomp=0.6
qmin=10
qmax=51
qdiff=4
bf=3
refs=4
trellis=1
All of the parameters for that ffmpeg “predefined” profile needed for playback on the xBox 360 were learned about from this web page:
http://www.dslreports.com/forum/r19076412-How-to-transcode-video-with-ffmpeg-for-the-Xbox-360
It should also be noted that at the very end of that ffmpeg command is the parameter: “
This tells ffmpeg to accept incoming keyboard commands from /dev/null. Which basically tells ffmpeg NOT to accept ANY incoming commands. This final parameter is very important when trying to run the ffmpeg re-encoding process in the background through a shell script via a cronjob.
That is pretty much it for this guide. Here are a couple files that mill help you out:
- libx264-xbox360.ffpreset — ffmpeg xbox360 profile
- mts2xbox.sh — automated ALL-IN-ONE mts2xbox.sh script
The “ALL-IN-ONE” shell script has some verbose output of ffmpeg & mencoder turned off, as it is meant to log everything to a file, and run in the background. It also uses exiftool to embed the record date as metadata into the mp4 file.
And… it ALSO attempts to auto-detect major A/V sync issues, and then re-output the avi with different -ofps to auto-correct the problem.
Finally, these scrips / commands might not be the most perfect, or greatest solution to problem, but it works decent enough. If you find this helpful, or use it somewhere, please make a note of where you got it from. That is all I ask. Thanks!
Nice work on the mp4 conversion. Is there a way to just output back to .avi format that will work on the xbox? Why is the automated script meant to input .mts files, what are those?