Transcoding MTS/M2TS AVCHD Video Into AVI Files with Free Software

dscn1233.JPGThis holiday season, I was an extremely lucky recipient of a Sony HDR-SR5 video camera with a whopping 40GB hard drive inside.

When I opened it, the first question in my head was not atypical of a Linux users’ train of thought:

“Is it compatible with Linux?”

The answer was a tiny bit more complicated than I imagined, and immersed me into the otherwise unknown world of video transcoding, which is something millions of people do every day but probably never think about it. The best example is on YouTube, where it happens behind the scenes in the Google computing cloud, and everything “just works.”

I’ve read a few things about the format the camera uses, called AVCHD. Even in Windows (or OSX for that matter) many people have headaches with the AVCHD format, so I figure that Linux users are probably going to be having a helluva time trying to get it to work.

The files the camera generates are compressed at an incredible 15:1 ratio. I’ve seen it mentioned that a Standard Definition compressed clip of is actually larger in file size than an HD clip in AVCHD format.

The compression is where a majority of the AVCHD format complaints come originate from, since there is not much out there in terms of being able to edit video stored in the format without uncompressing it first. It takes some rather respectable computing horsepower to actually convert the files into an uncompressed format that can be played with in a video editing software package. Using the method detailed here, it takes about 5-6 minutes to uncompress and transcode a minute of video, on an Intel Core2Duo running at 3.2GHz with 4GB of RAM and a 10,000RPM hard drive – OUCH!

When plugging in the Sony HDR-SR5, it functions as a USB Mass Storage Device. Copying files from the camera to the computer is a simple drag n’ drop affair. This would be a familiar process to anyone who has used a digital camera and imports pictures to their computer.

It would certainly be faster to playback the videos in real-time and capture them using the component outputs from the camera… but that wouldn’t be a challenge. I’ve never actually installed the software that came with the Sony Handycam, so I’m not sure what I’m missing out on, but it doesn’t seem like all that much, to be honest. I wouldn’t be surprised if it was the typical Sony software suite that is about as useless as the media it is distributed on.

Let’s get down to the meaty bits, shall we?

The first thing I searched for was “AVCHD Linux” and found a post over at AVS Forum. On a side note, my Google-Fu is really spot on lately.

That post is a gold mine. It literally contains everything we need to transcode the video into formats of our choosing that are usable in non-linear video editing programs such as Avidemux or Cinelerra.

m2tstoavi is the best information I have found (so far!) to uncompress the AVCHD video files on my camcorder and convert them into a .AVI file in Linux.

Installation is very simple, all it requires in Ubuntu is a quick apt-get install:

sudo apt-get install mplayer ffmpeg x264 faad2 faac a52dec mencoder faad libfaad2-0 libfaad2-dev subversion csh

Then edit the install script as noted in the README to grab the newest version of ldecod. Everything else is completely automated – nice job Axel!

I did need to modify the settings a tiny bit to actually get audio synchronized as well as fix a possible issue with the script itself. I had problems until I commented out the echo ffmpeg yadda yadda part. When modified, it runs the following commands:

xporthdmv -hn $file 1 1 1 && mv bits0001.mpa $audiofile
ldecod -i bits0001.mpv -o $videofifo &
ffmpeg -r 29.97 -s 1440x1080 -i $videofifo -i $audiofile -vcodec mpeg4 -sameq -acodec copy -aspect 16:9 -b 15000k

I’m using the m2tstoavi.fifo script that uses named pipes (denoted above with dollar signs) to stream the output of one command into another. It is efficient with disk space and does not fill up the drive as the regular m2tstoavi script does, not sure why the fifo version is not the default. Ah well, nothing is perfect.

Once installed, I just run this command to convert every MTS video in the current directory to .AVI files:

./m2tstoavi.fifo *

It turns this proprietary format mess:


Into precious memories:


All in all, I’m glad I don’t need proprietary software for this conversion. I really wish it were faster – but here’s the point of this exercise:

I never used Windows software, so I don’t know what I’m missing. I’m happy with the solution I have, and if 20 people comment on this post and say they can edit HD video in realtime, good for them.

If they do, then I would have a better reason to upgrade to a quad-core CPU.

Here’s a (VERY unpolished!) video talking about the process in a little bit more detail, and showing the actual encoding process and the finished result. I’m not responsible for anybody tripping out at the end on my extremely crazily bad camera skills in the rendered video.

