How to recover video from AVCHD (using open source software) at
DV Info Net

Go Back   DV Info Net > High Definition Video Acquisition > AVCHD Format Discussion

AVCHD Format Discussion
Inexpensive High Definition H.264 encoding to DVD, Hard Disc or SD Card.

Thread Tools Search this Thread
Old February 25th, 2009, 09:28 PM   #1
Regular Crew
Join Date: Feb 2009
Location: Denver, CO
Posts: 46
How to recover video from AVCHD (using open source software)

Years ago I had an AVCHD camcorder and before any of the NLEs was out, I wanted to use my video. I found a tutorial and was able to string together a workflow to do this. Soon after, though, I bought a Xacti which shoots native MP4 files, and after I'd converted all my AVCHD footage, I stopped dealing in that format all together.

However, on this forum I've seen a number of people run into problems, so I'm putting in this thread my notes from back then, and hope that y'all who are interested can extend it to make a modern workflow (Things may have gotten easier since then, but at least things have probably changed.) I don't have any AVCHD to test with, and this isnt' really my original workflow, so I can't really help much.

There is, however, a commercial product that does essentially this (its a wrapper around these tools) and is probably the most cost effective way to do it, if you value your time above minimum wage. You can find it here: VoltaicHD | ShedWorx I have no connection with them, and can't say anything good or bad about the product as I haven't used it.

Ok, the workflow I used. It involved pulling the H.264 video and the AC-3 audio out of the AVCHD MTS (MPEG2) transport stream, rendering the audio to Stereo, and producing a standard MP4 file from the results (Which is easily used by iMovie, and probably Final Cut)

Here's where I first found out about it, a thread called "AVCHD .m2ts conversion for Linux" on the AVS Forum. Couldn't find a direct link in my notes.

Here's the process, more or less, that I used:
Converting .m2ts/.mts video files to another format
7, Feb 2007
Mac Version .1
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 (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
------- ----------
svn Martin Ott
JM H.264/AVC JM Reference Software Download
x264 VideoLAN - x264
ffmpeg Get FFmpeg

Program Description
------- -----------
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.
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).

Get svn (Subversion). I cannot recall where I got it from, but Martin Ott has a nice packaged version. This is needed to obtain some software below. There is also an svn gui available (svnX), but I have not tried it.

Use your web browser to get . If 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).

Use you web browser to get . Versions change often, so if it fails, just change the 12.1 below to whatever is listed at H.264/AVC JM Reference Software Download . If 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 ; ./
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).

Subversion (svn) is required for x264 and ffmpeg. These commands need to be typed in a terminal.

svn co svn:// x264
cd x264
svn update
sudo make install
cd ..

You will be prompted for the root/administrator password to install the software.

#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 FFmpeg on Mac OS X How-to .

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-mp3lame --enable-x264 --enable-a52 --enable-a52bin \

Then you can do the "make" and "sudo make install", again requiring the root

#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, 11.7.*Using MEncoder to create QuickTime-compatible files 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: Perian - The swiss-army knife of QuickTime components 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
Jeffrey Wilson <- note the zeros.
Liza Witz is offline   Reply With Quote
Old February 26th, 2009, 07:27 AM   #2
Regular Crew
Join Date: Dec 2008
Location: Smyrna, GA
Posts: 28
good information.

when i first got my camera, and was contemplating what NLE system to go with, i was also considering transcoding it to a format that FCP (older HD version on a G5) would support. i eventually gave up on the the process because it was just too much of a hassle to deal with every time, and ended up buying a NLE that naively supported AVCHD.
Jeff DeLamater is offline   Reply With Quote
Old March 4th, 2009, 05:49 AM   #3
New Boot
Join Date: Mar 2009
Location: Darmstadt Germany
Posts: 23
opensource kdenlive is worth considering

Thanks for the information. ffmpeg has made a LOT of advances in the past number of weeks, and so its support for AVCHD is even better now.

I posted on this here wrt ffmpeg and the opensource non-linear-video editor kdenlive sucessfully rendering some avchd raw videos on a few different computers:
Lee Matheson is offline   Reply With Quote
Old March 5th, 2009, 10:11 PM   #4
Regular Crew
Join Date: Feb 2009
Location: Denver, CO
Posts: 46
I'm glad to see that the open source software has moved forward in the past several years.

In considering getting a camera to use AVCHD, the workflow I'd really like to use is based on simply extracting the video and audio from the AVCHD files and putting them in an MP4 container.

The audio will have to be transcoded to AAC (probably) but the video is already H.264, and I'd really like to not transcode it.

It seems to me that MTS just means transport stream format, and all I really want to do is take the video that's there and put it into a different format file.

So far I've been unable to do so.

I'd be keen to hear suggestions for a method. The method above was based around extracting frames, storing them and then re-encoding. The resulting footage is high quality, but its a very slow process.

VLC seems to think it will do this, and it does it pretty quickly, but the resutling file plays back in quicktime player with just a GREEN screen and its aspect ratio is backwards (1888x1920 for some reason.)
Liza Witz is offline   Reply

DV Info Net refers all where-to-buy and where-to-rent questions exclusively to these trusted full line dealers and rental houses...

B&H Photo Video
(866) 521-7381
New York, NY USA

Scan Computers Int. Ltd.
+44 0871-472-4747
Bolton, Lancashire UK

DV Info Net also encourages you to support local businesses and buy from an authorized dealer in your neighborhood.
  You are here: DV Info Net > High Definition Video Acquisition > AVCHD Format Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search


All times are GMT -6. The time now is 03:51 PM.

DV Info Net -- Real Names, Real People, Real Info!
1998-2021 The Digital Video Information Network