Created
January 27, 2010 08:48
-
-
Save pklaus/287665 to your computer and use it in GitHub Desktop.
Rip a DVD in an Automated Way
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 | |
# found on <http://episteme.arstechnica.com/eve/forums/a/tpc/f/96509133/m/792004650041?r=798009370041#798009370041> | |
# Exit Codes | |
# 1 : vobcopy failed | |
# 2 : encoding failed | |
# 3 : lock file present | |
# 4 : DVD not mounted | |
# 5 : VIDEO_TS not present - probably not a video DVD | |
VOB_DIR="/tmp/ripdvd/vobs" # Location to store vobs | |
ENC_DIR="/mnt/movies" # Location to place encoded videos | |
DVD_DIR="/media/dvd" # Mount location of dvd | |
DVD_DEV="/dev/hda" # DVD Device | |
LOCK_FILE="/tmp/ripdvd/ripdvd.lock" # Lock File | |
# Only run if not already running | |
if [ -f "${LOCK_FILE}" ]; then | |
echo "*** Lock file present" | |
exit 3 | |
fi | |
touch "${LOCK_FILE}" | |
mount | grep "${DVD_DIR}" | |
if [ $? -ne 0 ]; then | |
# dvd not mounted | |
echo "*** DVD not mounted" | |
rm "${LOCK_FILE}" | |
exit 4 | |
fi | |
sleep 30; | |
if [ ! -d "${DVD_DIR}/VIDEO_TS" ]; then | |
# not a video dvd? | |
echo "*** VIDEO_TS directory not present" | |
rm "${LOCK_FILE}" | |
exit 5 | |
fi | |
DVD_NAME="$(vobcopy -I 2>&1 > /dev/stdout | grep DVD-name | sed -e 's/.*DVD-name: //')" | |
vobcopy -m -o "${VOB_DIR}" -i "${DVD_DIR}" | |
if [ $? -ne 0 ]; then | |
# vobcopy failed | |
echo "*** Error during vob copy" | |
rm -rf "${VOB_DIR}/${DVD_NAME}" | |
rm "${LOCK_FILE}" | |
exit 1 | |
fi | |
MP4_NAME="${DVD_NAME}" | |
INC="" | |
while [ -f "${ENC_DIR}/${MP4_NAME}${INC}.mp4" ]; do ((INC=INC+1)); done; | |
if [ ${INC} -ne "" ]; then MP4_NAME="${MP4_NAME}${INC}"; fi | |
HandBrakeCLI -i "${VOB_DIR}/${DVD_NAME}/" -o "${ENC_DIR}/${MP4_NAME}.mp4" -e x264 -b 1500 -a 1 -E faac -B 160 -R Auto -6 dpl2 -f mp4 -m -2 -T -x ref=2:bframes=2:me=umh | |
if [ $? -ne 0 ]; then | |
# encoding failed | |
echo "*** Error during encoding" | |
rm -rf "${VOB_DIR}/${DVD_NAME}" | |
rm "${ENC_DIR}/${MP4_NAME}.mp4" | |
rm "${LOCK_FILE}" | |
exit 2 | |
fi | |
rm -rf "${VOB_DIR}/${DVD_NAME}" | |
umount "${DVD_DIR}" && eject "${DVD_DEV}" | |
rm "${LOCK_FILE}" | |
echo -e "\n\nRip of ${DVD_NAME} completed.\nEncoded to ${ENC_DIR}/${MP4_NAME}.mp4" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment