ifnull
8/20/2013 - 9:52 AM

Encode videos for Vine

Encode videos for Vine

#!/usr/bin/perl

my @dimensions = split('x', $ARGV[0]);
my $srcWidth = $dimensions[0];
my $srcHeight = $dimensions[1];
my $input = $ARGV[1];
my $output = $ARGV[2];
my $crop = "";
my $startAt = 0;

if($#ARGV > 3) {	
	$startAt = $ARGV[4];
}

if($#ARGV > 2) {	
	$crop = $ARGV[3];
} else {
	if ($srcWidth >= $srcHeight) {
	   $cropAmount = int(($srcWidth-$srcHeight) + 0.99) /2;
	   $crop = "0:0:$cropAmount:$cropAmount";

	} else {
	   $cropAmount = int(($srcHeight-$srcWidth) + 0.99) /2;
	   $crop = "$cropAmount:$cropAmount:0:0";
	}
}

my $cmd="handbrake ".
	" --input $input".
	" --output $output".
	" --format mp4".
	" --encoder x264".
	" --vb 500".
	" --rate 24".
	" --vfr".
	" --quality 20".
	" --encopts level=3.0:weightp=0:subq=7:vbv-bufsize=10000:vbv-maxrate=10000:rc-lookahead=30:8x8dct=1:cabac=1:bframes=1:ref=1".
	" --maxHeight 480".
	" --maxWidth 480".
	" --height 480".
	" --width 480".
	# " --start-at-preview".
	" --start-at duration:$startAt".
	" --stop-at duration:5".
	" --crop $crop".
	" --custom-anamorphic".
	" --pixel-aspect 480:480".
	" --itu-par".
	" --display-width 480".
	" --modulus 2".
	" --markers".
	" --audio 1".
	" --aencoder faac".
	" --mixdown mono".
	" --arate 44.1".
	" --ab 160".
	" --drc 0.0".
	" --gain 0.0".
	" --audio-copy-mask aac,ac3,dtshd,dts,mp3".
	" --audio-fallback ffmpeg";
print STDERR "$cmd\n";
system($cmd);
sudo ln -s /Applications/HandBrakeCLI /usr/bin/handbrake
1. Download http://handbrake.fr/rotation.php?file=HandBrake-0.9.9-MacOSX.6_CLI_x86_64.dmg
2. Mount HandBrake-0.9.9-MacOSX.6_CLI_x86_64.dmg
3. Copy HandBrakeCLI to /Applications/HandBrakeCLI