Skip to content

Instantly share code, notes, and snippets.

@mveinot
Last active June 17, 2019 23:47
Show Gist options
  • Save mveinot/fdb2a2a1e33c2a96645daf3e19325798 to your computer and use it in GitHub Desktop.
Save mveinot/fdb2a2a1e33c2a96645daf3e19325798 to your computer and use it in GitHub Desktop.
#!/opt/local/bin/perl
# ^ perl installed using Homebrew
# make it harder to suck
use strict;
use warnings;
# mediainfo command
my $height_cmd = "/usr/local/bin/mediainfo '--Inform=Video;%Height%' ";
# handbrake 720p profile
my $h265_720_cmd = "HandBrakeCLI -Z 'Matroska/H.265 MKV 720p30' ";
# handbrake 480p profile
my $h265_480_cmd = "HandBrakeCLI -Z 'Matroska/H.265 MKV 480p30' ";
# get a filename passed as a parameter (you could easily expand this into a loop to handle multiple named files)
my $file = shift;
## BEGIN
my $cmd = '';
# determine the height of the video
my $height = `$height_cmd $file`;
# if the height is 720 or more, use the 720p profile
if ($height >= 720)
{
$cmd = $h265_720_cmd.'-i '.$file.' -o '.$file.'.mkv';
} else {
# otherwise use the 480p profile
$cmd = $h265_480_cmd.'-i '.$file.' -o '.$file.'.mkv';
}
# run the command
system $cmd;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment