Skip to content

Instantly share code, notes, and snippets.

@rsgranne
Created August 11, 2014 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsgranne/aa07d7864ea0bd47ae01 to your computer and use it in GitHub Desktop.
Save rsgranne/aa07d7864ea0bd47ae01 to your computer and use it in GitHub Desktop.
Convert contents of current folder to M4V using HandBrakeCLI
#!/bin/bash
#===============================================================================
# FILE: handconv.sh
#
# USAGE: Run manually
#
# DESCRIPTION: Converts the contents of the current folder to M4V using HandBrakeCLI
#
# AUTHOR: Scott Granneman (RSG), scott@websanity.com
# COMPANY: WebSanity
# VERSION: 0.1
# CREATED: 05/31/2013 10:48:32 CDT
# REVISION:
#===============================================================================
# Set IFS to split on newlines, not spaces, but first save old IFS
# See http://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names
SAVEIFS=$IFS
IFS=$'\n'
for i in $(ls *) ; do
# Get the extension of the file, so we can get $filename
extension=${i##*.}
# Get the name of the file, sans extension
filename=$(basename "$i" $extension)
# Encode files with HandBrakeCLI
/Applications/HandBrakeCLI -i "$i" -o ~/Desktop/"$filename"m4v --preset="Normal"
done
# Restore IFS so it’s back to splitting on <space><tab><newline>
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment