Created
February 24, 2017 19:28
-
-
Save realchrisolin/90b9f682de1df7107cfca5c970fa207d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
#This script is a simple bash script that checks the directory (and subdirectories) that it is | |
#run in and tries converting any ISO images to H.264 videos using Handbrake. You will need | |
#dirname installed on your machine along with HandBrakeCLI. | |
# | |
#WARNING: It WILL change the extensions of your .iso images to .osi. Comment the second to last | |
#line in the script if you do not want this to happen. | |
# | |
#Be sure to edit the script and change "/path/to/converted_movies" to whatever directory you | |
#want the converted files to be placed in. The script is written to create a folder in this | |
#directory with the name of the name of the directory the ISO image is found in. In the case | |
#of subdirectories, the directory name in the converted directory is created with the name of | |
#the "root" directory and the filename the same as the source file, sans .iso extension. See below for an example. | |
# | |
#../Movie Name/A Subdirectory/Another Subdirectory/Example.iso | |
# | |
#will result in | |
# | |
#../path/to/converted_movies/Movie Name/Example.mp4 | |
#Enabling debug mode so we can see what is happening. | |
find . -iname "*.iso" | while read file | |
do | |
#Print second field because results start with ./<dir>/... | |
dir=`echo "$file" | awk -F/ '{print $2}'` | |
dir2=`dirname -- "$file"` | |
if [ -d "$dir" ]; then | |
filename=`echo "$file" | awk -F/ '{print $NF}' | sed 's/.\{4\}$//'` | |
fi | |
mkdir /path/to/converted_movies/"$dir" | |
HandBrakeCLI -v --preset="High Profile" -i "$file" -o /path/to/converted_movies/"$dir"/"$filename".mp4 -f mp4 -O --main-feature -m -B 160,440 -s 1,2,3,4,5,6,7,8,9 < /dev/null 2> /path/to/converted_movies/"$dir"/log.txt | |
#Comment the next line to prevent this script from renaming converted .iso files | |
#to .osi. Copy/paste and execute the following comment with the # after this script | |
#is done running to restore .iso extension | |
#find . -iname "*.osi" | while read f; do echo mv \"$f\" \"${f/.osi/.iso}\"; done | |
mv "$file" "$dir2"/"$filename".osi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment