Last active
June 17, 2019 23:47
-
-
Save mveinot/fdb2a2a1e33c2a96645daf3e19325798 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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