Converting .m2ts video files to another format Version .6 11/6/2009 Axel Olmos The scripts and instructions in this package are free to use and redistribute AT YOUR OWN RISK!! Standard disclaimers apply. There is NO WARRANTY. This kit was originally created in 2007 when I bought a Sony HDR-SR1 camcorder. At that time mplayer did not play .m2ts / .mts files. Since then three things have changed... 1. Mplayer can play .m2ts/.mts, and also converts those files to other formats via mencoder. I still have severe lipsync issues when trying to play my .m2ts files directly with mplayer, but I anticipate that being resolved someday. 2. Mplayer can use libvdpau. This means that videos can use Nvidia hardware acceleration, and CPU requirements for playing back HD are no longer astronomical. 3. The PS3 can play HDR-SR1 .m2ts files perfectly via DLNA. As a result of these three developments, I no longer convert video files, and my expertise in this area of the past three years has returned to almost nothing. These instructions are for people who have recorded .m2ts 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. After looking at http://forum.doom9.org, and trial and error, I was able to come up with a procedure to make .m2ts files viewable on a Linux machine. This procedure requires: Package Source URL ------- ---------- xporthdmv http://www.w6rz.net/xport.zip JM http://iphome.hhi.de/suehring/tml/download http://iphome.hhi.de/suehring/tml/download/jm14.0.zip ffmpeg http://ffmpeg.mplayerhq.hu/download.html mplayer http://www.mplayerhq.hu/design7/dload.html Program Description ------- ----------- xporthdmv xport Transport Stream Demuxer. ldecod part of the JM H.264/AVC Reference Software. ffmpeg general purpose video converter. mplayer general purpose video player. If you have ffmpeg and mplayer already installed, great! If not, and you are running Linux, try: yum install mplayer ffmpeg x264 faad2 faac a52dec mencoder For everyone else, there are included scripts, download, configure, and compile that will try and build the packages above. I have only tested this package under Fedora Core 6 Linux, but it should be somewhat platform generic. (The svn portion of the scripts is untested, and if you don't have svn installed, you may want to acquire it through other means. svn is required to build ffmpeg and mplayer, if you don't have them already on your system.) To do a complete download, configure, compile, and install of the packages into /usr/local/bin, run the command: ./install Warning: The install script executes: sudo ./installasroot which has the same effect as running the script ./installasroot as the root user. If you do not have sudo installed and configured, just become root and run the installasroot script to copy the files into /usr/local/bin. It takes about 20 minutes for the download and build process to complete on my system. After successful installation, you should be able to convert a file named filename.m2ts with the command: m2tstoavi filename.m2ts Here is the procedure used to convert a .m2ts file by the m2tstoavi script: 1. Use xporthdmv to convert the file into .mpv and .mpa files. 2. Use ldecod to convert the .mpv file into a .yuv file. 3. Rename the .mpa file ldecod created to .ac3 At this point, a .yuv file and .ac3 file are created which should be standard. 4. Use ffmpeg to create a .avi file that contains the .yuv transcoded to something else and the .ac3 file. Step 4 is highly customizable. You should be able to transcode to whatever format you want at this step. There are different versions of m2tstoavi including m2tstoavi.fifo which uses a fifo to speed up the conversion process, and m2tstoavi.mencoder which uses mencoder instead of ffmpeg to create the video. Use whichever of the three versions of the scripts works best for you. The commands for steps 1-4 would look something like this, for a sample file named samplevideo.m2ts: xporthdmv -h 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 \ -vcodec mpeg4 \ -sameq -acodec copy -aspect 16:9 -b 15000k samplevideo.avi The commands above would produce a samplevideo.avi file that contains the converted version of the samplevideo.m2ts. In this example, it's converted to the mpeg4 codec, but you can use whatever codec you choose. The included example script m2tstoavi performs the conversion task, and makes things a little easier. Modify the m2tstoavi script to suit your specific transcoding needs by changing the mencoder line in the script. usage: m2tstoavi filename ... where filename is something like homevideo.m2ts and it will start the process, creating homevideo.avi as output. You can also use wildcards, like: m2tstoavi *.m2ts This process is extremely slow. You will need a LOT of disk space in /tmp. I have included a sample video file, samplevideo.m2ts. Try converting it and watch it with the commands: m2tstoavi samplevideo.m2ts mplayer samplevideo.m2ts DO NOT DELETE YOUR ORIGINAL .m2ts or .MTS FILES. mplayer plays .m2ts files now, and will only get better in the future. For those of your with a Sony HDR-SR1 AVC HD Camcorder and Linux: I plug in the HSR-SR1 to my USB 2.0 port and run the script: hdrsr1 which converts all the .MTS files in the camcorder to .avi and places them in the current directory. If someone comes up with a better process, please modify this package and run with the ball. Thanks to 0ctane from AvsForum for showing me how to get rid of the yuv->y4m conversion, and the readme_osx.txt. p28driver came up with the brilliant FIFO idea which greatly reduces disk usage when converting files. Thanks to alkayata from AvsForum for offering an updated m2tstoavi which I have included in m2tstoavi.alkayata. Axel Olmos ax@olmosconsulting.com