Oh yeah, and for those of you who were wondering, I also received quite possibly one of the best books I’ve read in a long time… it’s all about how cool Eric S. Raymond is ninjas are.


  • moore

    For transcoding M2TS/MTS to avi, mpeg, etc. I use
    HD Video Converter for Mac
    This software easily can transcoding these files. I use it for a long time and I haven’t any problem with it.You can try it too.

  • gogee

    you’re the best man. thx for putting this together

  • Afchine


    Maybe someone can help me, I bought a new camcorder Canon HG21 and I tried to convert the M2TS files to AVI to be able to watch them on my laptop (OS Windows) but the quality is very poor, the original file size is 29MB and the converted file is only 714KB, the original video size was 1440×1080 and the converted video size is 176×144. Could you please let me know which software I can use for the better quality?

  • wenling

    Your original resolution is 1440*1080, and now you converted to 176*144, that’s why you get poor quality.

    Get a iSkysoft video converter, set the output format, and go to setting panel, set the resolution. If you want to convert to SD (Standard-Definition) video, 720*480 should be fine.

  • johnson

    4Media HD Video Converter you may try, it will convert all general and HD videos to HD AVI, H.264/AVC, HD MPEG4 TS, HD MPEG2 TS, HD WMV, MOD, TOD, AVCHD (M2TS, MTS, M2T), TS, TP, TRP, H.264/AVC, MKV, HD WMV, MPEG-4 and Quick Time etc. HD Quick Time and other general videos and audios. If you want a try, here:

  • Afchine

    Hi Guys, Thanks for your help, I bought the software WonderShare which is HD video converter and everything is perfect now. Once again thanks for your help.

  • orfeo

    Now you can use “ffmpeg”.

    hdffxvrt is your friend!.

  • Alan

    I have been fairly successful using HandBrake

    (Used mostly to create scaled-down, reasonably sized videos that can be easily shared with others.)

  • Alan

    P.S. Even Mac and Windows users need not be jealous…

  • roguededguy

    VLC plays MTS files natively. I use both ubuntu and Arch with Openbox and the MTS files from my Sony HDR-SR12 play just fine. Actually they play much better than in the SONY provided software for Microshaft and it doesn’t take hours and hours to transfer the files.

    I simply copy them over USB and play them in VLC that’s it.

    If you do want to encode though, Handbrake is the way to go.

  • roguededguy, I just want to point out, the MTS files may be slightly corrupt to SONY VEGAS if you then later try to use those MTS files in a project IF they are 2 GB files broken up automatically by the camera.

    I’ve had many 2 GB MTS files that SONY would either not import or not recognize the audio from. Allowing the (kind of annoying) Sony PC software to convert them (rejoin them) to larger M2TS files allowed me to import the same videos without issue.

    So I would recommend letting the import software convert the MTS files to M2TS as you take them off the video camera, in case they cause you grief when you try edit with them later.

  • Afchine

    Hi there, I have a very poor quality when I’m burning the M2TS to the DVD. I’m using the video-to-DVD application from Wondershare software. Do you have any idea?

  • For Transcoding AVCHD Video MTS/M2TS Into AVI Files with this Software.


    Can you give me a link to convert m2ts files?

  • Alex

    I use WinFF which is GUI frontend for ffmpeg to convert mts files produced by Canon VIXIA HF20 to smaller scale avi’s. For the target format choose AVI and XviD Widescreen preset. The result is perfect.

  • Ryu

    I use this command to compress my m2ts files :

    (4 threads for 4 processors…)

    ffmpeg -i file.MTS -threads 4 -deinterlace -y -vcodec libx264 -sameq -acodec ac3 -ab 192k -ar 48000 -ac 6 -s 1280×720 -r 50 -b 20000k outputfile.avi

    The result is very good! I hope it will be useful…

  • Tomás

    A little experience with ffmpeg

    ffmpeg -i 24Mps_input.mts -target pal-dvd output_24_dvd.mpg

    It works fine in my Opensuse 11.1. The only problem in my system was that the first version I’ve installed of ffmpeg did not run. It was i686, I replaced it for the i586 package and all it’s ok. Note that i use the pal system. Adjust your settings to ntsc if necessary.
    Sorry for my poor english, I hope at least it’s possible to understand me…
    Happy new year. Great post! Thanks all of you…

  • oudinmelanie09

    [b]Aunsoft MTS/M2TS Converter for Mac[/b] is a powerful Mac MTS/M2TS Converter tool to help you convert MTS/M2TS files on Mac OS X to other popular video formats with various editing functions and fast converting speed. It can let you edit and convert *.mts or *.m2ts files to MP4, 3GP, 3G2 AVI, MPG. MOV, M4V, MKV, AVI, FLV, VOB, FLAC, OGG, WAV, AC3, M4A, MP3, WAV etc.

    The program focuses on helping you to convert M2TS/MTS files to suitable format for editing software like iMovie, Final Cut Studio, FCE, Avid, Adobe Premiere Pro, etc, to stream MTS/M2TS videos to play on iPad, iPod, iPhone, Android phones, Zune HD, Apple TV, Archos, etc, and to load MTS/M2TS files to iDVD for burning DVD and so on. Moreover, the Deinterlacing and Simple gauss blur function in the program are very useful to recorded AVCHD file format, since it can remove the interlacing artifacts and image noise from recorded videos.

    [b]Why choose Aunsoft MTS/M2TS Converter for Mac?[/b]
    – Easily enjoy M2TS, MTS, and M2T videos everywhere with portable devices like iPad, iPod, iPhone, Blackberry etc.
    – Support AVCHD videos recorded by Sony, Canon, Panasonic, JVC, etc camcorder.
    – Convert 1080p, 1080i, 720p M2TS, MTS files to other format and keep pristine quality.
    – Compress or shrink big M2TS/MTS files to small size for burning to DVD.
    – Convert MTS/M2TS files to iMovie, FCE, FCP, etc for professional editing.
    – Set diverse profiles with different settings for one original file.
    – Excellent and characteristic audio/video sync technology.

    [b]Key Features:[/b]
    [b]Compress MTS/M2TS video size with best quality[/b]
    The Aunsoft MTS/M2TS Converter for Mac helps to reduce MTS/M2TS video size in large scale but maintain with the best quality. Just select the right video and audio bit rate. Once clicked the convert button, you can see the estimated output size.

    [b]Output videos for many uses[/b]
    You can convert MTS/M2TS videos to compatible formats for playing on various multimedia devices, for further editing in Final Cut Pro, FCE, iMovie, Adobe Premiere Pro, Avid, etc, for burning to blank DVD with iDVD, Nero, etc, or for uploading to YouTube, Myspace, Hulu, Websites, etc, or for playing on media players like WDTV, Apple TV, Popcorn, TViX, etc.

    [b]Comprehensive list of output video formats[/b]
    Aunsoft MTS/M2TS Converter for Mac supports helping you to rip and convert AVCHD (*.MTS, *.M2TS, *.M2T) videos to any other format like MPEG4, AVI, MKV, MP4, MPEG, FLV, MPG, DivX, Xvid, WMV, ASF, VOB, MOV, AAC, AC3, MP3, WMA, 3GP, etc.

    [b]Deinterlacing AVCHD (MTS/M2TS) files[/b]
    If your video source is from some interlaced AVCHD camcorders, you will find many annoying interlaces on the video. It’s easy to remove them in Mac MTS/M2TS Converter with the deinterlacing function. And it could be removed by default.

    [b]Trimming, cropping, merging MTS/M2TS files[/b]
    It is not a big deal if you have taken in some unwanted part or black edges on the MTS/M2TS videos. You can easily remove them with the trim and crop function. And you can also merge/combine/join several M2TS/MTS files into a single one.

    [b]Output settings for novices and veterans[/b]
    In order to enhance output video quality or let your output files more suitable for media devices, you can set output profile parameters like bitrate, resolution, sample rate, frame rate, codec, and channels. Batch conversion, fast speed.

    [b]Easiest, fastest conversion and best enjoyment[/b]
    Supporting multi-threading and batch process, the MTS/M2TS Converter for Mac automatically detects your CPU and offers you the best speed to convert video in a single click. Then it can bring a deluxe visual and acoustic feast with top-notch quality for you.

  • turtlerck

    Transcoding MTS/M2TS AVCHD Video Into AVI Files
    On PC

  • fgsfs

    iPad Video Converter can convert videos and audio to playback on iPad including convert AVI to iPad, WMV to iPad, MKV to iPad, AVCHD to iPad, YouTube(flv) to iPad. It can be done in a batch mode so as easily convert an entire a list of video files with very little effort.

  • Its like you learn my thoughts! You appear to understand so much about this, like you wrote the ebook in it or something. I believe that you just can do with some percent to power the message home a bit, but instead of that, this is wonderful blog. A fantastic read. I’ll certainly be back.

  • I personally was looking for plans for my personal weblog and uncovered your article, “Transcoding MTS/M2TS AVCHD
    Video Into AVI Files with Free Software | fsckin w/ linux”, will you mind in cases
    where I actually implement a number of your points? Thanks a lot -Henrietta

  • David

    For Mac users, clearly ClipWrap gives the best professional result

  • I actually wanted to share this particular blog, “Transcoding MTS/M2TS AVCHD Video Into AVI Files with
    Free Software | fsckin w/ linux” together with
    my own pals on facebook itself. I personallymerely
    planned to distribute your fantastic publishing! Regards, Alethea