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.


  • geoffrey

    it is that easy try it and see

  • Travis

    I just did and neither VirtualDub nor Windows Movie Maker could open it.

  • geoffrey

    windows media player works with it

  • geoffrey

    add this codec Haali Matroska Splitter to your system

  • Cbotelho

    It’s not working with ubuntu 8.04…help-me!

  • peddu

    Here is how you do it in windows xp..

    Can convert to any format that super can handle. Converted 2 min m2ts video to DVD vob (the website explains converting to mp4, but you can select any other output format in super), took about 20 min.

    hope it helps,

  • Pingback: .mt2s video file conversion Kit for Linux/Unix/Mac OS X «()

  • Britt

    I have actually read this book cover to cover and Robert Hamburger is a genius. I am glad to see that others think so too. Thanks for the software… I would donate money but I don’t see a link… add one!


  • Saif

    What about converting it onto something that a BluRay player will read? Which software for Win XP?

  • Saif

    What if you simply wanted to put it on DVD-R in HD format for non-BluRay players & on a BDR for play in a BluRay player.


  • James

    When I try to run the apt-get line, I am having trouble. It appears that ffmpeg depends: libmp3lame0 and mplayer depends: liblame0, but libmp3lame0 conflicts: liblame0. Am I doing something wrong?

  • Dany

    It’s not working with ubuntu 8.04 ..anyone..?

  • Dennis

    I use this guide to convert avchd pal to mpeg4 matroska:

    It works quite well and fast under Ubuntu 8.04.

  • Hans

    Thanks Dennis! Works fine on my Kubuntu 8.04 (2.6.24-19 AMD64)

  • Doug

    What software other than iMovie can you use to pay MTS video files created by my Sony SR12?

  • Pingback: AVCHD video processing « My tech blog diary()

  • Matus from Kaypax

    Here is AVCHD VIDEO EDITOR for UBUNTU and other Linux systems: and

  • gordonmcdowell

    So once you’ve transcoded the video, what is your final video editing solution? I use Vegas 8 (under XP) and find it edits AVCHD ok in realtime (on a dual core), but it certainly taxes the machine. However, the Aiptek cameras which record MOV files in H.264 not only require exporting from QuickTime to MP4 (due to a gimped audio format… its the audio which requires the export not the picture data), but can NOT be edited smoothly in realtime. I’ve got a quad core Dell XPS 430 and multi camera editing of 2 Aiptek 720p videos results in 1-frame-per-second updating in my editor. Crazy slow.

    My point being even if you get a top-of-the-line PC, the cameras seem to be employing video compression which requires more and more power to decompress on the fly. It may be transcoding for responsive editing (like you have done) becomes the norm.

    (But once again in case it was lost in this rant, what do you use to edit?)

  • Robbie

    Doug, VLC media player for both Linux and Windows should play your files. And pretty much anything else too!

    It has many CODECs built in so other changes to CODECs on your system will not affect your ability to play video files.


  • gordonmcdowell

    Doug (and Robbie), my experience with VLC player is for some reason it does not play footage captured on my SONY HDR-SR1, often closing with an error. If anyone (Robbie?) has used it to play AVCHD footage captured with this camera and thinks the problem is me, please lemmie know!

  • Robbie

    Sorry to disappoint Gordon, the files I’ve played with VLC are not from this source so can’t confirm experience with that data. Good luck in your search for a solution.

  • Pingback: The Most Beautiful Smile In The World « This week in panospace()

  • ssnfang

    iSkysoft Video Converter for Mac is a professional Mac Video Converter.It can convert video files from one format to another format and convert video to audio for Mac OS X users
    Download here:

  • Ajay

    I think KDEnLive is a pretty good alternative. All I did was use package manager to install kdenlive, start it, import my clips, add clips to time line, export to DVD.

    Its still exporting… Things are looking good though.

    Good luck.

  • Robert Forsman

    I’m going to jump to the conclusion that the A/V sync issues are caused because the tool chain does not honor the time stamps on the original video. MPEG video and audio packets almost always have time stamps (PTS/DTS) which exist specifically to synchronize audio and video. If a demultiplexer strips these off, the multiplexer will not know what the exact skew between the two is and the final video will be out of whack. In order to have proper A/V sync every filter in the chain has to respect and preserve time stamps.

  • Pingback: Transcoding AVHD (Cannon HF100 .mts) into a usable open format (MKV w/ FFMPEG) « Init()

  • Pingback: links for 2009-02-20 « Where Is All This Leading To?()

  • Ian

    I dont get this! xport is a .exe file??? this is Linux and those dont work. How did you get this to run?

  • Ian

    Hey I got it working a while ago but forgot to comment back. This is great. I’m having the audio sync problem. Is the problem fixed if you put -hn in the xporthdmv command? I’m using just a -h because in –help there is no -n option. Sooo. What is the consensus on the sync problems?

  • Ian

    Audio sync problem with Mencoder FIXED…

    just add “-of lavf” right before “-o outputfile” in your encoding command.

    *drop all quotes when using this advice.

    : )

  • Hans

    Hi Ian,
    do you can post a full example with your Mencoder options? Thanks!

  • Ian

    I use a fully modified version of the script. I’ll put up a download for you later sorry I have no time right now…

    also, I am still perfecting a couple of things…

  • Loris

    I also had the audio sync pb.

    gave an easy mencoder based solution:
    mencoder 00001.MTS -o 1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=10000 -fps 50 -vf scale=1280:720

    (this is for PAL/Europe. For NTSC/states change -fps 50 to -fps 60000/1001)

  • Mike

    I have read several articles about tyransfering HD video to a format that my computer can reaqd, my mate had a Sony HD camera on holiday last year and I am trying to read the disc he has sent me. So far I have only nread a lot of rubbish, it is full so full of abreviations that I don’t know what I am looking at. If this is a sample of this website, I am sorry, it is a complete load of Cr**. Sory for the invective but I saw it on a previous section and thought it was appropriate.

  • Taffy Boyo

    Is there any software out there that leverages the massive parallel computational capabilities of the AVIVO system that ATI/AMD use in their HD48xx systems?
    I have one of these and want to process AVCHD in it’s uncompressed form. A program that can use the AVIVO system and runs on Linux and Vista would be awesome.

  • Hans

    I can highly recommend KDENLIVE to cut, convert and render MTS-Files (AVCHD). For me it’s simply the best OpenSource Videoeditor and a good replacement for Mainactor for Linux.

  • Gordon McDowell

    Hans, I’ll back you up on that (KDENLIVE = GOOD), although I have not edited a full project on it yet. My issue was being unable to capture HDV via firewire on my Ubuntu box. I don’t know if that was an issue with KDENLIVE or my OS install. But in terms of supporting a wide variety of footage, KDENLIVE took EVERYTHING i could throw at it.

    My only concern was that it appears a bit slow playing AVCHD… like SONY VEGAS was a bit more responsive in playing back the same footage. But then Vegas costs serious $, and is having trouble is Aiptek 720p files >2GB (which KDENLIVE does not have trouble with).

    I’m looking for a free video editing solution for schools, and I’ll be checking out KDENLIVE again on my next install of Ubuntu. I’m told there are multimedia Ubuntu distributions, so I’ll probably try start with a fresh install of one of those.

  • Hans

    Hi Gorden,
    i recommend to install ubuntu jaunty (final release date is 09/04/23) which includes a lot of necessary patches for kdenlive, ffmpeg, mlt, etc.. it works fine with my panasonic hdc-sd5. are you a teacher, too?

  • Gordon McDowell

    No, but wife is principle of a school, and I’m volunteering some time to help them set up editing suite. Windows Movie Maker being what it is. I’ll let let Jaunty come out and try again with that. Thanks.

  • luismanolo
  • mrucs

    I’ve got a number of files .avi .mpeg etc I want to put onto a AVCHD disc, but I need to convert them into the correct directory structure i.e. BDMV and CERTIFICATES etc any app that does it?

  • Ian

    There’s such thing as an AVCHD disc?

  • mrucs

    Yeah, you can make a AVCHD DVD, which uses the BBMV and CERTIFICATE folders like a blu-ray disc.

    This allows you to have higher then 720p resolution on the disc, you obviously need a blu-ray player to play the disc though.

  • Ian

    oh that actually sounds really cool. So its basically like putting dvd video on a cd?

    i wish i had a blue ray player. they’re too much.

  • Andrew

    Dude, take that video out. Good article and completely “like total” level of commentaries eehhmm, ha, mmm like you know…. Terrible! Take it off!

  • Ian

    what are you talking about?

  • Joe

    Ubuntu 9.04:

    $ sudo apt-get install mplayer ffmpeg x264 faad2 faac a52dec mencoder faad libfaad2-0 libfaad2-dev subversion csh
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    ffmpeg is already the newest version.
    Package faad2 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However, the following packages replace it:
    E: Package faad2 has no installation candidate

  • badger

    For Transcoding AVCHD Video MTS/M2TS Into AVI Files with Free Software. I use a program called HD Converter for Mac. You can download a free Demo version at

  • http://[email protected] gary

    for Ubuntu 9.04:

    sudo apt-get install mplayer ffmpeg x264 faad faac a52dec mencoder faad libfaad2-0 libfaad-dev

  • Megit

    I would stick to iSkysoft video converter that makes much easier when editing AVCHD video with Abode premere CS4.