CanonVixiaHF10InLinux

Webs: Faemalia -:- Greatprawn -:- Playground -:- Technical -:- Tweak
Technical Web Sections: Register -:- Users -:- Changes -:- Index -:- Search -:- Statistics

Video Modes

Getting the Canon Vixia HF10 working under Ubuntu Linux. The November 2008 version. The Canon HF10 video format is AVCHD files with PAFF interlacing on "progressive scan" video modes. So supposing you're filming 30fps 1080p, that appears to actually mean 60fps 1080i with some weird hacks to make it seem 1080p.

If you lower the bitrate in the HF10, then it actually changes the resolution to 1440x1080 or other weird resolutions. I recommend leaving it in the highest (17Mbps) bitrate setting for the purposes of getting true 1080p output at the end of the process.

So supposing you're filming at 17Mbps 30fps "progressive," the camera is outputting a 1920x1080 60fps PAFF-interlaced MTS-encapsulated h.264 stream with some AC3 audio encoding that makes most Linux players unhappy. Your job is to get this into a 24fps (or 29.97fps, I'm having trouble figuring out which) AVI-encapsulated MPEG4 stream with a more standard AC3 audio encoding.

Transferring Video Files from the Camera to Linux Filesystem

It seems to me the flash card or USB cable methods are pretty failsafe at this point. I can't find anyone who has problems with this, and I don't have problems with it either. If you do have problems with this, the forums probably have answers for you. This page is meant to answer some questions that the forums never seem to answer, ie: how to get the video files into a format that actually works with typical Linux video players.

Converting (horked?) MTS files to (non-horked?) AVI Files

Just a super-quick primer. Video files are made up of Containers, Video and Audio streams encoded with Video/Audio codecs. So the container is just a file format; a way of mashing together some video and audio. The video portion of the file is encoded with a video codec (often to reduce file size). The audio is encoded with an audio codec.

The Canon Vixia HF10's MTS container appears to contain a horked h.264-encoded video stream and a horked AC3-encoded audio stream. We must use a current build of ffmpeg to convert these two streams to something that standard Linux video players are able to deal with. The fact that I choose an AVI file container is somewhat arbitrary: everyone else seems to be doing it, so I do too.

There are a lot of HOWTOs on this on the interwebs. They are all very convoluted and annoying and hard to deal with. Here's a short list of things I've seen that don't work or seem pretty bad:

I recommend downloading ffmpeg and using it to do the conversion for you. First, get ffmpeg from source (required as of 16 November 2008, but maybe an "aptitude install ffmpeg" will work in the near future). Compile it with libmp3lame support or not, if you don't want to use MP3 audio in your output stream. Note that in my example below I'm using AC3, not MP3, because all my players can play AC3 audio, and that's the closest format to the source stream.

sudo aptitude install lame lame-extras liblame-dev libx264-dev
wget http://ffmpeg.mplayerhq.hu/ffmpeg-export-snapshot.tar.bz2
bzip2 -dc ffmpeg-export-snapshot.tar.bz2
cd FFMPEGSOURCEDIR/
./configure --enable-libmp3lame --enable-libx264 --enable-gpl
make
sudo make install

What we've done here: use aptitude to get libmp3lame support (and lame itself, too, but you may not want/need that), get into ffmpeg source directory, compile it with libmp3lame support. Install it (into /usr/local).

Now we use ffmpeg to convert the .MTS file into something common Linux video players can play:

f=00000
/usr/local/bin/ffmpeg -y -itsscale 0:0.40681 -i $f.mts \ 
  -f avi -vcodec mpeg4 -b 6000000 -acodec ac3 -ab 128000 -s 854x480 $f.avi
mplayer -vo sdl -vfm ffmpeg -lavdopts fast:skiploopfilter=all $f.avi

What it all means:

f=00000 :: The $f.mts file to work with. Convert it to $f.avi leaving the original MTS in place.

-itsscale 0:0.40681 :: Rescale the input stream by a constant amount. Some explanation is due here. The Canon HF10 claims to be recording in progressive scan mode, but in fact it's using something called PAFF interlacing. I don't know what that is, except that it means your video stream has about 2x the number of frames it actually should have. Since the input stream has 60fps (I'm using the 30fps "progressive mode"), and the output stream must have 24fps (mpeg4 doesn't support 30fps), then I need to throw away all but 0.4x (24 divided by 60) of the input frames. However, for some reason, on my systems 0.4 doesn't work out exactly, so I have to put in a bit of fudge to keep the audio in sync. One hopes that ffmpeg will directly support AVCHD files with PAFF interlacing in the future so that we don't need to guess at this constant's value at all anymore.

I've only tested the constant on a 20-minute video stream, so if your videos are longer, do a test transcode once of your entire stream. If the video is early, make the constant larger. If the video is late, make the constant smaller. You probably only need to tweak it in the range of .40679 to .40683.

-s 854x480 :: I am resizing the video to a smaller size. Pick a size you prefer, or don't resize it smaller at all. I'm arbitrarily choosing the height resolution of a DVD movie (480 pixels) and then the 1.78:1 aspect ratio of the Canon Vixia HF10's file format to get 854x480.

-b 6000000 :: This is a 6000Kbit/sec encoding rate. I think that's a bit high for an 854x480 video, but for something like 720p (1280x720) it might even be a bit on the low side. I've done some side-by-side testing of XVID vs. MPEG4 codecs, and I'm not sure I can tell the difference when specifying the same bitrate for both codecs. Perhaps I don't know enough about the right parameters for feeding into XVID vs. MPEG4.

mplayer :: Now I'm using a standard build of mplayer to see if it can play the resultant AVI file. The extra options are just in case you're using a slow system or Xgl with a low-end video card. If your system is fast and has a nice video card, you should be able to just run mplayer without any options.

Tying it All Together

So I created a simple Perl script that will take a list of MTS files as input, generate and execute ffmpeg commands on those MTS files, and create AVI files as output. The script can be found here: http://faemalia.net/CoolStuff/convertMTStoAVI.pl.

--
PhiloVivero - 16-17 Nov 2008


Edit -:- Attach -:- Ref-By -:- Printable -:- More