Part 3: (Tutorial) Automating DVD Backup with FairMount, HandBrake and iTunes

Discussion in 'Apple TV and Home Theater' started by mac.jedi, Nov 14, 2008.

  1. macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #1

    Part 3: Automating DVD Backup with FairMount, HandBrake and iTunes

    Parts to this tutorial:
    Part 1: Introduction
    Part 2: Using AppleScript to Automate Ripping
    Part 3: Using a Batch Script to Automate HandBrake
    Part 4: TV Show Renamer Droplet
    Part 5: Add to iTunes and Auto-tag Script

    Using a Batch Script to Automate HandBrake

    What you need to get started
    To complete this tutorial you will need to download and install the following applications:

    HandBrakeCLI
    HandBrake is an open-source, GPL-licensed, multiplatform, multithreaded DVD to MPEG-4 converter, available for MacOS X, Linux and Windows. The Command Line Interface version of HandBrake is a lot faster and more flexible than the MacGui. Using scripting you can automate HandBrakeCLI to encode your files as a background process using the same parameters you'd set in the GUI.

    Script Editor
    Script Editor is located at /Applications/AppleScript/Script Editor.


    Install HandBrakeCLI

    1. Download and open the HandBrakeCLI disk image.

      [​IMG]

    2. Next, drag the HandBrakeCLI application from the disk image to your applications folder.


    Creating the HandBrakeCLI Batch Script:

    This shell script will batch encode an entire directory full of TS_Video source media to any desired output HandBrakeCLI can handle, including presets. It will also encode every track that is longer than the length you specify in the batch encode script, which is a great time saver for batch encoding TV Shows.

    1. Open TextEdit and create a new PLAIN TEXT document.
    2. Next, select, copy and paste the shell script below into your text file.

      Code:
      #!/bin/sh
      
      #  UPDATED: 01-22-2009
      
      #  HandBrakeCLI-batch.sh is a script to batch execute the HandBrakeCLI.
      #  This script is based upon the MediaForkCLI-batch.sh.
      
      # Usage: HandBrakeCLI-batch.sh [options]
      #
      #  arg1:   inputSearchDir=<string>   Set input directory to process all DVDs in it (example: ~/Movies/Batch Rip) "
      #  arg2:   outputDir=<string>        Set output directory for all output files (example: ~/Movies/Batch Encode) "
      #  arg3:   fileType=<string>         Set the file type: .mp4, .avi, .omg, .mkv, .m4v (example: .m4v) "
      #  arg4:   minTrackTime=<number>     Set the minimum time (mins) of the track/s to encode (example: 30) "
      #  arg5:   toolArgs=<string>         Set the HandBrakeCLI encode settings (example: -2 -w 640) "
      
      # Revision history:
      # 0.20070329.0 - initial release
      # 0.20081125.0 - revised for HandBrakeCLI
      # 0.20090122.0 - fixed problem with spaces in the directory tree
      
      
      #############################################################################
      # globals
      
      # const global variables
      scriptName=`basename "$0"`
      scriptVers="2.0"
      scriptPID=$$
      saveDVDinfo=1       # the dvd track info is also saved as txt file when on
      skipDuplicates=1    # if this option is off (-0),
                          # the new output files will overwrite existing files
      E_BADARGS=65
      
      # set the global variables to default
      toolName="HandBrakeCLI"
      toolPath="/Applications/$toolName"
      toolTrackArgs="-t 0" # scans dvd title list for all tracks
      inputSearchDir=$1    # set input search directory: "~/Movies/Batch Rip"
      outputDir="$2"       # set output directory: "~/Movies/Batch Encode"
      fileType="$3"        # set output container: .m4v, .mp4, .avi, .omg, .mkv
      minTrackTime="$4"    # this is in minutes: "30"
      toolArgs="$5"        # set handbrakecli encode settings: "-2 -w 640"
      
      #############################################################################
      # functions
      
      verifyFindCLTool()
      {
      	# attempt to find the HandBrakeCLI if the script toolPath is not good
      	if [ ! -x "$toolPath" ];
      	then
      		toolPathTMP=`PATH=.:/Applications:/:/usr/bin:/usr/local/bin:$HOME:$PATH which $toolName | sed '/^[^\/]/d' | sed 's/\S//g'`
      		
      		if [ ! -z $toolPathTMP ]; then 
      			toolPath=$toolPathTMP
      		fi
      	fi	
      }
      
      displayUsageExit()
      {
      	echo "Usage: $scriptName [options]"
      	echo ""
      	echo "    -h, --help   Print help"
      	echo "    arg1:   inputSearchDir=<string>   Set input directory to process all DVDs in it (example: ~/Movies/Batch Rip) "
      	echo "    arg2:   outputDir=<string>        Set output directory for all output files (example: ~/Movies/Batch Encode) "
      	echo "    arg3:   fileType=<string>         Set the file type: .mp4, .avi, .omg, .mkv, .m4v (example: .m4v) "
      	echo "    arg4:   minTrackTime=<number>     Set the minimum time (mins) of the track/s to encode (example: 30) "
      	echo "    arg5:   toolArgs=<string>         Set the HandBrakeCLI encode settings (example: -2 -w 640) "
      	
      	
      	if [ -x "$toolPath" ];
      	then
      		echo "   $toolName possible options"
      		mForkHelp=`$toolPath --help 2>&1`
      		mForkHelpPt=`printf "$mForkHelp" | egrep -v '( --input| --output| --help|Syntax: |^$)'`
      		printf "$mForkHelpPt\n"
      	else
      		echo "    The options available to HandBrakeCLI except -o  and -i"
      		if [ -e "$toolPath" ];
      		then
      			echo "    ERROR: $toolName command tool is not setup to execute"
      			echo "    ERROR: attempting to use tool at $toolPath"
      		else
      			echo "    ERROR: $toolName command tool could not be found"
      			echo "    ERROR: $toolName can be install in ./ /usr/local/bin/ /usr/bin/ ~/ or /Applications/"
      		fi
      	fi
      	
      	echo ""
      	
      	exit $E_BADARGS
      }
      
      getTrackListLongerThan()
      {
      	# Two input arguments are are need. 
      	#   arg1 is the time in minutes selector
      	#   arg2 is the raw text stream from the track 0 call to HandBrake
      	#   returns: a list of track numbers of tracks longer then the selector
      	
      	if [ $# -lt 2 ]; then
      		return ""
      	fi
      	
      	minTime="$1"
      	shift
      	allTrackText="$*"
      	aReturn=""
      
      	trackList=`eval "echo \"$allTrackText\" | egrep '(^\+ title |\+ duration\:)' | sed -e 's/^[^+]*+ //'g -e 's/title \([0-9]*\):/\1-/'g -e 's/duration: //'g"`
      	
      	trackNumber=""
      	for aline in $trackList
      	do
      		trackLineFlag=`echo $aline | sed 's/[0-9]*-$/-/'`
      		if [ $trackLineFlag = "-" ];
      		then
      			trackNumber=`echo $aline | sed 's/\([0-9]*\)-/\1/'`
      		else
      			set -- `echo $aline | sed -e 's/(^[:0-9])//g' -e 's/:/ /g'`
      			if [ $3 -gt 29 ];
      			then let trackTime=($1*60)+$2+1
      			else let trackTime=($1*60)+$2
      			fi
      
      			if [ $trackTime -gt $minTime ];
      			then aReturn="$aReturn $trackNumber"
      			fi
      		fi
      	done
      	
      	echo "$aReturn"
      }
      
      makeFullPath()
      {
         aReturn=""
         currentPath=`pwd`
         
         if [ $# -gt 0 ]; then
            inPath="$*"
            
            # put full path in front of path if needed
            aReturn=`echo "$inPath" | sed -e "s!~!$currentPath/!" -e "s!^./!$currentPath/!" -e "s!^\([^/]\)!$currentPath/\1!" -e "s!^../!$currentPath/../!"`
            
            # remove ../ from path - only goes 4 deep
            aReturn=`echo "$aReturn" | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g'`
            
            # cleanup by removing //
            aReturn=`echo "$aReturn" | sed -e 's!//!/!g'`
         fi
         
         echo "$aReturn"
      }
      
      isPIDRunning()
      {
      	aResult=0
      	
      	if [ $# -gt 0 ]; then
      		txtResult="`ps ax | egrep \"^[ \t]*$1\" | sed -e 's/.*/1/'`"
      		if [ -z "$txtResult" ];
      		then aResult=0
      		else aResult=1
      		fi
      	fi
      	
      	echo $aResult
      }
      
      #############################################################################
      # MAIN SCRIPT
      
      # initialization functions
      verifyFindCLTool
      
      # fix input and output paths to be full paths
      inputSearchDir=`makeFullPath "$inputSearchDir"`
      outputDir=`makeFullPath "$outputDir"`
      
      # see if the output directory needs to be created
      if [ ! -e $outputDir ]; then
      	mkdir -p "$outputDir"
      fi
      
      # sanity checks
      if [[ ! -x $toolPath || ! -d $inputSearchDir || ! -d $outputDir || -z "$toolArgs" ]]; then
      	displayUsageExit
      fi
      
      # display the basic setup information
      echo "$scriptName $scriptVers"
      echo "  Start: `date`"
      echo "  Input directory: $inputSearchDir"
      echo "  Output directory: $outputDir"
      echo "  File type: $fileType"
      echo "  Minimum get track time: $minTrackTime mins"
      echo "  Tool path: $toolPath"
      echo "  Tool args: $toolArgs"
      echo "  - - - - - - - - - - - - - - - -"
      
      # find all the DVD videos in the input search directory tree
      # spaces in file path temporarily become /008 and paths are separ with spaces
      dvdTSVidList=`find "$inputSearchDir" -name VIDEO_TS -print0 | tr ' ' '\007' | tr '\000' ' '`
      
      # process each DVD video found
      for dvdTSDir in $dvdTSVidList
      do
      	# correct the tmp char back to spaces in the DVD file paths
      	dvdTSDir=`echo $dvdTSDir | tr '\007' ' '`
      	
      	# get the DVD's name and path to root of the DVD
      	dvdVolPath=`dirname "$dvdTSDir"`
      	dvdName=`basename "$dvdVolPath"`
      	dvdNameALNUM=`basename "$dvdVolPath" | sed 's/[^[:alnum:]^-^_]//g'`
      	
      	# display information
      	echo "  * Processing DVD '$dvdName'"
      	
      	# create tmp link to the dvdVolPath to workaround a problem that the
      	# HandBrakeCLI tool has a problem with the input file paths with space
      	# when in a script
      	tmpNoSpacePath="/tmp/dvdVol-$dvdNameALNUM-$scriptPID"
      	ln -s "$dvdVolPath" $tmpNoSpacePath
      	
      	# get the track list information from the DVD
      	cmd="$toolPath -i $tmpNoSpacePath $toolTrackArgs /dev/null 2>&1"
      	dvdTrackInfo=`eval $cmd`
      	# save the DVD info
      	outputFilePath="$outputDir/${dvdName}_Info.txt"
      	if [ $saveDVDinfo -eq 1 ]; then
      		if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]]; then
      			echo "$dvdTrackInfo" | egrep '[ \t]*\+' > "$outputFilePath"
      		fi
      	fi
      	# get the track number of tracks which are longer then the time desired
      	trackFetchList=`getTrackListLongerThan $minTrackTime "$dvdTrackInfo"`
      	if [ ! -z "$trackFetchList" ];
      	then
      		echo "   Will encode the following tracks: `echo $trackFetchList | sed 's/ /, /g'` "
      	else
      		echo "   No tracks on this DVD are longer then the minimum track time setting"
      	fi
      				
      	trackCount=`echo $trackFetchList | wc -w`
      	for aTrack in $trackFetchList
      	do
      		if [ $trackCount -gt 1 ]
      			then outputFilePath="$outputDir/${dvdName}${aTrack}$fileType"
      			else outputFilePath="$outputDir/${dvdName}$fileType"
      		fi
      		cmd="$toolPath -i $tmpNoSpacePath $toolArgs -t $aTrack -o \"$outputFilePath\" > /tmp/${dvdNameALNUM}Results.txt 2>&1"
      		
      		if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]];
      		then
      			# simple command execution
      			#ripResult=`eval $cmd`
      			
      			# background command execution with some status
      			eval $cmd &
      			cmdPID=$!
      			while [ `isPIDRunning $cmdPID` -eq 1 ]; do
      				cmdStatusTxt="`tail -n 1 /tmp/${dvdNameALNUM}Results.txt | grep 'Encoding: '`"
      				if [ ! -z "$cmdStatusTxt" ]; then
      					echo -n "$cmdStatusTxt"
      				fi
      				sleep 1s
      			done
      			echo ""
      			wait $cmdPID
      			
      		else
      			echo "   Output file SKIPPED because it ALREADY EXISTS"
      		fi
      		
      		if [ -e /tmp/${dvdNameALNUM}Results.txt ]; then
      			rm /tmp/${dvdNameALNUM}Results.txt
      		fi
      	done
      
      	rm $tmpNoSpacePath
      done
      
      echo "  - - - - - - - - - - - - - - - -"
      echo "  End: `date`"
      
      exit 0
      
      
      # End Script
      
    3. Save the file in your ~/Movies/BatchScripts folder as: HandBrakeCLI-batch.sh. Save using the .sh extension.
    4. Next we need to set the file permissions, open Terminal.app, type: chmod 777 ~/Movies/BatchScripts/HandBrakeCLI-batch.sh
    5. Hit enter. Alternatively, you can just drag the file to the terminal window after the chmod 777 with a space before the path.


    Creating Your Batch Encode Script:

    This AppleScript can be triggered by an iCal Alarm to run the HandBrakeCLI-batch.sh file with defined encoding parameters for HandBrakeCLI.

    1. Select, copy and paste the script below into a new Script Editor document.

      Code:
      ---------- BatchEncode.scpt ----------
      ---------- Updated: 01-22-2009 ----------
      
      
      global batchScript1, batchScript2
      
      ---------- Properties ----------
      
      -- The input directory to process all DVDs (TS Folders) in it. Default is: ~/Movies/BatchRip. This folder will be automatically created on first run, but the script will fail since there isn't anything in the folder.
      property inputPath1 : "~/Movies/BatchRip"
      
      -- The output directory for all output files. Default is: ~/Movies/BatchEncode. This folder will be automatically created on first run.
      property outputPath : "~/Movies/BatchEncode"
      
      -- The path to your HandBrakeCLI-batch.sh script. Default is: ~/Movies/BatchScripts/HandBrakeCLI-batch.sh
      property scriptPath : "~/Movies/BatchScripts/HandBrakeCLI-batch.sh" -- Insert the path to HandBrakeCLI-batch.sh.
      
      -- Set your HandBrakeCLI encode settings.  Default is the Universal preset, HandBrake's universally compatible, full resolution settings for all current Apple devices: iPod, iPhone, AppleTV, and Macs). For more info in setting parameters, visit http://handbrake.fr and read the CLI Guide Wiki. 
      property encodeSettings : "--preset=\"Universal\"" -- Note: you must escape quotes for presets. 
      
      -- Set the minimum time (minutes) of the track/s to encode (default: 20)
      property minGetTime : "20"
      
      ---------- Optional Properties ----------
      
      -- Dual-Encode: If you have a fast multi-core processor and hard disk, you can setup two batch folders to encode two RIPs at once. 
      property batchFolders : 1 -- If adding a second input directory, change number of batch folders to 2. 
      property inputPath2 : "~/Movies/BatchRip2" -- Set second input directory to process all DVDs in it. Default is: ~/Movies/BatchRip2. This folder will be automatically created if the batchFolders property is set to 2.
      
      -- Output Container: This script's default output container is .m4v(mp4). HandBrake can also save files in: .mkv, .avi, and .ogm.
      property fileType : ".m4v"
      
      -- Setup Growl Support: Set useGrowl to yes and set the path to the GrowlNotifyLib.scpt.
      property useGrowl : no -- If you have growl, set to yes.
      property growlTitle : "Batch Encode"
      property growlMessage : "Your HandBrake Encodes Are Done!"
      property growlLibraryPath : POSIX file "Users/userloginname/Movies/BatchScripts/GrowlNotifyLib.scpt" -- Set the path to the GrowlNotifyLib.scpt.
      
      ---------- Encode Script ----------
      
      try
      	if useGrowl is yes then setGrowl(growlTitle) of (load script growlLibraryPath)
      end try
      try
      	createBatchScript()
      	mkDir(inputPath1) & mkDir(outputPath)
      	if batchFolders is 2 then mkDir(inputPath2)
      	with timeout of 36000 seconds
      		doScript()
      		growlMe(growlTitle, growlMessage) of (load script growlLibraryPath)
      	end timeout
      end try
      
      ---------- Sub-routines ----------
      to doScript()
      	tell application "Terminal"
      		activate
      		tell application "System Events" to keystroke "n" using {command down}
      		if batchFolders is 2 then repeat 1 times
      			tell application "System Events" to keystroke "t" using {command down}
      		end repeat
      		do script batchScript1 in tab 1 of window 1
      		if batchFolders is 2 then do script batchScript2 in tab 2 of window 1
      		repeat until tab 1 of window 1 is not busy
      			delay 4
      		end repeat
      		if batchFolders is 2 then repeat until tab 2 of window 1 is not busy
      			delay 4
      		end repeat
      	end tell
      end doScript
      
      to setInput(batchFolder)
      	set inputDir to quoted form of batchFolder
      end setInput
      
      to createBatchScript()
      	set spc to " "
      	set inputDir1 to setInput(inputPath1)
      	set inputDir2 to setInput(inputPath2)
      	set logFile to " | tee " & escapePath(outputPath)
      	set outputDir to quoted form of outputPath
      	set batchScript1 to escapePath(scriptPath) & spc & inputDir1 & spc & outputDir & spc & quoted form of fileType & spc & quoted form of minGetTime & spc & quoted form of encodeSettings & logFile & "/BatchEncode.log"
      	set batchScript2 to escapePath(scriptPath) & spc & inputDir2 & spc & outputDir & spc & quoted form of fileType & spc & quoted form of minGetTime & spc & quoted form of encodeSettings & logFile & "/BatchEncode2.log"
      end createBatchScript
      
      on escapePath(outputPath)
      	set the search_string to " "
      	set the replacement_string to "\\ "
      	set AppleScript's text item delimiters to the " "
      	set the text_item_list to every text item of the outputPath
      	set AppleScript's text item delimiters to the replacement_string
      	set the new_item_name to the text_item_list as string
      	set AppleScript's text item delimiters to ""
      	set the outputPath to new_item_name
      end escapePath
      
      on mkDir(somepath)
      	do shell script "mkdir -p " & escapePath(somepath)
      end mkDir
      
      ---------- End Script ---------
      
    2. Choose Script > Compile (CMD-K)
    3. Follow the steps in the script to set the properties, if needed.
    4. Save the script in your ~/Movies/BatchScripts folder as "batchEncode.scpt"



    Setting An iCal Batch Encode Alarm

    1. Create a Calendar and name it (ex. Scripts)
    2. Select your new calender, create a New Event and name it (ex. Encode Alarm)
    3. Set the Start Time to the time you'd like your encodes to begin (ex. 12:00AM)
    4. Set the End Time to the Start Time + 1 minute (ex. 12:01AM)
    5. Set Repeat to "Every Day" (if you want it to run every night)
    6. Set End to "Never"
    7. Set Alarm to "Run Script"
    8. Below "Run Script", change "None" to "Other" and navigate to select your batchEncode.scpt
    9. Set Notification to "0 minutes before"

      [​IMG]

    10. Click Done.

      Note: If you sync your iCal calendars with other Macs, you will need to select the calendar containing your Batch Encode Alarm on the other Macs and choose File > Get Info > and check the box next to "Ignore Alarms".


    Go To Part 4: TV Show Renamer Droplet
     
  2. macrumors newbie

    Joined:
    Oct 30, 2006
    #2
    Thanks for this wonderful tutorial. Any idea if you can get it to automate with .mkv files too?
     
  3. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #3
    HandBrakeCLI will encode to mkv. You will need to modify the [mono]encodeSettings[/mono] in the batchEncode.scpt provided in the tutorial. More info on the code you will need is available at: http://trac.handbrake.fr/wiki/CLIGuide

    It may be as easy as adding: -f mkv, but I haven't tried it. I usually only output to m4v.

    BatchEncode.scpt Snippet
    Code:
    -- Insert your HandBrake encode settings. Note: you must escape quotes for presets. For more info in setting parameters, visit http://handbrake.fr and read the CLI Guide.
    set encodeSettings to "--preset=\"AppleTV\" -2 -T"
    
     
  4. macrumors newbie

    Joined:
    Oct 30, 2006
    #4
    What I meant to ask was is there a way to change the source from VIDEO_TS folders to any file with a .mkv extension. Instead of batch encoding DVD video batch convert .mkv files to .m4v format. Thanks again. :)
     
  5. macrumors 6502

    Joined:
    Jul 10, 2008
    #5
    Yes i would love to see this setup modified to include other formats, espescialy avi's.
     
  6. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #6
    I don't think HandBrake is really designed to convert between codecs. I think the latest dev build of HandBrake may be adding this, but I'm not sure. Anyway, necessity is what drove me to figure out this workflow. Perhaps one of you will be so obsessed that you will find a way and let the rest of us know.:)
     
  7. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #7
    Forgot to include instructions for M4V output for DD 5.1

    Post Edited:
    This post originally included a step for changing the MP4 output container to M4V for 5.1 Dolby Digital output. This is now a property in the BatchRip.scpt and also allows HandBrakeCLI to save files in three other widely used containers: .mkv, .avi, and .ogm.
     
  8. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #8
    ANNOUNCEMENT: Tutorial & Scripts Updated!

    ANNOUNCEMENT!
    The tutorial instructions and scripts have been updated to make them more plug and play.

    Changes:
    • Scripts have been rewritten to make them much easier to setup. My hope is that most users will not have to modify the scripts at all.
    • Scripts now include defaults that should run on any system. Default locations for files and scripts have been set to the ~/Movies/ directory.
    • BatchRip and BatchEncode Folders are now automatically created in your ~/Movies/ folder.
    • Growl Nofity Code has been moved to a script library that is loaded when called. You can now easily enable it in your batch script's properties.
    • BatchRip now auto-checks if two disks are loaded, no dual-drive setup required.
    • BatchRip now includes an auto-eject yes/no property.
    • BatchRip will now growl the disk name(s) when completed. Great for email notification.
    • HandBrakeCLI-Batch.sh shell script has been updated & posted. No additional setup should be needed.
    • BatchEncode now uses HandBrake's Universal preset by default.
    • BatchEncode now includes easier setup for encoding two batch folders at the same time.
    • BatchEncode now has a file type property to easily change output container. Default has been set to .m4v.

    That might be it. Will edit if I think of anything else. Thx.
     
  9. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #9
    ANNOUNCEMENT!
    The tutorial instructions and scripts have been updated.

    Changes:
    • BatchRip, BatchEncode and the HandBrakeCLI-batch.sh have been updated to correctly parse spaces in the directory tree
    • BatchEncode now displays progress through Terminal and saves output to a text file.

    Thx.
     
  10. macrumors 6502a

    Joined:
    Jan 29, 2008
    #10
    question about the script? Seeing the terminal output there are lots of 'finds' going on, on a volume not related to the script or rip or encode. Is that normal? Here is the first part of my terminal output for reference.

    Code:
    Last login: Sun Jan 25 16:32:02 on ttys000
    ~/Movies/BatchScripts/HandBrakeCLI-batch.sh 'Volumes/media/JPNrips' 'Volumes/media/encodes' '.m4v' '20' '--preset="Universal" -2 -T -N eng --decomb' | tee Volumes/media/encodes/BatchEncode.log
    MacMini:~ richardmini$ ~/Movies/BatchScripts/HandBrakeCLI-batch.sh 'Volumes/media/JPNrips' 'Volumes/media/encodes' '.m4v' '20' '--preset="Universal" -2 -T -N eng --decomb' | tee Volumes/media/encodes/BatchEncode.log
    tee: Volumes/media/encodes/BatchEncode.log: No such file or directory
    HandBrakeCLI-batch.sh v1.0
      Start: Sun 25 Jan 2009 16:32:02 GMT
      Input directory: /Volumes
      Output directory: /Users/richardmini/Movies/BatchRip
      Minimum get track time: 60 mins
      Tool path: /Applications/HandBrakeCLI
      Tool args:  Volumes/media/JPNrips Volumes/media/encodes .m4v 20 --preset="Universal" -2 -T -N eng --decomb
      - - - - - - - - - - - - - - - -
    find: /Volumes/mini backup/.Trashes: Permission denied
    find: /Volumes/mini backup/Library/Application Support/Apple/ParentalControls/Users: Permission denied
    find: /Volumes/mini backup/Library/Application Support/Apple/Remote Desktop/Client: Permission denied
    find: /Volumes/mini backup/Library/Logs/Console/501: Permission denied
    find: /Volumes/mini backup/private/etc/cups/certs: Permission denied
    find: /Volumes/mini backup/private/var/agentx: Permission denied
    find: /Volumes/mini backup/private/var/at/tabs: Permission denied
    find: /Volumes/mini backup/private/var/at/tmp: Permission denied
    find: /Volumes/mini backup/private/var/backups: Permission denied
    find: /Volumes/mini backup/private/var/db/dhcpclient: Permission denied
    "media" is an external USB drive attached to the mini. "mini backup" is a partition on the same drive used for superduper clones of the mini. I have no idea what its looking at that for at all?

    and then, at the end, after a bunch more 'finds', it comes up with this

    Code:
      * Processing DVD 'SILENT_RUNNING'
       No tracks on this DVD are longer then the minimum track time setting
      * Processing DVD 'Kikis delivery service'
       Will encode the following tracks: 1 
    
    now the kiki part is fine, thats what its encoding, but SILENT_RUNNING isn't there any more - I checked and it was never in the JPNrips folder, and isn't in the normal rips folder either. Is that just a hangover from a previous encode?
     
  11. macrumors 6502a

    Joined:
    Jan 29, 2008
    #11
    another question :D

    How do I get the batch encode script to put the system to sleep once its finished encoding? I think from reading up a little that the command is

    Code:
    tell application "Finder" to sleep
    but where in the batch script should I put it?

    Then I can set it to run each morning and if the queue is empty it'll just go to sleep to save energy during weekdays when its not going to be used
     
  12. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #12
    Hi, it appears your input directory is not entered correctly and it's trying to find all TSVideo folders on all Volumes.

    I think you're missing a "/" at the beginning of your paths. It should be: "/Volumes/media/JPNrips"

    If you want, post your entire script and I'll take a look. This is what my output looks like (notice all the paths start with a /):

    Code:
    /Volumes/SpeedDisk/Scripts/HandBrakeCLI-batch.sh '/Volumes/SpeedDisk/Batch Rip 2' '/Volumes/SpeedDisk/Batch Encode' '.m4v' '20' '--preset="Universal" -2 -T' | tee /Volumes/SpeedDisk/Batch\ Encode/BatchEncode2.log
    HandBrakeCLI-batch.sh 2.0
      Start: Sun Jan 25 12:02:00 PST 2009
      Input directory: /Volumes/SpeedDisk/Batch Rip 2
      Output directory: /Volumes/SpeedDisk/Batch Encode
      File type: .m4v
      Minimum get track time: 20 mins
      Tool path: /Applications/HandBrakeCLI
      Tool args: --preset="Universal" -2 -T
      - - - - - - - - - - - - - - - -
    

    Since your script is scanning all volumes, I think SILENT_RUNNING is probably somewhere on your system, either on your HD or an external drive, could even be on a mounted network drive. Once your input directory is correctly pointed to your batch folder. It will only scan that folder.

    I hope this helps. Thx.
     
  13. thread starter macrumors 6502

    Joined:
    Feb 1, 2008
    Location:
    The O.C.
    #13
    You could try putting it after the End Try. However, I wouldn't do it. It might cause issues if the script hasn't finished completely and you never know if there is a backup or something else going on when the command is issued.

    I'd just set your sleep preferences to sleep after 30 or ? minutes of inactivity. That's what I do. If you setup an iCal alarm, the system should wake up and execute the script. You might have to set the "wake for administrator access" to on in the security pref pane. I don't remember if that's necessary or not.
     
  14. macrumors member

    Joined:
    Jan 26, 2009
    #14
    mac.jedi: Is there a way to select audio track, but with Language instead of number ? I'm not sure that my DVD's are all the same, so if I changed the script to look for Track 2 (French) on a DVD, how can I be sure it will be track 2 on all DVD ? I looked on the CLI wiki, but didnt find anything about that. They say you can have multiple audio track, but they dont say how to select a track by it's HEX Language code....

    Do you think it's possible, because if not, it's pretty useless ! I would have to check each of them in the process which defeat the purpose of automation...

    GoldstarQC
     
  15. macrumors 6502a

    Joined:
    Jan 29, 2008
    #15
    I've looked and couldn't find anything. There was a brief discussion I found on the handbrake forums somewhere, and they pointed out that it isn't foolproof, as a DVD may have multiple language tracks for the same language - eg main audio, stereo, commentary etc.

    I wanted this to pick out Japanese audio from anime DVDs - discs from Japan are usually Japanese on track 1, but UK releases are usually English dub on track 1. I've ended up manually selecting the UK releases, and automatically doing the Japanese discs, and its working out ok so far.
     
  16. macrumors demi-god

    Joined:
    Jul 7, 2007
    #16
    I'm trying to convert a tv series(house) I tried the script but it says there are no files greater than 20 mins. I think the issue is that the each episode is made up of multiple vob files and theyre about 13 mins each. Using this method will it only include the episodes by the small portions, or can I have it put together an entire episode?

    Thanks
     
  17. macrumors 6502a

    Joined:
    Jan 29, 2008
    #17
    I'm either going to have to give up on this stage, or write about 4 different encode scripts, perhaps setting each one to execute on a different day of the week. I just have too many discs that don't fit into one standard. Off the top of my head I have

    1) standard english language discs with english on track 1, no subs

    2) Japanese import anime (mostly Ghilbi collection) which usually have Japanese on track one, and so I'd need english subs. I already have an amended batchencode script to hard code english subs when Japanese is the first audio track

    3) English/US anime (eg Disney distributed Ghibli). These usually have the English dub as the first language, with Japanese on track 2. So I'd need a different script to force track 2, then use english subs as per (2) above

    4) Disney discs which basically don't like being ripped at all.

    So I'll end up with at least 3 scripts, and probably have to manually handle the disney stuff via handbrake 'specific title' or MTR chapter extraction.

    I think I can handle the 3 different encode scripts, perhaps having 3 different batch rip scripts to put them in the right buckets (I already have 2 batchrip scripts mapped to remote control button presses via Remote buddy), and then maybe use my MBP to do the Disney stuff by hand.
     
  18. macrumors 65816

    Joined:
    Aug 24, 2005
    #18
    New problem - I can only figure through reading that I can use Handbrake presets in the CLI, however I have a preset named 'iPhone Movie' in my Handbrake GUI which rips just right for my needs on iPhone, iTunes, and AppleTV, but as I understand this won't exist in the CLI application I just installed, or will it? And if it doesn't, how can I get this automation to work to my preferred custom preset?


    And another problem, I got to this stage yesterday and tried getting it to do the automated handbrake bit and had an error come up when the script ran. Perhaps someone can help me decode this?

    Here's my code for the batch encode script
    Code:
    ---------- BatchEncode.scpt ----------
    ---------- Updated: 01-22-2009 ----------
    
    
    global batchScript1, batchScript2
    
    ---------- Properties ----------
    
    -- The input directory to process all DVDs (TS Folders) in it. Default is: ~/Movies/BatchRip. This folder will be automatically created on first run, but the script will fail since there isn't anything in the folder.
    property inputPath1 : "/Volumes/Toshiba/batchrip"
    
    -- The output directory for all output files. Default is: ~/Movies/BatchEncode. This folder will be automatically created on first run.
    property outputPath : "/Volumes/Toshiba/batchencode"
    
    -- The path to your HandBrakeCLI-batch.sh script. Default is: ~/Movies/BatchScripts/HandBrakeCLI-batch.sh
    property scriptPath : "/Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh" -- Insert the path to HandBrakeCLI-batch.sh.
    
    -- Set your HandBrakeCLI encode settings.  Default is the Universal preset, HandBrake's universally compatible, full resolution settings for all current Apple devices: iPod, iPhone, AppleTV, and Macs). For more info in setting parameters, visit http://handbrake.fr and read the CLI Guide Wiki. 
    property encodeSettings : "--preset=\"AppleTV\"" -- Note: you must escape quotes for presets. 
    
    -- Set the minimum time (minutes) of the track/s to encode (default: 20)
    property minGetTime : "20"
    
    ---------- Optional Properties ----------
    
    -- Dual-Encode: If you have a fast multi-core processor and hard disk, you can setup two batch folders to encode two RIPs at once. 
    property batchFolders : 1 -- If adding a second input directory, change number of batch folders to 2. 
    property inputPath2 : "~/Movies/BatchRip2" -- Set second input directory to process all DVDs in it. Default is: ~/Movies/BatchRip2. This folder will be automatically created if the batchFolders property is set to 2.
    
    -- Output Container: This script's default output container is .m4v(mp4). HandBrake can also save files in: .mkv, .avi, and .ogm.
    property fileType : ".m4v"
    
    -- Setup Growl Support: Set useGrowl to yes and set the path to the GrowlNotifyLib.scpt.
    property useGrowl : no -- If you have growl, set to yes.
    property growlTitle : "Batch Encode"
    property growlMessage : "Your HandBrake Encodes Are Done!"
    property growlLibraryPath : POSIX file "Users/userloginname/Movies/BatchScripts/GrowlNotifyLib.scpt" -- Set the path to the GrowlNotifyLib.scpt.
    
    ---------- Encode Script ----------
    
    try
    	if useGrowl is yes then setGrowl(growlTitle) of (load script growlLibraryPath)
    end try
    try
    	createBatchScript()
    	mkDir(inputPath1) & mkDir(outputPath)
    	if batchFolders is 2 then mkDir(inputPath2)
    	with timeout of 36000 seconds
    		doScript()
    		growlMe(growlTitle, growlMessage) of (load script growlLibraryPath)
    	end timeout
    end try
    
    ---------- Sub-routines ----------
    to doScript()
    	tell application "Terminal"
    		activate
    		tell application "System Events" to keystroke "n" using {command down}
    		if batchFolders is 2 then repeat 1 times
    			tell application "System Events" to keystroke "t" using {command down}
    		end repeat
    		do script batchScript1 in tab 1 of window 1
    		if batchFolders is 2 then do script batchScript2 in tab 2 of window 1
    		repeat until tab 1 of window 1 is not busy
    			delay 4
    		end repeat
    		if batchFolders is 2 then repeat until tab 2 of window 1 is not busy
    			delay 4
    		end repeat
    	end tell
    end doScript
    
    to setInput(batchFolder)
    	set inputDir to quoted form of batchFolder
    end setInput
    
    to createBatchScript()
    	set spc to " "
    	set inputDir1 to setInput(inputPath1)
    	set inputDir2 to setInput(inputPath2)
    	set logFile to " | tee " & escapePath(outputPath)
    	set outputDir to quoted form of outputPath
    	set batchScript1 to escapePath(scriptPath) & spc & inputDir1 & spc & outputDir & spc & quoted form of fileType & spc & quoted form of minGetTime & spc & quoted form of encodeSettings & logFile & "/BatchEncode.log"
    	set batchScript2 to escapePath(scriptPath) & spc & inputDir2 & spc & outputDir & spc & quoted form of fileType & spc & quoted form of minGetTime & spc & quoted form of encodeSettings & logFile & "/BatchEncode2.log"
    end createBatchScript
    
    on escapePath(outputPath)
    	set the search_string to " "
    	set the replacement_string to "\\ "
    	set AppleScript's text item delimiters to the " "
    	set the text_item_list to every text item of the outputPath
    	set AppleScript's text item delimiters to the replacement_string
    	set the new_item_name to the text_item_list as string
    	set AppleScript's text item delimiters to ""
    	set the outputPath to new_item_name
    end escapePath
    
    on mkDir(somepath)
    	do shell script "mkdir -p " & escapePath(somepath)
    end mkDir
    
    ---------- End Script ---------
    Which I believed was fine (it points to the right folders for where I want it to.)

    And here's my code from the .sh file
    Code:
    #!/bin/sh
    
    #  UPDATED: 01-22-2009
    
    #  HandBrakeCLI-batch.sh is a script to batch execute the HandBrakeCLI.
    #  This script is based upon the MediaForkCLI-batch.sh.
    
    # Usage: HandBrakeCLI-batch.sh [options]
    #
    #  arg1:   inputSearchDir=<string>   Set input directory to process all DVDs in it (example: ~/Movies/Batch Rip) "
    #  arg2:   outputDir=<string>        Set output directory for all output files (example: ~/Movies/Batch Encode) "
    #  arg3:   fileType=<string>         Set the file type: .mp4, .avi, .omg, .mkv, .m4v (example: .m4v) "
    #  arg4:   minTrackTime=<number>     Set the minimum time (mins) of the track/s to encode (example: 30) "
    #  arg5:   toolArgs=<string>         Set the HandBrakeCLI encode settings (example: -2 -w 640) "
    
    # Revision history:
    # 0.20070329.0 - initial release
    # 0.20081125.0 - revised for HandBrakeCLI
    # 0.20090122.0 - fixed problem with spaces in the directory tree
    
    
    #############################################################################
    # globals
    
    # const global variables
    scriptName=`basename "$0"`
    scriptVers="2.0"
    scriptPID=$$
    saveDVDinfo=1       # the dvd track info is also saved as txt file when on
    skipDuplicates=1    # if this option is off (-0),
                        # the new output files will overwrite existing files
    E_BADARGS=65
    
    # set the global variables to default
    toolName="HandBrakeCLI"
    toolPath="/Applications/$toolName"
    toolTrackArgs="-t 0" # scans dvd title list for all tracks
    inputSearchDir="/volumes/Toshiba/batchrip"    # set input search directory: "/volumes/Toshiba/batchrip"
    outputDir="/Volumes/Toshiba/batchencode"       # set output directory: "/volumes/Toshiba/batchencode"
    fileType="$3"        # set output container: .m4v, .mp4, .avi, .omg, .mkv
    minTrackTime="$4"    # this is in minutes: "30"
    toolArgs="$5"        # set handbrakecli encode settings: "-2 -w 640"
    
    #############################################################################
    # functions
    
    verifyFindCLTool()
    {
    	# attempt to find the HandBrakeCLI if the script toolPath is not good
    	if [ ! -x "$toolPath" ];
    	then
    		toolPathTMP=`PATH=.:/Applications:/:/usr/bin:/usr/local/bin:$HOME:$PATH which $toolName | sed '/^[^\/]/d' | sed 's/\S//g'`
    		
    		if [ ! -z $toolPathTMP ]; then 
    			toolPath=$toolPathTMP
    		fi
    	fi	
    }
    
    displayUsageExit()
    {
    	echo "Usage: $scriptName [options]"
    	echo ""
    	echo "    -h, --help   Print help"
    	echo "    arg1:   inputSearchDir=<string>   Set input directory to process all DVDs in it (example: ~/Movies/Batch Rip) "
    	echo "    arg2:   outputDir=<string>        Set output directory for all output files (example: ~/Movies/Batch Encode) "
    	echo "    arg3:   fileType=<string>         Set the file type: .mp4, .avi, .omg, .mkv, .m4v (example: .m4v) "
    	echo "    arg4:   minTrackTime=<number>     Set the minimum time (mins) of the track/s to encode (example: 30) "
    	echo "    arg5:   toolArgs=<string>         Set the HandBrakeCLI encode settings (example: -2 -w 640) "
    	
    	
    	if [ -x "$toolPath" ];
    	then
    		echo "   $toolName possible options"
    		mForkHelp=`$toolPath --help 2>&1`
    		mForkHelpPt=`printf "$mForkHelp" | egrep -v '( --input| --output| --help|Syntax: |^$)'`
    		printf "$mForkHelpPt\n"
    	else
    		echo "    The options available to HandBrakeCLI except -o  and -i"
    		if [ -e "$toolPath" ];
    		then
    			echo "    ERROR: $toolName command tool is not setup to execute"
    			echo "    ERROR: attempting to use tool at $toolPath"
    		else
    			echo "    ERROR: $toolName command tool could not be found"
    			echo "    ERROR: $toolName can be install in ./ /usr/local/bin/ /usr/bin/ ~/ or /Applications/"
    		fi
    	fi
    	
    	echo ""
    	
    	exit $E_BADARGS
    }
    
    getTrackListLongerThan()
    {
    	# Two input arguments are are need. 
    	#   arg1 is the time in minutes selector
    	#   arg2 is the raw text stream from the track 0 call to HandBrake
    	#   returns: a list of track numbers of tracks longer then the selector
    	
    	if [ $# -lt 2 ]; then
    		return ""
    	fi
    	
    	minTime="$1"
    	shift
    	allTrackText="$*"
    	aReturn=""
    
    	trackList=`eval "echo \"$allTrackText\" | egrep '(^\+ title |\+ duration\:)' | sed -e 's/^[^+]*+ //'g -e 's/title \([0-9]*\):/\1-/'g -e 's/duration: //'g"`
    	
    	trackNumber=""
    	for aline in $trackList
    	do
    		trackLineFlag=`echo $aline | sed 's/[0-9]*-$/-/'`
    		if [ $trackLineFlag = "-" ];
    		then
    			trackNumber=`echo $aline | sed 's/\([0-9]*\)-/\1/'`
    		else
    			set -- `echo $aline | sed -e 's/(^[:0-9])//g' -e 's/:/ /g'`
    			if [ $3 -gt 29 ];
    			then let trackTime=($1*60)+$2+1
    			else let trackTime=($1*60)+$2
    			fi
    
    			if [ $trackTime -gt $minTime ];
    			then aReturn="$aReturn $trackNumber"
    			fi
    		fi
    	done
    	
    	echo "$aReturn"
    }
    
    makeFullPath()
    {
       aReturn=""
       currentPath=`pwd`
       
       if [ $# -gt 0 ]; then
          inPath="$*"
          
          # put full path in front of path if needed
          aReturn=`echo "$inPath" | sed -e "s!~!$currentPath/!" -e "s!^./!$currentPath/!" -e "s!^\([^/]\)!$currentPath/\1!" -e "s!^../!$currentPath/../!"`
          
          # remove ../ from path - only goes 4 deep
          aReturn=`echo "$aReturn" | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g'`
          
          # cleanup by removing //
          aReturn=`echo "$aReturn" | sed -e 's!//!/!g'`
       fi
       
       echo "$aReturn"
    }
    
    isPIDRunning()
    {
    	aResult=0
    	
    	if [ $# -gt 0 ]; then
    		txtResult="`ps ax | egrep \"^[ \t]*$1\" | sed -e 's/.*/1/'`"
    		if [ -z "$txtResult" ];
    		then aResult=0
    		else aResult=1
    		fi
    	fi
    	
    	echo $aResult
    }
    
    #############################################################################
    # MAIN SCRIPT
    
    # initialization functions
    verifyFindCLTool
    
    # fix input and output paths to be full paths
    inputSearchDir=`makeFullPath "$inputSearchDir"`
    outputDir=`makeFullPath "$outputDir"`
    
    # see if the output directory needs to be created
    if [ ! -e $outputDir ]; then
    	mkdir -p "$outputDir"
    fi
    
    # sanity checks
    if [[ ! -x $toolPath || ! -d $inputSearchDir || ! -d $outputDir || -z "$toolArgs" ]]; then
    	displayUsageExit
    fi
    
    # display the basic setup information
    echo "$scriptName $scriptVers"
    echo "  Start: `date`"
    echo "  Input directory: $inputSearchDir"
    echo "  Output directory: $outputDir"
    echo "  File type: $fileType"
    echo "  Minimum get track time: $minTrackTime mins"
    echo "  Tool path: $toolPath"
    echo "  Tool args: $toolArgs"
    echo "  - - - - - - - - - - - - - - - -"
    
    # find all the DVD videos in the input search directory tree
    # spaces in file path temporarily become /008 and paths are separ with spaces
    dvdTSVidList=`find "$inputSearchDir" -name VIDEO_TS -print0 | tr ' ' '\007' | tr '\000' ' '`
    
    # process each DVD video found
    for dvdTSDir in $dvdTSVidList
    do
    	# correct the tmp char back to spaces in the DVD file paths
    	dvdTSDir=`echo $dvdTSDir | tr '\007' ' '`
    	
    	# get the DVD's name and path to root of the DVD
    	dvdVolPath=`dirname "$dvdTSDir"`
    	dvdName=`basename "$dvdVolPath"`
    	dvdNameALNUM=`basename "$dvdVolPath" | sed 's/[^[:alnum:]^-^_]//g'`
    	
    	# display information
    	echo "  * Processing DVD '$dvdName'"
    	
    	# create tmp link to the dvdVolPath to workaround a problem that the
    	# HandBrakeCLI tool has a problem with the input file paths with space
    	# when in a script
    	tmpNoSpacePath="/tmp/dvdVol-$dvdNameALNUM-$scriptPID"
    	ln -s "$dvdVolPath" $tmpNoSpacePath
    	
    	# get the track list information from the DVD
    	cmd="$toolPath -i $tmpNoSpacePath $toolTrackArgs /dev/null 2>&1"
    	dvdTrackInfo=`eval $cmd`
    	# save the DVD info
    	outputFilePath="$outputDir/${dvdName}_Info.txt"
    	if [ $saveDVDinfo -eq 1 ]; then
    		if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]]; then
    			echo "$dvdTrackInfo" | egrep '[ \t]*\+' > "$outputFilePath"
    		fi
    	fi
    	# get the track number of tracks which are longer then the time desired
    	trackFetchList=`getTrackListLongerThan $minTrackTime "$dvdTrackInfo"`
    	if [ ! -z "$trackFetchList" ];
    	then
    		echo "   Will encode the following tracks: `echo $trackFetchList | sed 's/ /, /g'` "
    	else
    		echo "   No tracks on this DVD are longer then the minimum track time setting"
    	fi
    				
    	trackCount=`echo $trackFetchList | wc -w`
    	for aTrack in $trackFetchList
    	do
    		if [ $trackCount -gt 1 ]
    			then outputFilePath="$outputDir/${dvdName}${aTrack}$fileType"
    			else outputFilePath="$outputDir/${dvdName}$fileType"
    		fi
    		cmd="$toolPath -i $tmpNoSpacePath $toolArgs -t $aTrack -o \"$outputFilePath\" > /tmp/${dvdNameALNUM}Results.txt 2>&1"
    		
    		if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]];
    		then
    			# simple command execution
    			#ripResult=`eval $cmd`
    			
    			# background command execution with some status
    			eval $cmd &
    			cmdPID=$!
    			while [ `isPIDRunning $cmdPID` -eq 1 ]; do
    				cmdStatusTxt="`tail -n 1 /tmp/${dvdNameALNUM}Results.txt | grep 'Encoding: '`"
    				if [ ! -z "$cmdStatusTxt" ]; then
    					echo -n "$cmdStatusTxt"
    				fi
    				sleep 1s
    			done
    			echo ""
    			wait $cmdPID
    			
    		else
    			echo "   Output file SKIPPED because it ALREADY EXISTS"
    		fi
    		
    		if [ -e /tmp/${dvdNameALNUM}Results.txt ]; then
    			rm /tmp/${dvdNameALNUM}Results.txt
    		fi
    	done
    
    	rm $tmpNoSpacePath
    done
    
    echo "  - - - - - - - - - - - - - - - -"
    echo "  End: `date`"
    
    exit 0
    
    
    # End Script
    And finally, here's the error message I get
    Code:
    Last login: Sun Feb  8 10:38:00 on ttys000
    /Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh '/Volumes/Toshiba/batchrip' '/Volumes/Toshiba/batchencode' '.m4v' '20' '--preset="AppleTV"' | tee /Volumes/Toshiba/batchencode/BatchEncode.log
    david-clarkes-macbook:~ davidclarke$ /Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh '/Volumes/Toshiba/batchrip' '/Volumes/Toshiba/batchencode' '.m4v' '20' '--preset="AppleTV"' | tee /Volumes/Toshiba/batchencode/BatchEncode.log
    /Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh: line 1: {rtf1ansiansicpg1252cocoartf949cocoasubrtf270: command not found
    /Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh: line 2: syntax error near unexpected token `}'
    /Volumes/Toshiba/batchrip/HandBrakeCLI-batch.sh: line 2: `{\fonttbl\f0\fmodern\fcharset0 Courier;}'
    david-clarkes-macbook:~ davidclarke$ 
    
    Any help anyone? Please? :S
     
  19. macrumors newbie

    Joined:
    Feb 14, 2009
    #19
    error encode script

    When I try to run the script, it says this:

    bteeuwen@Ben-2 ~]$~/Movies/BatchScripts/HandBrakeCLI-batch.sh '~/Movies/BatchRip' '~/Movies/BatchEncode' '.m4v' '20' '--preset="Universal"' | tee ~/Movies/BatchEncode/BatchEncode.log
    /Users/bteeuwen/Movies/BatchScripts/HandBrakeCLI-batch.sh: line 1: {rtf1ansiansicpg1252cocoartf949cocoasubrtf430: command not found
    /Users/bteeuwen/Movies/BatchScripts/HandBrakeCLI-batch.sh: line 2: syntax error near unexpected token `}'
    /Users/bteeuwen/Movies/BatchScripts/HandBrakeCLI-batch.sh: line 2: `{\fonttbl\f0\fswiss\fcharset0 Helvetica;}'

    Any ideas what I am doing wrong?
     
  20. macrumors newbie

    Joined:
    Aug 20, 2007
    Location:
    Kansas
    #20
    I've been having the exact same error and finally figured out the problem. In textedit when you are creating the HandBrake script you need to format the document for plain text which is done by clicking 'Make Plain Text' under format on the menu bar. That's what got it working for me.
     
  21. macrumors newbie

    Joined:
    Mar 31, 2008
    #21
    Simple question, but does the universal preset automatically encode the dolby digital track with this script so u get surround sound on the appletv?

    thx
     
  22. macrumors newbie

    Joined:
    Jun 12, 2008
    #22
    25gig log file???

    I just ran this script to encode the rips in my BatchRip folder (4 dvds) and when reviewing all of the files it appeared that batchencode.log was just under 25gb in size? Any idea what could be going on? When encoding, the progress was printing a new line every second or so, resulting in thousands of lines over the 18 hours or so of encoding, but still, I would think that the log file is only text, so why would it be so big? Must be some type of bug in the code, right?

    Can someone help out, or offer to either review my scripts for me? I copied and pasted everything, only changing the CLI options for HandBrake.

    Thanks
    Mike
     
  23. macrumors newbie

    Joined:
    May 24, 2009
    #23
    Another syntax error

    When I copy and paste, and then hit CMD + K, it errors and tells me "expected end of line, but found number."

    It then highlights numbers like what I've bolded below:

    end repeat
    do script batchScript1 in tab 1 of window 1
    if batchFolders is 2 then do script batchScript2 in tab 2 of window 1
     
  24. macrumors newbie

    Joined:
    Jul 3, 2009
    #24
    Yeah, that batchencode.log was insanely sized for me as well. I figured out why. Here are my changes. This increased my encoding speed by almost 15x!

    Change the lines in HandBrakeCLI-batch.sh near line 263 to look like this. I changed the tail, echo and sleep parameters.
    Code:
    			while [ `isPIDRunning $cmdPID` -eq 1 ]; do
    				cmdStatusTxt="`tail -b 1 /tmp/${dvdNameALNUM}Results.txt | grep 'Encoding: '`"
                                    if [ ! -z "$cmdStatusTxt" ]; then
    					echo "$cmdStatusTxt"
                                    fi
                                    sleep 10s
                            done
    
     
  25. macrumors member

    Joined:
    Apr 10, 2002
    #25
    Will it know if it's already encoded something?

    As far as I can tell, I've got the scripts installed correctly, but with the multiple iCal events starting the batch encoding, it seems to attempt to re-encode everything that's in BatchRip each time it runs. Is this correct behavior?

    Thanks

    Stuart
     

Share This Page