shahine.com/omar/

homepage | Send mail to the author(s) contact

yet another Microsoft blogger

# Sunday, December 14, 2008

Batch re-encoding Canon PowerShot videos

Since having a kid we have sort of fallen in love with the movie taking capabilities of our point and shoot digital cameras. We take a lot of 30 second – 1 minute videos. Probably over 1,000 in the past 2 years. We then rate and tag them like we do our photos.

I have owned a number of Panasonic and Canon cameras over the years. Recently I switched back to a Canon PowerShot SD880 for a few reasons:

  • Wide Angle lens
  • Less noise than Panasonic cameras
  • H.264 Video Support.

The latter being the most important.  Previous video cameras all shoot their video using Motion JPEG. H.264 is the new hotness in video codecs. The only problem is that the Canon shoots the video in a QuickTime MOV container which is not readable by Windows 7 without the QuickTime codecs. Also the bitrate is around 10 MBps which is huge for the quality of video it shoots.

Well, I’ve been using Handbrake, which is a really awesome video encoder for Windows and Mac to encode some video files for our iPod Touch. It turns out Handbrake is a fantastic application for re-encoding these digigam video files. On average I am seeing at least 3x - 6x smaller encoded files with the same quality.

But using Handbrake each time I download videos can be a bit cumbersome. I’ve been messing around with PowerShell lately now that it’s build into Windows 7 and am really loving what I can do with it. I’ve never been a batch scripter and like the more object oriented nature to C# applications to do these kinds of things. PowerShell does the job really well once you get over the small learning curve.

Below is a PowerShell script I wrote that will take all the videos in one folder and encode them into another folder skipping any already encoded files.

All you need to do is configure the first 3 variables:

$sourceFolder = "C:\Users\Public\Videos\_Ingest\"
$destinationFolder = "C:\Users\Public\Videos\Encoded\"
$handBrakeCli = "C:\Program Files\Handbrake\HandBrakeCLI.exe"

$files = dir $sourceFolder *.mov

foreach ($file in $files)
{
	$baseName = $file.Name.Trim('.mov')
	$source = $file.FullName
	$destination = $destinationFolder + $baseName + ".mp4"

	if (Test-Path $destination)
	{
		Write-Output "skipping $source"
	}
	else
	{
		$scriptString = "-i '$source' -t 1 -c 1 -o '$destination' -f mp4 -p  -e x264 -b 2000 -2  -T  -a 1 -E faac -B 160 -R 0 -6 mono -D 1 -x ref=2:bframes=2:me=umh -v"
		$sp = [diagnostics.process]::start("$handBrakeCli", "$scriptString")
		$sp.WaitForExit()
	}
}

Posted Sunday, December 14, 2008    Permalink    Comments [1]  View blog reactions

 

Monday, January 05, 2009 7:55:47 PM (Pacific Standard Time, UTC-08:00)
Thanks for the script!
Stormside
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview