Encoding 5d mII video

The 5d mark II shoots rather high quality videos. Using ffmpeg it’s possible to view the specifics of the original file during encoding. For my example file I’ve been seeing the following:

  Duration: 00:02:24.50, start: 0.000000, bitrate: 41087 kb/s
    Stream #0.0(eng): Video: h264, yuv420p, 1920x1088, 39674 kb/s, 30 fps, 30 tbr, 3k tbn, 6k tbc
    Stream #0.1(eng): Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s

This shows the two parts of the file’s stream (#0.0 and #0.1) are divided between video (#0.0) and audio (#0.1). The video part is encoded using the h264 codec, which is a nice high quality / highly compressed video codec with a bit rate of 39,674Kb/s, so close to 40Mb/s. The audio is also a fairly high quality capture, using the uncompressed, 16bit (bit depth), little-endian, PCM format at a fairly high rate of 1,411Kb/s.

Recently I wanted to post up some videos I took of Niilo Smeds playing and the above clip is 2:24 seconds worth of video, which consumes 708Mb (yes ~one CD-R worth of data). This makes uploading to a free Vimeo account rather difficult due to the 500Mb per week limit.

I’ve turned to recoding the videos to a lower bit rate so that I can post and have the knowledge that I still have the original 1080p version to play with more later.

I found that mp4 was one of the few container formats that I could easily convert to from videos using the older firmware (that I’m currently upgrading). The older firmware captured at exactly 30 frames per second (not 29.97/sec), which seems to cause havoc for other container formats (like mpeg), but mp4 seems to be quite happy. I’m interested to see if the newer firmware, which allows some choice in frame rate will allow for converting to other containers or if the problem is actually localized to the open source libraries that are used for conversion.

For audio I would have liked to use the original audio (I am recording a guitar player after all) and there is the -acodec copy option to ffmpeg, but again the mp4 container format didn’t like the raw pcm audio. Instead I chose MP2, which didn’t have as much sound degradation as MP3.

After much playing with options my simple script to encode videos from the 5dMII for Vimeo is as follows:

#!/bin/bash

# Copyright Elliott Johnson 2010
# Distributed under the GPL-3.0
#    http://www.gnu.org/licenses/gpl.html

# For encoding video from my 5D into a high quality,
# small file format suitable for vimeo.

THREADS=7 # tune this to your number of execution units - 1

function help() {
  echo "$0: infilename outfilename"
}

INPUTFILE=$1
OUTPUTFILE=$2

ffmpeg -i $INPUTFILE \
       -b 14515.5kb \
       -s 960x544 \
       -r 30 \
       -threads $THREADS \
       -acodec mp2 \
       -ab 256kb \
       -ac 2 \
       $OUTPUTFILE

Leave a Reply

Your email address will not be published. Required fields are marked *