#!/bin/sh
for i in $(find $1 -name '*.mpg') ; do
/Applications/Video/HandBrakeCLI -i $i -o $i.mp4 -e x264 -b 300 -B 128 -R 48 -E faac -f mp4 -I -w 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1 -2 -T
done#!/bin/sh
for i in $(find $1 -name VIDEO_TS) ; do
/Path/to/HandBrakeCLI -i $i -o $i.mp4 -e x264 -b 300 -B 128 -R 48 -E faac -f mp4 -I -w 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1 -2 -T -L
done#!/bin/sh
for i in $(find $1 -name VIDEO_TS) ; do
#default
/path/to/HandBrakeCLI -i $i -o $i.m4v --preset="AppleTV" -2 -T -L -P
done
#!/bin/sh
# BatchEncode.sh is a script to batch execute the HandBrakeCLI
# Copyright (C) 2007 Mic Marvin
# set the global variables to default
toolName="HandBrakeCLI"
toolPath="/usr/local/bin/$toolName"
toolArgs="-e x264 -b 2500 -B 160 -R 48 -E faac -f mp4 -x level=41:subme=5:me=umh -m -p"
inputSearchDir="/var/lib/mythtv/videos"
outputDir="/var/lib/mythtv/videos"
# start main script
for moviefile in *.iso
do
dvdName=`basename "$moviefile" .iso`
inputFilePath="$inputSearchDir/${moviefile}"
outputFilePath="$outputDir/$dvdName.mp4"
cmd="$toolPath -i $inputFilePath $toolArgs -o $outputFilePath"
eval $cmd
rm -f -v $moviefile
done
exit 0#!/bin/sh
# usage is ./thisScript.sh minimumDuration SomeDirContainingVIDEO_TS
# duration is set in minutes ("30" equals 30 minutes)
# specify the container directory for the VIDEO_TS directory
# example ./handbrake-longer-than.sh 30 24_SEASON6_D1
#set default path to HandBrakeCLI
PathToHandBrakeCLI=/some/path/to/HandBrakeCLI
if [ "${1}x" = "x" ]; then
echo "Minutes not provided"
exit
fi
if [ "${2}x" = "x" ]; then
echo "VIDEO_TS path not provided"
exit
fi
time=$1
export time
for i in $(find $2 -type d -name VIDEO_TS) ; do
for title in $($PathToHandBrakeCLI -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 > (60 * ENVIRON["time"]) { print $3 "-" $5 } ') ; do
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
# you can change the preset or any other variables here
$PathToHandBrakeCLI -i $i -o ${2}-title${titlenum}-appletv.m4v --preset="AppleTV" -2 -T -P -t ${titlenum}
#output example: 24_SEASON6_D1-title1-appletv.m4v
done
done
chmod 777 ./handbrake-longer-than.sh./handbrake-longer-than.sh 30 24_SEASON6_D1ronnor wrote:This is slightly different from your request, but I figured out to to loop through a dir full of MPEGs (from my BeyondTV PVR).
- Code: Select all
for i in $(find $1 -name '*.mpg') ; do
/Applications/Video/HandBrakeCLI -i $i -o $i.mp4 -e x264 -b 300 -B 128 -R 48 -E faac -f mp4 -I -w 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1 -2 -T
done
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening testfile.mpg...
ERROR: dvd: DVDOpen failed (testfile.mpg)No title found.
HandBrake has exited.
trondmm, can you post your full CLI command and any changes you made to the script?
$ handbrake -i test.mpg -o test.mp4 -e x264 -b 300 -B 128 -R 48 -E faac -f mp4 -I -w 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:subme=6:no-fast-pskip=1:trellis=1 -2 -T
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening test.mpg...
ERROR: dvd: DVDOpen failed (test.mpg)No title found.
HandBrake has exited.
$ handbrake -i test.mpg -o test.mp4
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening test.mpg...
ERROR: dvd: DVDOpen failed (test.mpg)No title found.
HandBrake has exited.
$ handbrake -i test.avi -o test.mp4
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening test.avi...
ERROR: dvd: DVDOpen failed (test.avi)No title found.
HandBrake has exited.
$ handbrake -i test.mkv -o test.mp4
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening test.mkv...
ERROR: dvd: DVDOpen failed (test.mkv)No title found.
HandBrake has exited.
$ handbrake --aencoder faac --ab 64 --arate 48 --mixdown stereo --encoder x264 --vb 192 --format mp4 --x264opts "crf=18:ref=2:mixed-refs=1:bframes=3:b-rdo=1:bime=1:weightb=1:subme=7:trellis=2:analyse=all:level=3:merange=64:no-fast-pskip:me=umh:sar=1/1" --deblock --two-pass --turbo --drc 2 --width 480 --height 272 -i test.mpg -o test.mp4
HandBrake 0.9.2 (2008021900) - http://handbrake.m0k.org/
2 CPUs detected
Opening test.mpg...
ERROR: dvd: DVDOpen failed (test.mpg)No title found.
HandBrake has exited.
ronnor wrote:So, I'm starting to wonder if handbrake (or at the very least, my installation of handbrake) is able to convert standalone video files at all.
ronnor wrote:In a nutshell, it will process any mpeg2 file (DVD, Capture from most PVR cards, Transport Stream files from OTA HD, etc.).
ronnor wrote:(Did you try the GUI to see if you got an error there?)
Series/
24/
24_SEASON1_DISC1/
24_SEASON1_DISC2/
24_SEASON1_DISC3/
...
BABYLON_5/
B5_SEASON1_DISC1/
B5_SEASON1_DISC2/
B5_SEASON1_DISC3/
...filename=$(echo $i | sed 's/[/]/ /g') #!/bin/sh
# usage is ./thisScript.sh minimumDuration SomeDirContainingVIDEO_TS
# duration is set in minutes ("30" equals 30 minutes)
# specify the container directory for the VIDEO_TS directory
# example ./handbrake-longer-than.sh 30 24_SEASON6_D1
#set default path to HandBrakeCLI
PathToHandBrakeCLI=/home/snorre/hb/trunk/HandBrakeCLI
if [ "${1}x" = "x" ]; then
echo "Minutes not provided"
exit
fi
if [ "${2}x" = "x" ]; then
echo "VIDEO_TS path not provided"
exit
fi
time=$1
export time
for i in $(find $2 -type d -name VIDEO_TS) ; do
for title in $($PathToHandBrakeCLI -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 > (60 * ENVIRON["time"]) { print $3 "-" $5 } ') ; do
#this names the filename after it's parent folder
filename=$(echo $i | sed 's/[/]/ /g')
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
# you can change the preset or any other variables here
$PathToHandBrakeCLI -i $i -o /home/snorre/Videos/${filename}-title${titlenum}-iPhone.mp4 -Z "iPhone / iPod Touch" -t ${titlenum}
#output example: 24_SEASON6_D1-title1-iPhone.mp4
done
donefilename=$(echo $i | sed 's/[/]/ /g' | awk '{print $2}') #!/bin/sh
# usage is ./thisScript.sh minimumDuration SomeDirContainingVIDEO_TS
# duration is set in minutes ("30" equals 30 minutes)
# specify the container directory for the VIDEO_TS directory
# example ./handbrake-longer-than.sh 30 24_SEASON6_D1
#set default path to HandBrakeCLI
PathToHandBrakeCLI=/home/snorre/hb/trunk/HandBrakeCLI
if [ "${1}x" = "x" ]; then
echo "Minutes not provided"
exit
fi
if [ "${2}x" = "x" ]; then
echo "VIDEO_TS path not provided"
exit
fi
time=$1
export time
for i in $(find $2 -type d -name VIDEO_TS) ; do
for title in $($PathToHandBrakeCLI -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 > (60 * ENVIRON["time"]) { print $3 "-" $5 } ') ; do
#this names the filenameafter it's parent folder
filename=$(echo $i | sed 's/[/]/ /g' | awk '{print $(NF-1)}')
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
# you can change the preset or any other variables here
$PathToHandBrakeCLI -i $i -o /home/snorre/Videos/${filename}-title${titlenum}-iPhone.mp4 -Z "iPhone / iPod Touch" -t ${titlenum}
#output example: 24_SEASON6_D1-title1-iPhone.mp4
done
doneSnorreSelmer wrote:Thanks a lot to ronnor for getting me started on this.Now we could just use a few command-line options for maximum length, minimum length and input folder (and maybe even output folder).
Maybe something like:
-s "shorter than x minutes"
-l "longer than x minutes"
-i "input-folder"
-o "output-folder"
+ title 1:
+ chapters:
+ 1: cells 0->0, 36725 blocks, duration 00:01:28
+ 2: cells 1->1, 239064 blocks, duration 00:11:21
+ 3: cells 2->2, 171542 blocks, duration 00:08:46
+ 4: cells 3->3, 196490 blocks, duration 00:09:42
+ 5: cells 4->4, 257910 blocks, duration 00:12:55
+ 6: cells 5->5, 10099 blocks, duration 00:00:46
+ 7: cells 6->6, 178 blocks, duration 00:00:01
+ title 2:
+ chapters:
+ 1: cells 0->0, 37217 blocks, duration 00:01:28
+ 2: cells 1->1, 130575 blocks, duration 00:06:13
+ 3: cells 2->2, 124021 blocks, duration 00:06:18
+ 4: cells 3->3, 188030 blocks, duration 00:09:17
+ 5: cells 4->4, 134835 blocks, duration 00:06:47
+ 6: cells 5->5, 288224 blocks, duration 00:14:19
+ 7: cells 6->6, 10198 blocks, duration 00:00:46
+ 8: cells 7->7, 178 blocks, duration 00:00:01
+ title 3:
+ chapters:
+ 1: cells 0->0, 36964 blocks, duration 00:01:29
+ 2: cells 1->1, 172055 blocks, duration 00:09:06
+ 3: cells 2->2, 208151 blocks, duration 00:10:00
+ 4: cells 3->3, 251951 blocks, duration 00:12:11
+ 5: cells 4->4, 241960 blocks, duration 00:11:52
+ 6: cells 5->5, 10052 blocks, duration 00:00:46
+ 7: cells 6->6, 178 blocks, duration 00:00:01
+ title 4:
+ chapters:
+ 1: cells 0->0, 36990 blocks, duration 00:01:28
+ 2: cells 1->1, 145986 blocks, duration 00:07:28
+ 3: cells 2->2, 122029 blocks, duration 00:06:26
+ 4: cells 3->3, 215773 blocks, duration 00:10:29
+ 5: cells 4->4, 386394 blocks, duration 00:18:51
+ 6: cells 5->5, 9889 blocks, duration 00:00:45
+ title 5:
+ chapters:
+ 1: cells 0->0, 36725 blocks, duration 00:01:28
+ 2: cells 1->1, 239064 blocks, duration 00:11:21
+ 3: cells 2->2, 171542 blocks, duration 00:08:46
+ 4: cells 3->3, 196490 blocks, duration 00:09:42
+ 5: cells 4->4, 257910 blocks, duration 00:12:56
+ 6: cells 5->5, 10099 blocks, duration 00:00:46
+ 7: cells 6->6, 37217 blocks, duration 00:01:28
+ 8: cells 7->7, 130575 blocks, duration 00:06:13
+ 9: cells 8->8, 124021 blocks, duration 00:06:18
+ 10: cells 9->9, 188030 blocks, duration 00:09:17
+ 11: cells 10->10, 134835 blocks, duration 00:06:47
+ 12: cells 11->11, 288224 blocks, duration 00:14:20
+ 13: cells 12->12, 10198 blocks, duration 00:00:46
+ 14: cells 13->13, 36964 blocks, duration 00:01:29
+ 15: cells 14->14, 172055 blocks, duration 00:09:06
+ 16: cells 15->15, 208151 blocks, duration 00:10:00
+ 17: cells 16->16, 251951 blocks, duration 00:12:11
+ 18: cells 17->17, 241960 blocks, duration 00:11:53
+ 19: cells 18->18, 10052 blocks, duration 00:00:46
+ 20: cells 19->19, 36990 blocks, duration 00:01:28
+ 21: cells 20->20, 145986 blocks, duration 00:07:28
+ 22: cells 21->21, 122029 blocks, duration 00:06:26
+ 23: cells 22->22, 215773 blocks, duration 00:10:29
+ 24: cells 23->23, 386394 blocks, duration 00:18:51
+ 25: cells 24->24, 9889 blocks, duration 00:00:45
#!/bin/sh
###############################################################################
# Shellscript : hb.sh - Batch-encoder script for HandBrakeCLI
# Author : Snorre Selmer <snorre.selmer@gmail.you-know-the-rest>
# Date : 2008-09-07
# Requires : HandBrakeCLI, awk, sed
###############################################################################
# Description:
# This script does recursive scanning of a given folder and encodes all titles
# that are within an optionally given minimum and maximum length, and outputs
# the resulting files into an optionally given folder.
###############################################################################
# Cudos:
# - First of all, big thanks to the HandBrake team for making the most awesome
# MP4-encoder I've ever used.
# - Second thanks goes to the HandBrake CLI-forum (http://forum.handbrake.fr)
# and especially ronnor for making the script I used as a base for this one.
# I learned a lot from "disassembling" your script.
# - The SED and AWK tutorials at http://www.grymoire.com/Unix/index.html were
# a great help in understanding ronnor's script.
# - Finally, http://www.shelldorado.com/goodcoding/cmdargs.html is where I
# got the code for the commandline arguments. Excellent shell-script site!
###############################################################################
# Disclaimer:
# I give no guarantees that this script will work on your system. It works on
# mine (GNU/Linux Ubuntu 8.04 x86_64 with HandBrakeCLI svn1667) and that's the
# only place I've been able to test it so far. If you find a bug, let me know
# on the HandBrake forum at http://forum.handbrake.fr/viewtopic.php?f=10&t=5070
# and we can look at it.
# DO NOT E-MAIL ME BUGS! Bugs are best squashed when many can look at them,
# so use the forum!
###############################################################################
# Todo:
# - Sort out a command-line argument to enable deinterlacing
# - Sort out a command-line argument to select presets
# - Space for sale, user-input required
###############################################################################
#basic program-info stuff
name=`basename "$0"`
version='0.2'
#path to the HandBrakeCLI binary
CLIpath=/home/snorre/hb/trunk/HandBrakeCLI
#default minimum title-time (in minutes) to encode
longerthan=0
#default maximum title-time (in minutes) to encode (default = 24 hours)
shorterthan=1440
#the folder you want to scan for DVDs to encode
input=
#the folder you want to store the encoded files in (default is the folder you're in when you run the script)
output=.
#function that prints usage-instructions if the user input something wrong
Usage () {
echo >&2 "$name - HandBrakeCLI batch-script, v$version
usage: $name -i PathToDVDs [-o PathToSaveFolder] [-l MinimumTitleTimeToEncode] [-s MaximumTitleTimeToEncode]
-i: path to scan for VIDEO_TS folders.
-o: path to where you want to store the finished encodes.
Default: the current folder (./)
-l: only encode titles that are longer than this (in minutes).
Ex: \"-i 30\" will only encode titles longer than 30 minutes.
Can be used in conjunction with -s.
-s: only encode titles that are shorter than this (in minutes).
Ex: \"-s 30\" will only encode titles shorter than 30 minutes.
Can be used in conjunction with -l.
Example:
$name -l 30 -s 60 -i Scrubs -o /home/username/mp4
This will scan the subfolder Scrubs and encode all titles that are longer than
30 minutes and shorter than 60 minutes, and store them in /home/username/mp4.
Input- and output-paths can be either relative or absolute (ie. Scrubs, ../Scrubs or /path/to/Scrubs).
"
exit 1
}
BadArg() {
echo >&2 "Invalid argument.
Try \"$0 -h\" for more information"
exit 1
}
#command-line argument parser
while [ $# -gt 0 ]
do
case "$1" in
-i) input="$2"; shift;;
-o) output="$2"; shift;;
-l) longerthan="$2"; shift;;
-s) shorterthan="$2"; shift;;
-h) Usage;;
-*) BadArg;;
esac
shift
done
#test to make sure the user gave an input-path (the minimum required to successfully run the script)
if [ "${input}" = "" ]
then echo "This script requires that you atleast give it an input-path.
Try \"$0 -h\" for more information"
exit 1
fi
export longerthan
export shorterthan
#scans the input-path for VIDEO_TS folders
for i in $(find $input -type d -name VIDEO_TS) ; do
#scans all the titles in the DVD $i, scrapes out the length in seconds and compares them to $longerthan and $shorterthan
for title in $($CLIpath -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 >= (60 * ENVIRON["longerthan"]) && $8 <= (60 * (ENVIRON["shorterthan"])) { print $3 "-" $5 } ') ; do
#this names the filenameafter it's parent folder
filename=$(echo $i | sed 's/[/]/ /g' | awk '{print $(NF-1)}')
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
#this executes the HandBrakeCLI
#you can change the preset or any other variables here
$CLIpath -i $i -o ${output}/${filename}-title${titlenum}.mp4 -Z "iPhone / iPod Touch" -t ${titlenum}
#output example: 24_SEASON6_D1-title1.mp4
done
done#!/bin/sh
###############################################################################
# Shellscript : hb.sh - Batch-encoder script for HandBrakeCLI
# Author : Snorre Selmer <snorre.selmer@gmail.you-know-the-rest>
# Date : 2008-09-10
# Requires : HandBrakeCLI, awk, sed
###############################################################################
# Description:
# This script does recursive scanning of a given folder and encodes all titles
# that are within an optionally given minimum and maximum length, and outputs
# the resulting files into an optionally given folder.
###############################################################################
# Cudos:
# - First of all, big thanks to the HandBrake team for making the most awesome
# MP4-encoder I've ever used.
# - Second thanks goes to the HandBrake CLI-forum (http://forum.handbrake.fr)
# and especially ronnor for making the script I used as a base for this one.
# I learned a lot from "disassembling" your script.
# - The SED and AWK tutorials at http://www.grymoire.com/Unix/index.html were
# a great help in understanding ronnor's script.
# - Finally, http://www.shelldorado.com/goodcoding/cmdargs.html is where I
# got the code for the commandline arguments. Excellent shell-script site!
###############################################################################
# Disclaimer:
# I give no guarantees that this script will work on your system. It works on
# mine (GNU/Linux Ubuntu 8.04 x86_64 with HandBrakeCLI svn1667) and that's the
# only place I've been able to test it so far. If you find a bug, let me know
# on the HandBrake forum at http://forum.handbrake.fr/viewtopic.php?f=10&t=5070
# and we can look at it.
# DO NOT E-MAIL ME BUGS! Bugs are best squashed when many can look at them,
# so use the forum!
###############################################################################
# Todo:
# - Find and eliminate the cause of the "Segmentation fault" errors
# - Sort out a command-line argument to enable deinterlacing
# - Sort out a command-line argument to select presets
# - Space for sale, user-input required
###############################################################################
#basic program-info stuff
name=`basename "$0"`
version='0.3'
#path to the HandBrakeCLI binary
CLIpath=/home/snorre/src/hb/trunk/HandBrakeCLI
#default minimum title-time (in minutes) to encode
longerthan=0
#default maximum title-time (in minutes) to encode (default = 24 hours)
shorterthan=1440
#the folder you want to scan for DVDs to encode
input=
#the folder you want to store the encoded files in (default is the folder you're in when you run the script)
output=.
#title-duration check-flag
check=0
#function that prints usage-instructions if the user input something wrong
Usage () {
echo >&2 "$name - HandBrakeCLI batch-script, v$version
usage: $name -i PathToDVDs [-o PathToSaveFolder] [-l MinimumTitleTimeToEncode] [-s MaximumTitleTimeToEncode]
-i: path to scan for VIDEO_TS folders.
-o: path to where you want to store the finished encodes.
Default: the current folder (./)
-l: only encode titles that are longer than this (in minutes).
Ex: \"-i 30\" will only encode titles longer than 30 minutes.
Can be used in conjunction with -s.
-s: only encode titles that are shorter than this (in minutes).
Ex: \"-s 30\" will only encode titles shorter than 30 minutes.
Can be used in conjunction with -l.
-c: scans the input-path, checks and prints out the length of the titles (in minutes).
Can be used with -l and -s, but -o has no meaning.
Example:
$name -l 30 -s 60 -i Scrubs -o /home/username/mp4
This will scan the subfolder Scrubs and encode all titles that are longer than
30 minutes and shorter than 60 minutes, and store them in /home/username/mp4.
Input- and output-paths can be either relative or absolute (ie. Scrubs, ../Scrubs or /path/to/Scrubs).
"
exit 1
}
BadArg() {
echo >&2 "Invalid argument.
Try \"$0 -h\" for more information"
exit 1
}
#command-line argument parser
while [ $# -gt 0 ]
do
case "$1" in
-i) input="$2"; shift;;
-o) output="$2"; shift;;
-l) longerthan="$2"; shift;;
-s) shorterthan="$2"; shift;;
-h) Usage;;
-c) check=1;;
-*) BadArg;;
esac
shift
done
#test to make sure the user gave an input-path (the minimum required to successfully run the script)
if [ "${input}" = "" ]
then echo "This script requires that you atleast give it an input-path.
Try \"$0 -h\" for more information"
exit 1
fi
export longerthan
export shorterthan
#scans the input-path for VIDEO_TS folders
for i in $(find $input -type d -name VIDEO_TS) ; do
#this names the filenameafter it's parent folder
filename=$(echo $i | sed 's/[/]/ /g' | awk '{print $(NF-1)}')
if [ $check = 0 ]
then
#scans all the titles in the DVD $i, scrapes out the length in seconds and compares them to $longerthan and $shorterthan
for title in $($CLIpath -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 >= (60 * ENVIRON["longerthan"]) && $8 <= (60 * (ENVIRON["shorterthan"])) { print $3 "-" $5 } ') ; do
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
#this executes the HandBrakeCLI
#you can change the preset or any other variables here
$CLIpath -i $i -o ${output}/${filename}-title${titlenum}.mp4 -t ${titlenum} -Z "iPhone / iPod Touch"
done
fi
if [ $check = 1 ]
then
#scans all the titles in the DVD $i, scrapes out the length in seconds and prints title duration (in minutes)
echo "\n$filename"
$CLIpath -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 >= (60 * ENVIRON["longerthan"]) && $8 <= (60 * (ENVIRON["shorterthan"])) { print " " $2 " " $5 " is " $8/60 " minutes long " }'
fi
donesnorre@snorre-desktop:~$ ./hb.sh -c -i /media/Series1/Firefly/
Segmentation fault
Firefly_Disc_1 Title 1 is 83.1833 minutes long
Firefly_Disc_1 Title 2 is 41.0833 minutes long
Firefly_Disc_1 Title 3 is 42.15 minutes long
Firefly_Disc_1 Title 4 is 0.433333 minutes long
Segmentation fault
Firefly_Disc_2 Title 1 is 42.2167 minutes long
Firefly_Disc_2 Title 2 is 41.0333 minutes long
Firefly_Disc_2 Title 3 is 42.1833 minutes long
Firefly_Disc_2 Title 4 is 42.2 minutes long
Firefly_Disc_2 Title 5 is 0.433333 minutes long
Segmentation fault
Firefly_Disc_3 Title 1 is 42.2 minutes long
Firefly_Disc_3 Title 2 is 41.1 minutes long
Firefly_Disc_3 Title 3 is 41.1667 minutes long
Firefly_Disc_3 Title 4 is 41.95 minutes long
Firefly_Disc_3 Title 5 is 0.433333 minutes long
Segmentation fault
Firefly_Disc_4 Title 1 is 42.3 minutes long
Firefly_Disc_4 Title 2 is 40.75 minutes long
Firefly_Disc_4 Title 3 is 42.3 minutes long
Firefly_Disc_4 Title 4 is 0.433333 minutes long
Firefly_Disc_4 Title 5 is 28.6667 minutes long
Firefly_Disc_4 Title 6 is 9.76667 minutes long
Firefly_Disc_4 Title 7 is 1.4 minutes long
Firefly_Disc_4 Title 8 is 1.6 minutes long
Firefly_Disc_4 Title 9 is 4.61667 minutes long
Firefly_Disc_4 Title 10 is 3.7 minutes long
Firefly_Disc_4 Title 11 is 2.2 minutes long
Firefly_Disc_4 Title 12 is 1.08333 minutes long
Firefly_Disc_4 Title 13 is 2.7 minutes long
Firefly_Disc_4 Title 14 is 1.28333 minutes long
Firefly_Disc_4 Title 15 is 2.63333 minutes long
snorre@snorre-desktop:~$ ./hb.sh -c -i /media/Series1/Firefly/ -l 30 -s 90
Segmentation fault
Firefly_Disc_1 Title 1 is 83.1833 minutes long
Firefly_Disc_1 Title 2 is 41.0833 minutes long
Firefly_Disc_1 Title 3 is 42.15 minutes long
Segmentation fault
Firefly_Disc_2 Title 1 is 42.2167 minutes long
Firefly_Disc_2 Title 2 is 41.0333 minutes long
Firefly_Disc_2 Title 3 is 42.1833 minutes long
Firefly_Disc_2 Title 4 is 42.2 minutes long
Segmentation fault
Firefly_Disc_3 Title 1 is 42.2 minutes long
Firefly_Disc_3 Title 2 is 41.1 minutes long
Firefly_Disc_3 Title 3 is 41.1667 minutes long
Firefly_Disc_3 Title 4 is 41.95 minutes long
Segmentation fault
Firefly_Disc_4 Title 1 is 42.3 minutes long
Firefly_Disc_4 Title 2 is 40.75 minutes long
Firefly_Disc_4 Title 3 is 42.3 minutes long
#!/bin/sh
###############################################################################
# Shellscript : hb.sh - Batch-encoder script for HandBrakeCLI
# Author : Snorre Selmer <snorre.selmer@gmail.you-know-the-rest>
# Date : 2008-10-23
# Requires : HandBrakeCLI, awk, sed
###############################################################################
# Description:
# This script does recursive scanning of a given folder and encodes all titles
# that are within an optionally given minimum and maximum length, and outputs
# the resulting files into an optionally given folder.
###############################################################################
# Cudos:
# - First of all, big thanks to the HandBrake team for making the most awesome
# MP4-encoder I've ever used.
# - Second thanks goes to the HandBrake CLI-forum (http://forum.handbrake.fr)
# and especially ronnor for making the script I used as a base for this one.
# I learned a lot from "disassembling" your script.
# - The SED and AWK tutorials at http://www.grymoire.com/Unix/index.html were
# a great help in understanding ronnor's script.
# - Finally, http://www.shelldorado.com/goodcoding/cmdargs.html is where I
# got the code for the commandline arguments. Excellent shell-script site!
###############################################################################
# Disclaimer:
# I give no guarantees that this script will work on your system. It works on
# mine (GNU/Linux Ubuntu 8.04 x86_64 with HandBrakeCLI svn1667) and that's the
# only place I've been able to test it so far. If you find a bug, let me know
# on the HandBrake forum at http://forum.handbrake.fr/viewtopic.php?f=10&t=5070
# and we can look at it.
# DO NOT E-MAIL ME BUGS! Bugs are best squashed when many can look at them,
# so use the forum!
###############################################################################
# Todo:
# - Find and eliminate the cause of the "Segmentation fault" errors
# - Sort out a command-line argument to enable deinterlacing
# - Sort out a command-line argument to select presets
# - Space for sale, user-input required
###############################################################################
#basic program-info stuff
name=`basename "$0"`
version='0.4'
#path to the HandBrakeCLI binary
CLIpath=/home/snorre/.src/hb/trunk/HandBrakeCLI
#default minimum title-time (in minutes) to encode
longerthan=0
#default maximum title-time (in minutes) to encode (default = 24 hours)
shorterthan=1440
#the folder you want to scan for DVDs to encode
input=
#the folder you want to store the encoded files in (default is the folder you're in when you run the script)
output=.
#title-duration check-flag
check="n"
#function that prints usage-instructions if the user input something wrong
Usage () {
echo >&2 "$name - HandBrakeCLI batch-script, v$version
usage: $name -i PathToDVDs [-o PathToSaveFolder] [-l MinimumTitleTimeToEncode] [-s MaximumTitleTimeToEncode]
-i: path to scan for VIDEO_TS folders.
-o: path to where you want to store the finished encodes.
Default: the current folder (./)
-l: only encode titles that are longer than this (in minutes).
Ex: \"-i 30\" will only encode titles longer than 30 minutes.
Can be used in conjunction with -s.
-s: only encode titles that are shorter than this (in minutes).
Ex: \"-s 30\" will only encode titles shorter than 30 minutes.
Can be used in conjunction with -l.
-c: scans the input-path, checks and prints out the length of the titles (in minutes).
Can be used with -l and -s, but -o has no meaning.
Example:
$name -l 30 -s 60 -i Scrubs -o /home/username/mp4
This will scan the subfolder Scrubs and encode all titles that are longer than
30 minutes and shorter than 60 minutes, and store them in /home/username/mp4.
Input- and output-paths can be either relative or absolute (ie. Scrubs, ../Scrubs or /path/to/Scrubs).
"
exit 0
}
BadArg() {
echo >&2 "Invalid argument.
Try \"$0 -h\" for more information"
exit 0
}
#command-line argument parser
while [ $# -gt 0 ]
do
case "$1" in
-i) input="$2"; shift;;
-o) output="$2"; shift;;
-l) longerthan="$2"; shift;;
-s) shorterthan="$2"; shift;;
-h) Usage;;
-c) check="y";;
-*) BadArg;;
esac
shift
done
#test to make sure the user gave an input-path (the minimum required to successfully run the script)
if [ "${input}" = "" ]
then echo "This script requires that you atleast give it an input-path.
Try \"$0 -h\" for more information"
exit 0
fi
export longerthan
export shorterthan
#scans the input-path for VIDEO_TS folders
for i in $(find $input -type d -name VIDEO_TS) ; do
#this names the filenameafter it's parent folder
filename=$(echo $i | sed 's/[/]/ /g' | awk '{print $(NF-1)}')
if [ $check = "y" ]
then
#scans all the titles in the DVD $i, scrapes out the length in seconds and prints title duration (in minutes)
echo "$filename"
$CLIpath -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 >= (60 * ENVIRON["longerthan"]) && $8 <= (60 * ENVIRON["shorterthan"]) {print " " $2 " " $5 " is " $8/60 " minutes long"}'
fi
if [ $check = "n" ]
then
#scans all the titles in the DVD $i, scrapes out the length in seconds and compares them to $longerthan and $shorterthan
for title in $($CLIpath -t 0 -i $i -L 2>&1 | grep "has length" | sed 's/sec//' | sed 's/[()]//g' | awk '$8 >= (60 * ENVIRON["longerthan"]) && $8 <= (60 * (ENVIRON["shorterthan"])) { print $3 "-" $5 } ') ; do
#this names the title for the output file
titlenum=$(echo $title | cut -f 2 -d '-')
#this executes the HandBrakeCLI
#you can change the preset or any other variables here
$CLIpath -i $i -o ${output}/${filename}-title${titlenum}.mp4 -t ${titlenum} -Z "iPhone / iPod Touch" --deinterlace="2"
done
fi
done#!/bin/bash
# replaces characters recursively in filenames and folder names
#####################################
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -depth -name '*' | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
newfilename=$(echo "$oldfilename" | tr ' ' '_' | sed 's/_-_/-/g')
if [ "$oldfilename" != "$newfilename" ]; then
mv -i "$directory/$oldfilename" "$directory/$newfilename"
echo ""$directory/$oldfilename" ---> "$directory/$newfilename""
fi
done
exit 0#!/bin/bash
# Convert underscores to spaces
# makes a folder based off of the file name
# moves the new file under this new folder
#####################################
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -name '*' | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
newfilename=$(echo "$oldfilename" | tr '_' ' ' | sed 's/-title[0-9]//g')
newdirectoryname=$(echo "$newfilename" | sed 's/.m4v//g')
if [ "$oldfilename" != "$newfilename" ]; then
mv -i "$directory/$oldfilename" "$directory/$newfilename"
echo ""$directory/$oldfilename" ---> "$directory/$newfilename""
fi
mkdir "$directory/$newdirectoryname"
mv -i "$directory/$newfilename" "$directory/$newdirectoryname"
done
exit 0#!/bin/bash
# ------------------------------------------------------------
# Setup Environment
# ------------------------------------------------------------
PDIR=${0%`basename $0`}
LCK_FILE=`basename $0`.lck
# ------------------------------------------------------------
# Am I Running
# ------------------------------------------------------------
if [ -f "${LCK_FILE}" ]; then
# The file exists so read the PID
# to see if it is still running
MYPID=`head -n 1 "${LCK_FILE}"`
TEST_RUNNING=`ps -p ${MYPID} | grep ${MYPID}`
if [ -z "${TEST_RUNNING}" ]; then
# The process is not running
# Echo current PID into lock file
echo "Not running"
echo $$ > "${LCK_FILE}"
else
echo "`basename $0` is already running [${MYPID}]"
exit 0
fi
else
echo "Not running"
echo $$ > "${LCK_FILE}"
fi
# ------------------------------------------------------------
# Do Something
# ------------------------------------------------------------
while true
do
echo
ismediaincheck=$(hal-device | grep /dev/scd0)
isi=${#ismediaincheck}
echo $isi" : Only two lines (84) means no dvd in drive."
if [ $isi -gt 85 ]
then
echo "GO! "
date
TITLE=$(lsdvd /dev/scd0 | grep -i Disc | sed 's/Disc Title: //g')
COPYTO=$"/mnt/raid/Shared/Open/fresh/"$TITLE".m4v"
OUTPUT=$"/mnt/raid/handbraketmp/"$TITLE".m4v"
if [ -f $COPYTO ]
then
echo
echo "RIP exists! "
date
umount /dev/scd0
eject /dev/scd0
else
echo "Ripping title to " $COPYTO
HandBrakeCLI -L -i /dev/scd0 -o $OUTPUT -e x264 -q 0.589999973773956 -a 1,1 -E faac,ac3 -B 160,auto -R 48,Auto -6 dpl2,auto -f mp4 -4 -X 960 -P -m -x level=30:cabac=0:ref=3:mixed-refs=1:bframes=6:weightb=1:direct=auto:no-fast-pskip=1:me=umh:subq=7:analyse=all
echo "Done ripping, moving file, umounting disc and ejecting."
mv $OUTPUT $COPYTO
umount /dev/scd0
eject /dev/scd0
fi
umount /dev/scd0
eject /dev/scd0
else
echo "NO-GO!"
date
echo
fi
sleep 15
done
# ------------------------------------------------------------
# Cleanup
# ------------------------------------------------------------
rm -f "${LCK_FILE}"
# ------------------------------------------------------------
# Done
# ------------------------------------------------------------
exit 0