Converting .m2ts/.mts video files to another format 16, April 2007 Mac Version .2 Original Linux work: Axel Olmos Mac OS X work: Jeffrey Wilson The scripts and instructions in this package are free to use and redistribute AT YOUR OWN RISK!! Standard disclaimers apply. There is NO WARRANTY. These instructions are for people who have recorded .m2ts/.mts videos using a high def camcorder and want to play them on their Linux / Unix / Mac OS X computer, or want to convert them to another format. Ideally, this should be accomplished at full resolution and sound quality using Open Source software. I have many libraries already installed since I do scientific programming, so I may have missed some details. This was all tested on a MacBook Pro using footage from a Sony HDR-SR1. You need to have the Development Tools installed and Xcode updated to 2.4.1. This means that OS 10.4 / Tiger is needed. Some familiarity with Terminal.app (or other terminal program) and unix commands are also necessary. The administrator password will also be necessary to install some software. This procedure also takes up a LOT of hard drive space. A 68 second *.MTS clip (132 MB) will require nearly 5 GB of disk space for the conversion! The following software is required: Package Source URL ------- ---------- wget http://www.merenbach.com/?page_id=17 svn http://www.codingmonkeys.de/mbo/ xporthdmv http://www.w6rz.net/xport.zip JM http://iphome.hhi.de/suehring/tml/download http://iphome.hhi.de/suehring/tml/download/jm12.1.zip x264 http://www.videolan.org/developers/x264.html liba52 http://liba52.sourceforge.net/files/ ffmpeg http://ffmpeg.mplayerhq.hu/download.html Program Description ------- ----------- wget Non-interactive downloading of files from the internet. svn Subversion source code management software. xporthdmv xport Transport Stream Demuxer. ldecod part of the JM H.264/AVC Reference Software. x264 h.264 encoder. liba52 AC3 processing ffmpeg general purpose video converter. If you have not done so yet, install Xcode. It is part of the developer tools which can be found on one of your install disks (10.4). #wget--------------------------------------------------------------------------- This is used by the download script to obtain the open source software necessary for the file manipulation. Andrew Merenbach has compiled this program and nicely packaged it. http://www.merenbach.com/?page_id=17 #svn---------------------------------------------------------------------------- Get svn (Subversion). http://www.codingmonkeys.de/mbo/ has a nice packaged version. This is needed to obtain some software below. #xportdmv----------------------------------------------------------------------- Use your web browser to get http://www.w6rz.net/xport.zip . If xport.zip did not automatically decompress/unzip, double-click on it to do so. In a terminal, navigate to the xport folder and type: gcc -o xportdmv xport.c ; chmod 755 xportdmv Copy xportdmv to some place in your path (such as ~/bin or /usr/local/bin). #jm12.1------------------------------------------------------------------------- Use you web browser to get http://iphome.hhi.de/suehring/tml/download/jm12.1.zip . Versions change often, so if it fails, just change the 12.1 below to whatever is listed at http://iphome.hhi.de/suehring/tml/download . If jm12.1.zip did not automatically decompress/unzip (makes a folder called "JM"), double-click on it to do so. In a terminal, navigate to the JM folder and type: chmod 755 unixprep.sh ; ./unixprep.sh cd ldecod ; sed -i s/-march=pentium4//g Makefile ; make ; cd bin I think I got an error from that sed command, but it can be safely ignored. Rename ldecod.exe to ldecod and copy it to some place in your path (such as ~/bin or /usr/local/bin). #x264--------------------------------------------------------------------------- Subversion (svn) is required for x264 and ffmpeg. These commands need to be typed in a terminal. svn co svn://svn.videolan.org/x264/trunk x264 cd x264 svn update ./configure make sudo make install cd .. You will be prompted for the root/administrator password to install the software. #liba52------------------------------------------------------------------------- You can follow the directions at http://wincent.com/knowledge-base/Building_liba52_on_Mac_OS_X I actually grabbed a52dec-snapshot.tar.gz instead, but I like being bleeding edge. #ffmpeg & mp3lame--------------------------------------------------------------- While not specifically a requirement, LAME is good to have for ffmpeg, especially if you want to output mp3 audio. Instructions for building ffmpeg and LAME for OS X are found at http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html . I do not use fink, so use his "optimistic" approach to obtain ffmpeg via svn. When configuring ffmpeg, I used the following command: ./configure --enable-libmp3lame --enable-x264 --enable-liba52 --enable-gpl Then you can do the "make" and "sudo make install", again requiring the root password. This worked for version SVN-r8743. #All set to go------------------------------------------------------------------ Hopefully everything has worked so far. Hopefully you have placed the binary files in your path. Below are the commands to be used for converting a sample movie provided by Alex Olmos. (% represents the command prompt) % xporthdmv -nh samplevideo.m2ts 1 1 1 % ldecod -i bits0001.mpv -o /tmp/samplevideo.yuv % mv bits0001.mpa /tmp/samplevideo.ac3 % ffmpeg -r 29.97 -s 1440x1080 -i /tmp/samplevideo.yuv -i /tmp/samplevideo.ac3 -acodec copy \ -vcodec mpeg4 -aspect 16:9 -b 15000k samplevideo.avi Well, it works! Sort of.... VLC and Mplayer will play the file fine. However, Quicktime 7 does not support aspect ratios != 1. For more info, http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-quicktime-7.html section 14.6.4. However, with Quicktime Pro, there are export settings for 1440x1080i HD, so I am not sure why it is not reading the content right. Here is what you do. Iin Quicktime, go into the Movie Properties, and change the size to 1920x1080 (turn off "perserve aspect ratio"), and save the film. It will display just fine then in Quicktime, but iMovieHD does not recognize the scaling. What you really need to do is Export... the film as a Quicktime Movie with Size... "HD 1440 x 1080 16:9" and Settings... "Apple Intermediate Codec" and the preset compressor "HDV 1080i". Then, iMovieHD sees the clip with the right ratio. If you have no audio in Quicktime, then you may need to get the ac3 codec. Try this: http://perian.org/ But, iMovieHD apparently does not recognize ac3 audio, so you may want to "-acodec mp3" in ffmpeg or export from Quicktime as a different audio format. Sorry, I do not have much experience with iMovieHD yet. Don't forget to clean up those *.yuv and *.mpv files in /tmp ... they are VERY big. DO NOT DELETE YOUR ORIGINAL .m2ts or .MTS FILES. Save them in case a better solution to this problem appears in the future. Axel Olmos filtered@olmosconsulting.com Jeffrey Wilson n0nane@0ctane.net <- note the zeros.