Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #Author : Blazewardog (blazewardog on irc.rizon.net)
- #Version : 1.0
- #Updated : 7/10/2011
- #Purpose : This script is to automate the task of encoding
- use warnings;
- use strict;
- use Getopt::Std;
- my $VERSION = "1.0";
- #Programs
- my $x264 = "x264-32";
- my $mkvmerge = "mkvmerge";
- my $mkvextract = "mkvextract";
- my $avs2avi = "avs2avi";
- my $splitProg = "split_aud.pl"; #Also should support vfr.py
- #Options
- my @x264opts = qw/--preset veryslow --crf 17 --fade-compensate .6 --fgo 5/;
- my @mkvmergeopts = qw/--compression "1:none" --compression "2:none" --language "2:jpn"/;
- #Get and parse our options
- my %opts;
- getopts('o:i:a:s:h', \%opts);
- if($opts{'h'}){
- HELP_MESSAGE();
- exit 1;
- }
- my $output = $opts{'o'} ? $opts{'o'} : die("Need output name");
- my $input = $opts{'i'} ? $opts{'i'} : die("Need input script");
- my $audio = $opts{'a'} ? $opts{'a'} : die("Need Audio file");
- my $sizes = $opts{'s'} ? $opts{'s'} : "native";
- #get the sizes to encode
- my @sizes = split(',', $sizes);
- system("ls");
- foreach my $size (@sizes){
- print "Starting $size\n";
- my $videofile = encode_video($input,$output,$size);
- my $audiofile = encode_audio($input,$audio,$output);
- my $outputfile = mux($videofile, $audiofile, $size);
- cleanup($videofile,$audiofile);
- }
- #Encodes the video
- sub encode_video {
- my $input = shift;
- my $output = shift;
- my $size = shift;
- if($size ne "native"){
- my @dimensions = getDimensions($size);
- open (AVS, ">$output.$dimensions[1].avs");
- print AVS "import(\"$input\")\n";
- print AVS "spline36resize($dimensions[0],$dimensions[1])\n";
- close (AVS);
- print "Encoding $size with settings of @x264opts \n";
- system($x264,@x264opts,"-o \"$output.$dimensions[1].vid.mkv\"", "\"$output.$dimensions[1].avs\"");
- print "Finished Encoding $size\n";
- unlink("$output.$dimensions[1].avs");
- return "$output.$dimensions[1].vid.mkv";
- }else{
- print "Encoding $size with settings of @x264opts\n";
- system($x264,@x264opts,"-o \"$output.vid.mkv\"", "\"$input\"");
- print "Finished Encoding $size\n";
- return "$output.vid.mkv";
- }
- }
- #A bit missnamed, splits the audio only currently
- sub encode_audio {
- my $input = shift;
- my $audio = shift;
- my $output = shift;
- print "Splitting Audio\n";
- system($splitProg, "-mvr","-i \"$audio\"","-o \"$output.mka\"","\"$input\"");
- return "$output.mka";
- }
- #Muxes a video and an audio track
- sub mux {
- my $video = shift;
- my $audio = shift;
- my $size = shift;
- print "Muxing $size\n";
- my $outputname;
- if($size ne "native"){
- my @dimensions = getDimensions($size);
- my $dim = $dimensions[1];
- $outputname = "$output.$dim.mkv";
- }else{
- $outputname = "$output.mkv";
- }
- system($mkvmerge,"-o", "\"$outputname\"", @mkvmergeopts,"\"$video\"","\"$audio\"");
- return $outputname;
- }
- #Does a bit of cleanup
- sub cleanup {
- my $video = shift;
- my $audio = shift;
- unlink $video;
- unlink $audio;
- }
- #Returns an array of the width and height for the provided size
- #is empty if not a valid size (native also returns empty)
- sub getDimensions {
- my $size = shift;
- my @dimensions;
- if($size eq "1080p"){
- @dimensions = qw/1920 1080/;
- }elsif($size eq "720p"){
- @dimensions = qw/1280 720/;
- }elsif($size eq "480p"){
- @dimensions = qw/848 480/;
- }else{
- @dimensions = ("","");
- }
- return @dimensions;
- }
- sub HELP_MESSAGE {
- print <<HELP;
- $0 $VERSION
- Usage: $0 [options] -i INPUT -o OUTPUT -a AUDIO
- Options:
- -i INPUT
- The filename is assumed to be the avisynth script to be encoded
- -o OUTPUT
- The base part of any output filenames
- ex: EP01 would produce output filenames of EP01.720.mkv and EP01.480.mkv if encoding both versions
- -a AUDIO
- The audio file to use with the video, it will be cut according to any trims in the INPUT
- -s SIZES
- What sizes of video to encode in a comma seperated list, valid values are
- native - Encode whatever the script is at
- 1080p - Encode a 1920x1080 File
- 720p - Encode a 1280x720 File
- 480p - Encode a 848x480 File
- HELP
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement