Encoding video from a Canon Vixia camera

I recorded some presentations at work recently using a Canon Vixia HF R21 video camera, and needed to encode the videos to lower resolution. It took me longer to figure this out than I expected, so I thought that I'd document the details.


The camera exposes an MTP interface when plugged in using USB, and the video files are stored under /AVCHD/BDMV/STREAM/. The M2TS container format is used, but the camera splits a single stream into multiple files such that each file is no bigger than 2GiB. These files need to be concatenated together before playing or re-encoding. Video is encoded using H.264 at an anamorphic resolution of 1440x1080 (i.e. it must actually be displayed at 1920x1080). The frames are interlaced at 50.96fps1. The bitrate can be set at 5, 7, 12, 17 or 24mbps. Audio is encoded using AAC with 2 channels at 48kHz, with a bitrate of 256kbps.


The best codecs in terms of storage space efficient seem to be H.264 and AAC, so that's what I chose to encode the output in. I wanted a good quality version at 720p, and a lower quality version at 480p. Since these were presentations, single channel audio is sufficient. I tried using both libav (previously ffmpeg) and mencoder and had trouble with both, but eventually got libav working.

Good quality

The command I used for good quality was:

avconv -i "$INFILE" \
    -acodec libfaac -ab 128k -ac 1 -coder ac \
    -vcodec libx264 -filter yadif -r 29.97 -s 1280x720 -aspect 16:9 \

Audio is reduced to mono and encoded in AAC at 128kbps. Video is resized to 1280x720, deinterlaced, and encoded in H.264 with the default quality settings. To adjust the quality one can use the --crf parameter (which defaults to a value of 23). At 30 the quality loss was easily noticeable.

On my Intel Core2 Duo P8600 this encoded at 10fps with a video bitrate of 700kbps and audio bitrate of 83kbps. This puts an hour of video at 339MiB. Adding -threads 2 allows both cores to be used, at the expense of slightly worse motion compensation. If this is too slow, one can select a faster x264 preset using the -pre parameter.

Low quality

The command I used for low quality was:

avconv -i "$INFILE" \
    -acodec libfaac -ab 128k -ac 1 -coder ac \
    -vcodec libx264 -filter yadif,crop=848:480 -r 29.97 -s 854x480 -aspect 53:30 \

Audio is encoded the same as above. Video is resized to 848x480, deinterlaced and encoded in H.264. Apparently codecs are more efficient when the resolutions are a multiple of 16 which is why the video is resized to 854 and then reduced to 848.

This encoded at 20fps with a video bitrate of 300kbps and audio bitrate of 83kbps. This puts an hour of video at 165MiB.

  1. The camera has options to use 30p and 24p in the menu, but this doesn't seem to have any effect. 

Trackback URL for this post:


H.264 isn't a free codec. In

H.264 isn't a free codec. In other words, I have to install the medibuntu repos on my machine before I can encode to it using mencoder. Don't have to do the same with xvid. On the other hand, f@ck freedom and go with something that will play well on the raspberry pi!

Secondly, consider transcoding to one of the supported DVD resolutions should you ever want to master DVDs at a later stage and the only video you have archived is the H264. 848 by 480, I would think, is non standard. The archiving codec thing is a bit of an odd one at the moment, but at least you'll be able to play a DVD in 10 years time.

Yeah, I realise H.264 isn't

Yeah, I realise H.264 isn't completely free (nor is AAC I think). I didn't really have time to compare it to Xvid+MP3, might do that at some stage. The libav 480p preset is 852x480, so it's only off by 4 pixels. Maybe multiples of 4 are good enough?