Skip to content

Instantly share code, notes, and snippets.

@rosiel
Created September 17, 2014 13:54
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 rosiel/78b27586ef9e18b00604 to your computer and use it in GitHub Desktop.
Save rosiel/78b27586ef9e18b00604 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Mac-compatible script
# Writes the contents of an unprotected DVD to an MPEG-2 file in the current directory.
# Temporarily set the for-loop delimiter to deal with filenames with spaces.
# Source: http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# Iterate over /Volumes/*/VIDEO_TS, i.e. find all volumes that are DVDs
for VTSPATH in $(find /Volumes -name VIDEO_TS -maxdepth 2 -mindepth 2)
do
# Get disk name
DVDNAME=${VTSPATH#/Volumes/}
DVDNAME=${DVDNAME%/VIDEO_TS}
# Find .VOB files
DVDPATH=$(find "$VTSPATH" -name "VTS*.VOB" 2>/dev/null | tr "\\n" "|" )
# Exit if files not found
if [ ! "$DVDPATH" ]; then
echo ".VOB files not found in $VTSPATH. Exiting."
exit
fi
echo -e "\n\n$DVDNAME\n"
read -p "That is the disk name. Is this the desired output filename? [y/N]: " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "\n\nEnter the desired output filename:"
read inputname
while [ $inputname = "" ]; do
read inputname
done
inputname=$(echo $inputname | sed -e 's/ //g')
echo $inputname
DVDNAME=$inputname
fi
# Perform the encoding
ffmpeg -i concat:"$DVDPATH" -f mpeg -c:v copy -c:a mp2 $DVDNAME.mpg
# Uncomment the following to give a system alert when the file is done.
# osascript -e 'tell app "System Events" to display dialog "Your disk is done!"'
# Eject the disk.
drutil eject external
done
# Reset the for-loop delimiter
IFS=$SAVEIFS
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment