Here's a quick perl script that batch rips files.
I've been ripping my DVD library into .mkv's for Plex.
The general setup is this, I have a big HD full of VIDEO_TS folders that uses the following structure:
>Hard Drive
>>Movie Name
>>>VIDEO_TS
>>Movie Name
>>>VIDEO_TS
>>Movie Name
>>>VIDEO_TS
etc...
I give the script a fileIn and then define a fileOut. The script goes through the target directory, lists all the contents and then batch converts. The script is NOT recursive so it does not go deeper then the root level of the fileIn directory. Wouldn't recommend keeping any other stuff in that target directory 'cause I'm not sure what will happen if you do.
All of the user variables are defined at the head of the script. Fairly self explanatory. If you can't follow basic unix commands or file paths you might want to reconsider using this script.
The perl script has some of the more basic rip variables included (the one's that I use at least) and it's a fairly simple matter at add additional ones. In addition there's an option to create a folder based on the name of the ripped file and move the rip. Also generates a log file for the entire process.
Code: Select all
#!/usr/bin/perl
###############################################################################
# perl script : HBbatch_rip.pl - Batch-encoder script for HandBrakeCLI
# Author : Craig Lyn
# Date : 11-10-2009
# Requires : HandBrakeCLI
###############################################################################
# Description:
# This script scans the contents of a directory and then batch encodes each
# enclosed VIDEO_TS file into a user defined format. There is an option to move
# the output into a directory based on the name of the file. The script also
# generates a time/date stamped log to plot the progress of long rips.
###############################################################################
# Disclaimer:
# I don't have much time to support this script so it's released as is. If you
# have difficulites with tasks such as file paths or basic Unix command line
# skills I would recommend NOT using this script. For now I've only put in the
# user defined variables that I use the most.
# For the log file name OSX does not allow ":" in filenames and instead subsitutes
# "/" for H:M:S separators.
###############################################################################
# Todo:
# - add additional user defined batch variables
# - script is having issues dealing with apostrophes " ' " in file names
# - does not like simlinks for some strange reason
###############################################################################
########## timestamp ###############
$starttime = timestamp();
######### user variables ###########
# path to the directory on the hard drive where the ripped DVDs are stored
$fileIn = '/Volumes/RAID\ 1/input'; # path to VIDEO_TS files
$fileOut = '/Volumes/Raid\ 1/output'; # output directory for ripped files
$logfile = "/Volumes/RAID\ 1/output/$starttime HBbatch log.txt"; # define a path for the output log and give it a name
# Turn on Ripping; Turn on moving
$do_rip = 1; # on/off rip the files with HandBrakeCLI
$do_move = 1; # on/off create a directory for the ripped movie and then move the ripped file
# array of the names of all of the .mkv files
@targetfile = `ls $fileIn`;
# number of elements in the array
$arraysize = @targetfile;
# Handbrake Variables
$verbose = 0; # -v turn on verbosity level from 0-2
$title = 1; # -t select the title from the DVD to encode.
$chap_start = 1; # chapter to start ripping
$chap_end = 1; # chapter to end ripping
$chapters = "$chap_start-$chap_end"; # -c default is to encode all but will have to remove flag from command line
$format = "mkv"; # -f output format: avi mp4 m4v ogm ogg mkv
$markers = 1; # -m turn chapter markers on or off
$encoder = "x264"; # -e encoders: ffmpeg xvid x264 theora
$bitrate = 2000; # -b ouput video bitrate
$twopass = 1; # -2 turn two pass encoding on/off
$turbo = 1; # -T turn on speedbost for first pass encoding
$audiotrack = 1; # -a select audio track
$aencoder = "ac3"; # -E audio encoders; faac lame vorbis ac3
$pixelratio = 1; # -p store pixel aspect ratio in the video stream
$decomb = 1; # -5 turn decomb (interlacing filter) on/off
$fsubtitle = 1; # -F turn on/off forced subtitling
########### create log file #############
open (MYFILE, ">$logfile");
print MYFILE "Batch conversion started: $starttime \n \n";
close (MYFILE);
########### run loop #############
print "\nThe following directories will be ripped: \n";
print "@targetfile\n";
print "Please type 'go' and hit Return to start the batch conversion: \n";
# STDIN takes the command line input
$go = <STDIN>;
# chomp removes the end carridge return and end space from the inputs
chomp $go;
print "Batch rip launched: $timestamp \n \n";
if ($go eq "go")
{
for ($i=0; $i<=$arraysize-1; $i++)
{
if ($do_rip eq "1")
{
# write to logfile start time
$currenttime = timestamp();
open (MYFILE, ">>$logfile");
$counter = $i+1;
print MYFILE "$counter of $arraysize - $targetfile[$i]\n";
print MYFILE "$currenttime: rip started\n";
close (MYFILE);
print "$currenttime: rip started $targetfile[$i]\n";
chomp $targetfile[$i];
system("HandBrakeCLI -i $fileIn/'$targetfile[$i]' -o $fileOut/'$targetfile[$i]'.$format -f $format -v $verbose -a $audiotrack -t $title -c $chapters -e $encoder -b $bitrate -2 $twopass -T $turbo -m $markers -E $aencoder -p $pixelratio -5 $decomb -F $fsubtitle");
$currenttime = timestamp();
print "$currenttime: Rip completed $targetfile[$i]\n \n";
# write to logfile end time
open (MYFILE, ">>$logfile");
print MYFILE "$currenttime: rip completed\n \n";
close (MYFILE);
}
if ($do_move eq "1")
{
chomp $targetfile[$i]; # remove carrige return from ls command if any
# create directory for each $targetfile
print "directory created for '$targetfile[$i]'\n";
system ("mkdir $fileOut/'$targetfile[$i]'"); # the 2 single quotes ' ' treats entire string as one without whitespace
# move target file into destination directory
system ("mv $fileOut/'$targetfile[$i].mkv' $fileOut/'$targetfile[$i]'")
}
}
}
open (MYFILE, ">>$logfile");
print MYFILE "Batch rip completed: $currenttime \n \n";
close (MYFILE);
print "Batch rip complete. Thank you, come again.\n \n";
########## timestamp ###############
sub timestamp
{
@Month_name = ( "January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December" );
( $sec, $min, $hour, $day, $month, $year ) = ( localtime ) [ 0, 1, 2, 3, 4, 5 ];
return sprintf "%02d:%02d:%02d %02d %s %04d", $hour, $min, $sec, $day, @Month_name->[$month], $year+1900 ;
#$starttime = $timestamp
}