Scripted use of HandBrake to re-encode video
My workflow for importing media from my cameras reflects the fact that video is just as important to me as still images, and beginning to dominate in terms of storage needs. Which is saying a lot considering that I have a Canon 5D Mk2 and take a lot of RAW images which are over 30MB each.
Video originates mainly from my family's 2 point & shoot cameras - a Canon Powershot TX1, and my new (awesome summer camera) Canon D10, and to a lesser degree from the 5D Mk2.
Generally, the video is generally not particularly high quality - it's family orientated stuff that we really want to keep but doesn't need to be, for example, a 1080p 40Mb/s stream. So, I want to re-encode the footage to reduce my storage needs. In the case of video from the point & shoot cameras - I am well served by the "Universal" preset available in HandBrake (yes, I have an AppleTV), i.e. there' no noticeable quality loss but often storage is only 1/3 of the original. For footage from the 5D Mk2, I may use the "Universal" preset - which creates a 720p version that is still lovely and clear but uses only 10% of the storage (!!) or I handle the file using a different workflow (it will probably get used directly in Final Cut Express).
So, my workflow is something like this:
My "encode" script.
This script does the following:
#!/bin/zsh
# Author: balrob. Date: Feb 2010. Copyright: public domain.
set -G
for EXT in 'MOV' 'mov' 'AVI' 'avi'; do
for FILE in *.$EXT; do
BASE=`echo $FILE | sed s/.$EXT//`
HandBrakeCLI -Z Universal -i $FILE -o $BASE.mp4
touch -c -t `stat -f '%Sm' -t '%Y%m%d%H%M.%S' $FILE` $BASE.mp4
done
done
Yes, I know I could have used case-insensitive globbing, but that doesn't help me here:
sed s/.$EXT//
because sed is case sensitive.
Video originates mainly from my family's 2 point & shoot cameras - a Canon Powershot TX1, and my new (awesome summer camera) Canon D10, and to a lesser degree from the 5D Mk2.
Generally, the video is generally not particularly high quality - it's family orientated stuff that we really want to keep but doesn't need to be, for example, a 1080p 40Mb/s stream. So, I want to re-encode the footage to reduce my storage needs. In the case of video from the point & shoot cameras - I am well served by the "Universal" preset available in HandBrake (yes, I have an AppleTV), i.e. there' no noticeable quality loss but often storage is only 1/3 of the original. For footage from the 5D Mk2, I may use the "Universal" preset - which creates a 720p version that is still lovely and clear but uses only 10% of the storage (!!) or I handle the file using a different workflow (it will probably get used directly in Final Cut Express).
So, my workflow is something like this:
- Import from camera or card, using Image Capture, into an import folder - the same folder each time.
- Run my "encode" script from a Terminal window - see below (I could call this from Automator but haven't done so yet).
- From Finder, check the encoded video is ok. I have seen issues with Handbrake not creating usable output from very short input files. If all ok, delete the original video files.
- Import content into Aperture 3 (Yippee, Aperture 3 supports video !!)
- Kick off a Time Machine backup.
- Erase import folder.
My "encode" script.
This script does the following:
- Enumerates files of type avi & mov in the current folder and generates H264 mp4 files that can play on my AppleTV.
- Sets the timestamp of the mp4 files to be the same as the input file - since there is no EXIF-type data in the mp4 files you would otherwise lose the original time & date.
#!/bin/zsh
# Author: balrob. Date: Feb 2010. Copyright: public domain.
set -G
for EXT in 'MOV' 'mov' 'AVI' 'avi'; do
for FILE in *.$EXT; do
BASE=`echo $FILE | sed s/.$EXT//`
HandBrakeCLI -Z Universal -i $FILE -o $BASE.mp4
touch -c -t `stat -f '%Sm' -t '%Y%m%d%H%M.%S' $FILE` $BASE.mp4
done
done
Yes, I know I could have used case-insensitive globbing, but that doesn't help me here:
sed s/.$EXT//
because sed is case sensitive.
Comments
Cheers!