Register
It is currently Thu Apr 24, 2014 1:29 pm

Burning/Ripping video DVDs


All times are UTC - 6 hours


Post new topic Reply to topic  [ 17 posts ] 
Author Message
 PostPosted: Sat Sep 16, 2006 12:59 am   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Here's a script I use quite a bit........I have a friend who films and edits videos (singers and bands), which get put on a local Comcast channel, periodically. Then he has a master disc made and I rip-n-burn a bunch for him..... :-)

So this script actually started out as two separate scripts, about one page of code for each........Then I started adding a few features, here and there. But, after a few mishaps, I started adding sanity checks until I felt comfortable and could rest easy that I did a good job.......If there was a mistake to be made, I probably made it........ :lol:

This is not for editing, only ripping and burning.....But rest assured, it will get done right, or the script will scream and holler if something is wrong...... :wink:

A few of the features include:
    * Burn one disc, or a bunch at a time, and let you know which disc you're on
    * Tray will pop out for loading discs, and when the job(s) get done
    * Will automatically find the correct device for burning or ripping, or let you know if nothing appropriate is found
    * Will accept "file:///" URLS in path name

The script is well commented, so the script is also the documentation. Save it as burnvideo, and create a symlink called ripvideo in the same directory. A good place is to put it is in /usr/local/bin.

Also, this script is not only bash-specific but also made to run on Linux, due to probing the /proc directory for getting the drive info.......I suppose it could be ported to other OSes, but I'll leave that to you......... :wink:

burnvideo/ripvideo - NOTE: This script will always have the latest changes/updates included, while any changes made will be announced in one of the posts below.
Code:
#!/bin/sh
################################################################################
# burnvideo/ripvideo - burn and rip DVD videos
#
# This is actually two programs combined into one.  The script is saved as
# '/usr/local/bin/burnvideo', and then a 'ripvideo' symlink is made in the same
# directory.  Example:
#    ln -s burnvideo /usr/local/bin/ripvideo
#
# Requirements:
#   Linux OS
#   dvdbackup  growisofs  mkisofs    <-- might have to install these
#   cat  dd  isosize  fold  grep  mkdir  mount  rm  rmdir  sed  tac  tr umount
#
# NOTE: This is a Linux only program, due to probing the /proc directory for
# device info.  For the external programs, the first three programs may have
# to be installed, while the rest are standard programs and shipped with the
# majority of Linux distros.
#
#
# Written by CTWaley (aka, thegeekster),  (c) February 2006
#
# You may do anything you want with this script, as long as the line directly
# above remains with it.  Which means, give credit where credit is due!
#
################################################################################

## This is the directory to place the temporary video image when burning discs.
## It should be located in a partition with plenty of room to hold the image.
VIDTMP="/home/fun/video/tmp"

###### DO NOT EDIT BELOW THIS POINT ############################################

## Since we'll be creating files, and possibly directories, make sure we have
## sane permissions
umask 0022
readonly PROG=${0##*/}

## Assigning aliases for easier typing and not forgetting some needed options:
alias echo="echo -e"
alias fold="fold -s"
alias growisofs="growisofs -dvd-compat \
                           -use-the-force-luke=wrvfy,noload,dao \
                           -speed=1"
alias sed="sed -r"
alias toUpper="tr [[:lower:]] [[:upper:]]"

## The hex value '\x1b' is the same as the more familiar octal value '\033',
## which represents the <Esc> key on the keyboard
B="\x1b[1m"  # Bold
b="\x1b[0m"  # Unbold  (actually 'undo' whatever was 'done' in the first place)

## These two help identify what the hex values we're using mean"
TAB="\x09"
LF="\x0a"

## CD/DVD drive info using the /proc filesystem instead of 'cdrecord -scanbus'
DEVINFO="$(sed -n '/drive name:/,/DVD-RAM/p' </proc/sys/dev/cdrom/info | sed "s/$TAB+/$TAB/g")"
## Arrays to hold the results of the DEVINFO query.  Note - We must reverse the
## results in case there's more than one valid device.  The dev/cdrom/info lists
## the devices in reverse order, such as:
##   drive name:             sr1     sr0
##
## Useful lines to check for in '/proc/sys/dev/cdrom/info' are:
##   drive name:
##   Can play audio:
##   Can write CD-R:
##   Can write CD-RW:
##   Can read DVD:
##   Can write DVD-R:
##   Can write DVD-RAM:
##
DRIVE=($(grep 'drive name:' <<<"$DEVINFO" | sed "s/.+:$TAB(.+)/\1/; s/$TAB/$LF/" | tac))
NUMDRIVE=${#DRIVE[@]}  ## Number of drives found
# Can read DVDs  (0 means 'no', 1 means 'yes')
READDVD=($(grep 'read DVD:' <<<"$DEVINFO" | sed "s/.+:$TAB(.+)/\1/; s/$TAB/$LF/" | tac))
# Can write DVDs  (0 means 'no', 1 means 'yes')
WRITEDVDR=($(grep 'write DVD-R:' <<<"$DEVINFO" | sed "s/.+:$TAB(.+)/\1/; s/$TAB/$LF/" | tac))
unset DEVINFO  ## We're done with this variable, so let's free up a little memory

##
##  Program functions
##
error_msg(){
    echo "\n===> $PROG: ERROR: $*" | fold >&2
}

warn_msg(){
    echo "\n===> WARNING: $*" | fold >&2
}

## Find the proper type of device asked for and assign to DEV, if it exists.
## Usage: find_dev ${READDVD[*]}   -or-   find_dev ${WRITEDVD[*]}
find_dev() {
    local -i SUB
    local -a TEMP=($1)
    ## Looping in case more than one drive found
    for ((SUB=0 ; SUB<NUMDRIVE ; SUB++))
    do  ## Find first value of 1, assign corresponding drive to DEV and return successful
        test ${TEMP[$SUB]} -eq 1  &&  export DEV=/dev/${DRIVE[$SUB]}  &&  return 0
    done
    ## Else found only 0(s) (not 1), so return unsuccessful
    return 1
}

## Find iso size.  Usage: find_size image|device
find_size(){
#    du -sb <"$1" | cut -f1
    isosize "$1"
}

## Random generator function, called from the rip_video() function. (Some of you
## might recognize this as a variation of "gen_pass()" from my version of a
## random password generator <http://bashscripts.org/viewtopic.php?p=808#808> ;-) )
mk_temp(){  ##  Usage:  VAR=$(mk_temp)
    local RNDDEV
    test -c /dev/urandom  &&  RNDDEV=/dev/urandom  ||  RNDDEV=/dev/random
    echo /tmp/ripvid.$(LC_ALL=C tr -dc "[:alnum:]" <$RNDDEV | head -c 6)
}

## Called from the burn_video() function, if needed.  Usage:  tmp_iso $SOURCE
tmp_iso(){
    local ISOINFO="$(isoinfo -d -i $SOURCE 2>/dev/null)"
    export IMAGE="$(sed -n 's/Volume id: (.+)/\1/p' <<<"$ISOINFO").tmp"

    ## Function that reads the raw data from a device, using 'dd'.
    ## NOTE; This function is based on a script called 'rawread' by Steve Litt,
    ## which can be found at "Coasterless CD Burning"
    ##    <http://www.troubleshooters.com/linux/coasterless.htm#rawread>:
    raw_read(){
        local -i BS COUNT

        BS=$(sed -n 's/Logical block size is: (.+)/\1/p' <<<"$ISOINFO")
        test -z "$BS"  &&  error_msg "No block size present\n"  &&  exit 1

        COUNT=$(sed -n 's/Volume size is: (.+)/\1/p' <<<"$ISOINFO")
        test -z "$COUNT"  &&  error_msg "No block count present\n"  &&  exit 1

        dd if=$1 bs=$BS count=$COUNT conv=notrunc,noerror > "$VIDTMP/$IMAGE"
        IMGSIZE="$(find_size $VIDTMP/$IMAGE)"  ## Finding image size for comparison
    }

    test ! -d "$VIDTMP"  &&  ## Making sure the temp directory exists
        { warn_msg "The directory, ${B}${VIDTMP}${b}, does not exist."
              return 1;}

    SRCSIZE="$(find_size $SOURCE)"  ## Finding the source size on the disc

    ## If an image already exists, is it the same size as what's on the disc?
    if [ -f "$VIDTMP/$IMAGE" ];then
        IMGSIZE="$(find_size $VIDTMP/$IMAGE)"
        test $IMGSIZE -ne $SRCSIZE  &&  ## If size mismatch, do it over
            { echo "Recreating temp image, ${B}${IMAGE}${b}..."
              raw_read "$SOURCE";}
    else  ## No image found
        echo "===> Creating temp image of ${B}${SOURCE}${b}..."
        raw_read "$SOURCE"
    fi

    test $IMGSIZE -ne $SRCSIZE  &&  ##  Double-checking for any size mismatches
        { warn_msg "There is a size mismatch between ${B}${SOURCE}${b} and ${B}$VIDTMP/${IMAGE}${b}.  This may mean there isn't enough room to create the image, or there may be hardware/software issues to be taken care of."
          return 1;}
    ## Reassigning SOURCE to the temp image
    SOURCE="$VIDTMP/$IMAGE"
    return 0
}

print_usage(){  ## Usage: print_usage
    if [ "$PROG" == "ripvideo" ];then
        echo "\n\tUsage:  $PROG /path/to/video/directory\n"
    elif [ "$PROG" == "burnvideo" ];then
        cat<<_USAGE_

    Usage:  $PROG [-c NUM] /my/video/directory
            $PROG [-c NUM] /my/video/filename.iso
The name given to the video will be the name of the directory/ISO given. NUM is
the number of copies to be made (optional).

_USAGE_
    fi
}

## This is an important function to determine what we need to do, based on the
## return code.  Usage: test_iso image|block device
test_iso(){
    isoinfo -i "$1" >/dev/null 2>&1
    return $?

##  Some results of the return code.
:<<_RETURNS_
   0: target is ISO 9660 formatted
   1: target is not an ISO image, it is a file or corrupt image
   2: target does not exist
   5: target is audio formatted
   6: target is not an ISO, it is an empty device (no disc in tray)
  13: permission denied to open target  (fix perms or run as root)
  19: target is not an ISO, it is an unused character device
  21: target is not an ISO, it is a directory
  22: target is not an ISO, it is a blank/unformatted disc
  29: target is not an ISO, it is a character device
  30: target is unreadable (missing or bad)
255: target is too small to be a valid image
_RETURNS_
}

## 'burnvideo' program converted to a function.  Usage: burn_video "$@"
burn_video(){
    ## Check for the existence of a DVD writer:
    find_dev "${WRITEDVDR[*]}"  ||
        { error_msg "No DVD writer found\n"  &&  exit 1;}

    ## See if we have 'growisofs'.  If not, say so and bail
    which growisofs >/dev/null 2>&1  ||
        { error_msg "Cannot find 'growisofs', which is needed for burning DVDs.\n"
          exit 1;}

    ## Does more than one disc need to be burned?  If so, chop off the
    ## option switch in $1 to see if NUM is appended to the switch
    case $1 in
        --copy*)  ## We'll only shift once here since NUM _must_ be appended
            test -z "${1/--copy=/}"  &&  ## If empty, say so and bail
            { error_msg "No number of copies specified in ${B}${1}${b}.\n"
              print_usage <&2  &&  exit 1;}
            NUM=${1/--copy=/}  &&  shift 1
        ;;
        -c*)
            if [ -z ${1/-c/} ]; then
                ## If empty, assign $2 to NUM and shift the command args twice
                NUM="$2"  &&  shift 2
                ## If still empty, say so and bail
                test -z "$NUM"  &&
                    { error_msg "Not enough arguments on the command line."
                      print_usage >&2  &&  exit 1;}
            else  ## It must not be empty, so we'll only need to shift once
                NUM="${1/-c/}"  &&  shift 1
            fi
        ;;
        *)  ## We don't have any request for more than one disc to burn
            NUM=1
        ;;
    esac

    ## Sanity checks
     # Okay let's see if we have a valid number to work with:
    [[ $NUM =~ [^[0-9]]* ]]  &&  ## If not all numbers, say so and bail
        { error_msg "${B}${NUM}${b} is not a valid, whole decimal number.\n"
          exit 1;}
     # Now, let's see if we have any args left after the shifting:
    test -z "$1"  &&
        { error_msg "Not enough arguments on the command line."
          print_usage >&2  &&  exit 1;}
     # Assign SOURCE before test if $1 exists (will also accept 'file:///' URLs):
    test "$1" == "."  &&  SOURCE="$(pwd)"  ||  SOURCE="$(sed 's|file:/{1,3}|/|' <<<"$1")"
     # Finally, if the last arg does not exist, say so and bail:
    test ! -e "$SOURCE"  &&
        { error_msg "${B}${SOURCE}${b} does not exist. Might be a typo.\n"  &&  exit 1;}

    ## This test is to see what action is needed, based on the return code:
    test_iso "$SOURCE"
    case $? in
        0)  #<--- We're dealing with a valid iso (either an image or block device)
            ## Sanity check
            test $(egrep '(AUDIO|VIDEO)_TS' <<<"$(isoinfo -p -i $SOURCE)" | wc -l) -ne 2  &&
                { error_msg "The ISO, ${B}${SOURCE##*/}${b}, does not contain a valid video directory structure.  You will need to make another one.  Make sure there is both a ${B}VIDEO_TS${b} and an ${B}AUDIO_TS${b} subdirectory present.\n"  &&  exit 1;}

            ## If the source is a block device (not an iso image) and more
            ## than one burn is requested, then create a temorary image.
            ## This will reduce the overall time it takes to produce the
            ## finished videos:
            if [ -b $SOURCE -a $NUM -gt 1 ];then
                tmp_iso $SOURCE  &&  eject $SOURCE 2>/dev/null  ||
                { echo -n "If you wish to continue, the copying will be done directly from drive to drive (on-the-fly).  However, the time to create the new discs will be much longer for each disc.  Do you wish to continue? [Y|n] " | fold
                  ## A 20-second timeout should be plenty of time to answer
                  read -t20
                  ## If reply equal "n[o]", abort:
                  [[ "$REPLY" =~ "^[nN][oO]?$" ]]  &&  echo "===> Aborting\n"  &&  exit 0;}
            fi;  unset REPLY
            SRCSIZE="$(find_size $SOURCE)"

            ## See if we have enough room to burn a 4.7G DVD:
            if [ $SRCSIZE -ge 4700000000 ]; then
                warn_msg "The source is too big to fit on a 4.7G DVD.  You will need a 'double-layer' disc, and a DVD writer that supports burning double-layered discs.  Do you wish to continue? [N|y] " | fold  &&  read -t20
                ## Reply must equal "y[es]", or abort:
                [[ "$REPLY" =~ "^[yY]([eE][sS])?$" ]]  ||  echo "===> Aborting\n"  &&  exit 0
            fi

            ## Looping for the number of discs to burn
            for ((INT=1 ; INT<=NUM ; INT++))
            do
                echo "${B}---> Starting disc $INT of ${NUM}:${b}"
                ## Feature - Insert blank disc before burning
                test_iso $DEV
                test $? -ne 22  &&
                    { eject $DEV 2>/dev/null
                      read -p "Place blank DVD in tray and press <Enter> to continue...";}

                ## Burn, baby, burn.....Or holler a warning if something goes wrong:
                growisofs -Z $DEV="$SOURCE"  ||
                    { warn_msg "Problem burning ISO image to disk. :-(\n"  &&  continue;}

                ## Sanity checks
                test_iso $DEV
                if [ $? -ne 0 ];then
                    warn_msg "This newly created disc is not a valid ISO 9660 formatted disc.  You will need to burn another one. :-("
                else
                    test $(find_size $DEV) -ne $SRCSIZE  &&
                        { warn_msg "This newly created disc is not the same size as the source.  You will need to burn another one. :-(";}
                fi
            done
        ;;
        1)  #<--- Probably an ordinary file, or corrupt image file
            error_msg "${B}${SOURCE}${b} is not an ISO 9660 formatted file.\n"  &&  exit 1
        ;;
        2)  #<--- File or device doesn't exist
            error_msg "No such file or device\n --> ${B}${SOURCE}${b} <--\n"  &&  exit 2
        ;;
        13) #<--- Not enough permissions
            error_msg "Not enough permissions to read ${B}${SOURCE}${b}.  Either fix the permissions problem, or run this script as root.\n"  &&  exit 13
        ;;
        21) #<--- We're dealing with a directory
            ## Sanity check
            test ! -d "${SOURCE}/VIDEO_TS" -o ! -d "${SOURCE}/AUDIO_TS"  &&
                { error_msg "The directory structure is incorrect for a video DVD.  There must be a ${B}VIDEO_TS${b} /AND/ ${B}AUDIO_TS${b} subdirectory present.  Also, make sure you supplied the correct path on the command line.\n"  &&  exit 1;}

            ## Extra growisofs options for burning from a directory tree
            ## and not an image:
            OPTS="-Z $DEV \
                  -dvd-video \
                  -volid '${SOURCE##*/}' \
                  -sysid '' \
                  -appid '' \
                  -preparer '' \
                  '$SOURCE'"

            ## Looping for the number of discs to burn
            for ((INT=1 ; INT<=NUM ; INT++))
            do
                echo "${B}---> Starting disc $INT of ${NUM}:${b}"
                ## Feature - Insert blank disc before burning
                test_iso $DEV
                test $? -ne 22  &&
                    { eject $DEV 2>/dev/null
                      read -p "Place blank DVD in tray and press <Enter> to continue...";}

                ## Burn, baby, burn.....Or holler a warning if something goes wrong:
                growisofs $OPTS  ||
                    { warn_msg "Problem burning ISO image to disk. :-(\n"  &&  continue;}

                ## Sanity check
                test_iso $DEV
                test $? -ne 0  &&
                    { warn_msg "This newly created disc is not a valid ISO 9660 formatted disc.  You will need to burn another one. :-(";}
            done
        ;;
        30) #<--- Either no DVD in tray or a corrupt DVD
             error_msg "Cannot read ${B}${SOURCE}${b}.  Make sure there's a DVD in the tray.\n"
             exit 30
        ;;
    esac

    ## Cleanup
    test "$IMAGE"  &&  rm -f "$VIDTMP/$IMAGE"

    echo "...Done"
}

## 'ripvideo' program converted to a function.  Usage: rip_video "$@"
rip_video(){
    ## Check for the existence of a DVD drive:
    find_dev "${READDVD[*]}"  ||
        { error_msg "No DVD drive found.\n"  &&  exit 1;}

    ## See if we have 'dvdbackup'.  If not, say so and bail.
    ## NOTE:  Dvdbackup requires 'libdvdread'.  If you want to rip encrypted
    ## DVDs, such as retail ones, you will need to have 'libdvdcss'
    ## installed as well.
    which dvdbackup >/dev/null 2>&1  ||
        { error_msg "Cannot find 'dvdbackup', which is needed for ripping DVDs.\n"
          exit 1;}
    whereis libdvdcss | grep -q 'libdvdcss:$'  &&
        { warn_msg "Cannot find 'libdvdcss'.  This is required only for backing up encrypted DVDs, such as retail movie discs."
          read -t20 -p "Do you wish to continue? [Y|n]"
          [[ "$REPLY" =~ "^[nN][oO]?$" ]]  &&  echo "===> Aborting\n"  &&  exit 0;}
        unset REPLY

    ## Sanity check
    test -d "$1"  &&  DEST=${1%/}  ||  ## If destination isn't a directory, bail
        { error_msg "${B}${1}${b} is not a valid directory. Aborting operation.\n" >&2
          exit 1;}
    test "$DEST" == "."  &&  DEST=$(pwd)

    ## This test is to see what action is needed, based on the return code:
    test_iso "$DEV"
    case $? in
        0)  #<--- We're dealing with a valid iso (an image or block device)
            ## Instead of making multiple calls to 'isoinfo', make one call
            ## and save results.
            ISOINFO="$(isoinfo -d -i $DEV 2>/dev/null)"

            ## Now we'll start weeding out the desired info we saved:
             # For LABEL, we'll ask if the current one found is okay:
            LABEL="$(sed -n 's/Volume id: (.+)/\1/p' <<<"$ISOINFO" | toUpper)"
            LABEL="${LABEL//[^[:alnum:]]/_}"
            read -t20 -p "
Enter a name of your choosing for the video, or simply hit <Enter> to use the default [$LABEL]: "
            test "$REPLY"  &&  LABEL="$(toUpper <<<"${REPLY//[^[:alnum:]]/_}")"
            unset REPLY

             # The rest of the info we'll be needing for later:
            SYSID="$(sed -n 's/System id: (.+)/\1/p' <<<"$ISOINFO")"
            VOLSETID="$(sed -n 's/Volume set id: (.+)/\1/p' <<<"$ISOINFO")"
            PUBLISHER="$(sed -n 's/Publisher id: (.+)/\1/p' <<<"$ISOINFO")"
            COPYRIGHT="$(sed -n 's/Copyright File id: (.+)/\1/p' <<<"$ISOINFO")"
            BIBLIO="$(sed -n 's/Bibliographic File id: (.+)/\1/p' <<<"$ISOINFO")"
            VOLSETSIZE="$(sed -n 's/Volume set size is: (.+)/\1/p' <<<"$ISOINFO")"
            VOLSETSEQ="$(sed -n 's/Volume set sequence number is: (.+)/\1/p' <<<"$ISOINFO")"

            if [ "$LABEL" ];then  ## If we have a name, then it's a go
                ## Sanity check to make sure we don't overwrite an existing backup tree:
                if [ ! -d "$DEST/$LABEL/VIDEO_TS" ];then
                    echo "\n===> Backing up directory structure..."
                    ## Let 'er rip.  If somethng bad happens in the process, bail
                    dvdbackup -M -i $DEV -o "$DEST" -n $LABEL  ||
                        { RETVAL= $?  &&  echo "Aborting operation."  &&  exit $RETVAL;}
                else  ## Found an existing 'VIDEO_TS' directory
                    error_msg "${B}$DEST/$LABEL/VIDEO_TS${b} already exists and will not be overwritten.  Choose another destination, or remove ${B}$DEST/$LABEL/VIDEO_TS${b} to continue.\n"  &&  exit 1
                fi
                ## Make an 'AUDIO_TS' directory for backward compatibility
                ## on old DVD players.  Even if there was one on the
                ## original disc, dvdbackup doesn't bother with it, probably
                ## because it's always empty, nowadays.
                mkdir -p "$DEST/$LABEL/AUDIO_TS"  ||  exit $?
            else  ## If no name, bail
                error_msg "No name for ISO. Aborting operation.\n"  &&  exit 1
            fi

            ## For some retail DVDs, there might be extra stuff in it, so we
            ## might as well copy them, too:
            MOUNT=$(mk_temp)  &&  mkdir $MOUNT
            mount $DEV $MOUNT -t udf -o ro
            ( cd $MOUNT
              ls -A | egrep -iv 'video_ts|audio_ts' | while read
              do
                  test ! -f $DEST/$LABEL/$REPLY  &&  cp -R $REPLY $DEST/$LABEL
              done )
            sync && umount $MOUNT  &&  rmdir $MOUNT

             # Make sure filenames are uppercase:
            find $DEST/$LABEL | sort -r | while read
            do
                NEW="$(toUpper <<<${REPLY##*/})"
                test "${REPLY%/*}/$NEW" != "$REPLY"  &&  mv $REPLY ${REPLY%/*}/$NEW
            done

            ## Now we'll create an iso image of the backup for storage,
            ## using the info from the original disc:
            echo "\n===> Creating DVD image..."
            mkisofs -dvd-video \
                    -volid "$LABEL" \
                    -sysid "$SYSID" \
                    -appid "" \
                    -publisher "$PUBLISHER" \
                    -copyright "$COPYRIGHT" \
                    -biblio "$BIBLIO" \
                    -volset "$VOLSETID" \
                    -volset-size "$VOLSETSIZE" \
                    -volset-seqno "$VOLSETSEQ"\
                    -preparer "" \
                    -o "$DEST/$LABEL.dvd" \
                    "$DEST/$LABEL"  ||
                { RETVAL=$?  &&  echo "Aborting operation."  &&  exit $RETVAL;}

            ## Let's make sure we have a good image (more sanity checks)
            test_iso $DEST/$LABEL.dvd
            if [ $? -ne 0 ];then  ## If not good, bail
                { error_msg "The image, ${B}$LABEL.dvd${b}, is not a valid ISO 9660 image.  You will need to start over."  &&  exit 1;}
            else  ## If good, recheck for proper video structure
                ## This test may seem redundant and unnecessary, but I've
                ## acually burned a batch of DVDs with an incorect video
                ## tree in the image  :-\
                test $(egrep '(AUDIO|VIDEO)_TS' <<<"$(isoinfo -p -i $DEST/$LABEL.dvd)" |
                         wc -l) -ne 2  &&
                    { error_msg "The ISO, ${B}$LABEL.dvd${b}, does not contain a valid video directory structure.  You will need to make another one.  Make sure there is both a ${B}VIDEO_TS${b} and an ${B}AUDIO_TS${b} subdirectory present.\n"  &&  exit 1;}
            fi

            ## Another redundant sanity check before cleaning up  :-\
            test "$DEST/$LABEL" != "$DEST/"  &&   rm -rf "$DEST/$LABEL"

            ## Whew! Made it all the way....... :-D
            echo "\n===> Done. Saved DVD iso as: ${B}$DEST/$LABEL.dvd${b}\n"
        ;;
        1)  #<--- Probably an ordinary file, or corrupt image file
            error_msg "The disc in ${B}${DEV}${b} is not an ISO 9660 formatted disc.\n"
            exit 1
        ;;
        13) #<--- Not enough permissions
            error_msg "Not enough permissions to read ${B}${DEV}${b}.  Either fix the permissions problem, or run this script as root.\n"  &&  exit 13
        ;;
        22) #<--- An unformatted (blank) disc
            error_msg "The disc in ${B}${DEV}${b} is a blank disc.\n"
            exit 22
        ;;
        30) #<--- Either no DVD in tray or a corrupt DVD
            error_msg "Cannot read ${B}${DEV}${b}.  Make sure there's a DVD in the tray.\n"
            exit 30
        ;;
    esac
}

##################
#####  MAIN  #####
##################
test -z "$1"  &&
    { error_msg "No arguments given on command line."
      print_usage >&2  &&  exit 1;}

## checking for required 'mkisofs' program
which mkisofs >/dev/null 2>&1  ||
    { error_msg "Cannot find 'mkisofs'.\n"  &&  exit 1;}

case $PROG in  # How were we called?
    burnvideo)  burn_video "$@"
    ;;
    ripvideo)   rip_video "$@"
    ;;
    *)  ## Making sure the script hasn't been renamed accidently... ^_^
        echo "\n===> ERROR: This program has been renamed.  The proper name for this program is 'burnvideo', along with a symlink (in the same directory) pointing to it called 'ripvideo'.\n" | fold >&2
        exit 1
    ;;
esac

eject $DEV 2>/dev/null

exit 0


Enjoy :D
---thegeekster


Last edited by thegeekster on Fri Sep 29, 2006 10:52 pm, edited 8 times in total.

Top
 Profile  
 PostPosted: Sat Sep 16, 2006 12:29 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
---> UPDATE <---

I made some changes to the script....

One is to separate the programs from the case statement in the MAIN section of the script and put them into their own functions.......This is to make it easier to determine where one program ends and the other begins, not only for you but for me too... :wink:

Two is adding more comments.......I almost forgot to credit Steve Litt for the 'raw_read' function, which is based on his 'rawread' script at Coasterless CD Burning :!: .........plus more explanations at the top of the script, and some clarification on usage for a few functions.......

The verbose commenting I added just before posting this script to help others follow along with the coding, so I forgot to add here and there.......It only had enough comments for me to remember why I did what I did, and that was all..... :wink:

---thegeekster


Last edited by thegeekster on Tue Sep 26, 2006 2:28 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Sat Sep 16, 2006 1:15 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
I was wondering if this would work on bought dvd's. Have you checked it on say Sony DVD movies? I have been having the hardest time copying my sony dvd's. I am currently backing up all my dvd's, especially the kids' movies. Right now I don't have anything that will copy sony DVD's :x


Top
 Profile YIM  
 PostPosted: Sat Sep 16, 2006 1:33 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
coastie wrote:
I was wondering if this would work on bought dvd's. Have you checked it on say Sony DVD movies? I have been having the hardest time copying my sony dvd's. I am currently backing up all my dvd's, especially the kids' movies. Right now I don't have anything that will copy sony DVD's :x

It will work on most retail DVD movies from the store, but not all.

The ones I noticed that won't read are usually disney movies.......I'm pretty sure they use their own encryption scheme, as 'dvdbackup' chokes, and raw ripping chokes, with I/O errors..........The only way around that would be to have a DVD drive that allows raw reading, bit by bit, without checking for whatever checks are made to report I/O errors.....

I did make the script to make backups of movie DVDs I own, to be able to store the originals so they won't get damaged through (ab)use........ :lol:

For those retail DVDs, they're all double-layer discs, typically holding from 7-8 gigs per disc.......I have a burner that can handle double-layer discs, which allows me to copy them whole without having to strip out anything to make it fit on a normal DVD.........The only difference on those copies are they won't be encrypted anymore since they get unencrypted during the backup process....... :)


Top
 Profile  
 PostPosted: Sat Sep 16, 2006 2:25 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
---> UPDATE <---

Oops.............Notice another minor detail that was taken care of.......

For the two 'growisofs' lines, added a 'continue' command for the error warning.....This only means you'll get one waring, and not two.

So now, they look like this:
Code:
...blah-blah...

                ## Burn, baby, burn.....Or holler a warning if something goes wrong:
                growisofs -Z $DEV="$SOURCE"  ||
                    { warn_msg "Problem burning ISO image to disk. :-(\n"  &&  continue;}

...blah-blah...

                ## Burn, baby, burn.....Or holler a warning if something goes wrong:
                growisofs $OPTS  ||
                    { warn_msg "Problem burning ISO image to disk. :-(\n"  &&  continue;}

...blah-blah...




PS: This should be the last code fix.......**famous last words** :lol:


Last edited by thegeekster on Tue Sep 26, 2006 2:28 pm, edited 1 time in total.

Top
 Profile  
 PostPosted: Mon Sep 25, 2006 7:56 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
I'm getting ready to try this, but i had a quick question for you. Did you put that change in your script above? I'm lazy, but I'm on vacation, so I'm allowed to be :D


Top
 Profile YIM  
 PostPosted: Mon Sep 25, 2006 9:59 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Short answer: Yes

Long answer: Whenever I announce any changes, I will post what has been changed.....AND.....make the changes in the original post.... :-)

That way, anyone who comes along and makes a copy will have the latest changes, without having to hunt through the entire thread for the latest update.........But I should probably say so in the original post so someone else doesn't have to ask the same question..... ;-)


Top
 Profile  
 PostPosted: Mon Sep 25, 2006 10:10 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
Oh ya, there will be another change in the making which should make it easier to copy ANY encrypted discs.........Which means it should be an exact copy, bit for bit, including the encryption........

I just haven't been able to do any testing, yet........But that will have to wait as I finish up recovering everything from a failing disk..........It's started to make the infamous "click-of-death" noise, and has choked a few times, causing a little data corruption (of course.......it's the disk with my main OS on it :roll: )........I've been having to browse around using a live cd (BackTrack) until I get everything situated........


Top
 Profile  
 PostPosted: Tue Sep 26, 2006 6:14 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
I know how that is :( I once had to use a live disk for like 6 months.


Top
 Profile YIM  
 PostPosted: Tue Sep 26, 2006 2:24 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
6 months?..........Ouch

Fortunately (if you can call it that) I've had plenty of practice recovering from disaster..............usually of my own doing :wink:


Top
 Profile  
 PostPosted: Tue Sep 26, 2006 4:35 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
ok I tried to run it but got some errors. :o . What arguments would i use if i just wanted it to create an .iso of the movie itself? Is that an option :? , or does it do all the contents of the disk?


Top
 Profile YIM  
 PostPosted: Tue Sep 26, 2006 10:57 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
It only copies the entire disk, so you'll need a double-layer DVD to burn retail movies........Sorry about that, but I like to copy the entire contents of the disc (with all the extras) and I have a burner that can handle double-layer discs.....

You'll need something like DVDShrink for Linux........... :-(

Wait a minute...........After a quick look around, I came across this app: K9Copy.........This seems to be equivalent to DVDShrink in that it compresses (shrinks) the retail double-layer DVD (DVD9) to fit on a standard 4.7G DVD (DVD5).........Hmmm, I'm going to have to check it out when I get up and running..........One caveat is it's a KDE app (lucky for me :-D ).......Also requires DVDAuthor, libdvdread, growisofs, and vamps (for compression)........

Also, check out the Vamps homepage..............seems they have a Qt based app, called qVamps, which (at first glance) seems to provide similar functionality as K9Copy, but has different dependencies (except DVDAuthor is also required).........

:)
---thegeekster


Top
 Profile  
 PostPosted: Fri Sep 29, 2006 10:18 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
--> UPDATE <---

Well, folks, it's *famous last words* time..........I just remembered about another "little" thing in the script :roll: .......

In the ripvideo function, I forgot about the part where I temorarily mount the DVD to copy any other goodies that may be present in the DVD (usually found in a few retail movie DVDs)..........The temp mountpoint I used is /mnt, which might cause some problems for those of you who have their devices mounted in a subdirectory there.........

This is because of the current FHS standard which recommends using /mnt just for a temporary mountpoint (traditional 'old school' practice), and to use /media for other types of media. like '/media/cdrom', '/media/floppy', etc.........

I been doing it this way for so long, I forget that not all distros are 'FHS compliant' in that regard........So, until everyone is on the same page, I've moved that temp mountpoint to /tmp/ripvid.XXXXXX, which will be created, used, and removed.......

The change includes adding a random generator function for creating the temp name, as follows:
Code:

...blah-blah...

## Random generator function, called from the ripvideo() function. (Some of you
## might recognize this as a variation of "gen_pass()" from my version of a
## random password generator <http://bashscripts.org/viewtopic.php?p=808#808> ;-) )
mk_temp(){  ##  Usage:  VAR=$(mk_temp)
    local RNDDEV
    test -c /dev/urandom  &&  RNDDEV=/dev/urandom  ||  RNDDEV=/dev/random
    echo /tmp/ripvid.$(LC_ALL=C tr -dc "[:alnum:]" <$RNDDEV | head -c 6)
}

...blah-blah...

            ## For some retail DVDs, there might be extra stuff in it, so we
            ## might as well copy them, too:
            MOUNT=$(mk_temp)  &&  mkdir $MOUNT
            mount $DEV $MOUNT -t udf -o ro
            ( cd $MOUNT
              ls -A | egrep -iv 'video_ts|audio_ts' | while read
              do
                  test ! -f $DEST/$LABEL/$REPLY  &&  cp -R $REPLY $DEST/$LABEL
              done )
            sync && umount $MOUNT  &&  rmdir $MOUNT

...blah-blah...


Sorry about the inconvenience........... :-(

---thegeekster


Top
 Profile  
 PostPosted: Tue Dec 12, 2006 5:08 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
coastie wrote:
I was wondering if this would work on bought dvd's. Have you checked it on say Sony DVD movies? I have been having the hardest time copying my sony dvd's. I am currently backing up all my dvd's, especially the kids' movies. Right now I don't have anything that will copy sony DVD's :x
Well, I just found out when doing some research on editing video DVDs, there are newer, stronger copy protections out, called ARccOS and RipGuard DVD, used by Sony, Disney and others which basically are affiliated with these two........ :-(

So, there's some good news and bad about these copy protections.........

(1) Good news is.......there are programs out which can handle these newer copy protections....
(2) Bad news is......they are Windows programs, meaning they're GUI apps and not scriptable....
(3) Good news is......they've been recently upgraded to work in Linux using WINE, or have an actual Linux executable......
(4) Bad news is.......some are made to work with other Windows programs.....

The ones I've come across worth mentioning, so far, are:
    RipIt4Me - uses DVD Decrypter as a ripping engine and FixVTS to clean the ripped files.........DVD Decrypter rips the VOBs and related files to disk (which can also be accomplished with vobcopy or dvdbackup) and FixVTS makes the necessary adjustments to overcome the copy protection.....Requirements: Windows 9x, Me, 2000, 2003, XP, Linux under Wine........This seems to be a highly rated app in all the DVD video forums.....Caveat lector: DVD Decrypter is no longer being maintained, but the latest version runs fine in Linux using WINE with a little tweaking

    FixVTS - A single, standalone Windows executable that does not require any installing, and the current version (v1.602) was modified to run under WINE.......Requires the VOBs to already be copied to the hard disk, although it might be possible to simply mount the DVD and let FixVTS work on the VOBs from there......For this procedure to work, you will need to have FixVTS work in backup mode rather than directly on the source VOBs.........

    PgcEdit - "The Swiss Army knife of DVD editing", according to the home page. "PgcEdit is a DVD IFO and Menu editor designed to allow the modification of the navigation commands and parameters of an already authored DVD structure.
    "PgcEdit is also an excellent tool to learn how a DVD works, with his powerful Trace function.
    "Since v0.6.0, PgcEdit is also the first program able to burn a Double Layer DVD-Video on DL DVD+R or DL DVD-R, with an interactive interface (including a preview), to select the position of the layer break."........This is a Tcl/Tk app, but there's a standalone Linux binary at the site which already has the interpreter built in (probably a Starpack, but not sure)..........Or you can compile it yourself, in Linux, if you have Tcl/Tk already installed.........

There're are probably others out there, all for the Windows platform, most likely, and/or cost lot's of money, but these are ones that get mentioned more frequently in a few of the video help forums on the web.........I've yet to come across any Linux commandline apps that can handle these newer copy protection schemes.......But I'll give these a try and let you know the outcome.............

Only thing I don't like is they're all GUI apps, and I am looking for something that is scriptable :-( (PgcEdit looks the most promising for scripting, just need to brush up on my Tcl)..........But I'm going to keep my eyes open for a Linux command line version.......... ;-)


In the meantime, I will be updating my script to make it more "generic" rather than specific for my setup..........I just haven't had the time to work on it as I would like, lately.........Also, I will need to rip out the portion dealing with retail DVDs in my script, until I can find something suitable to replace it with..........

---thegeekster


Top
 Profile  
 PostPosted: Wed Dec 13, 2006 11:27 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 657
Location: Des Moines, Iowa
------------------------------ TOOLS FOR DVD MANIPULATION ON LINUX ----------------------------------------

RIPPING TOOLS:

Video-DVDRip [also called dvd::rip - GUI to rip and transcode]
http://www.exit1.org/dvdrip/

lxdvdrip [command line rip, author, preview, burn]
http://developer.berlios.de/projects/lxdvdrip
http://openfacts.berlios.de/index-en...title=lxdvdrip

ldvd [DVD backup tool with GUI]
http://ldvd9to5.gff-clan.net/

vobcopy [copies vob files to hard disk]
http://vobcopy.org/projects/c/c.shtml

dvdbackup [rips DVD to harddisk]
http://dvd-create.sourceforge.net/download.shtml
http://dvd-create.sourceforge.net/

kdvdbackup [backing up movie DVD's to hard disk. It uses the libdvdread and libdvdnav library]
http://agmanager.sourceforge.net/

subtitleripper [tools to extract DVD-subtitles]
http://subtitleripper.sourceforge.net/ - home page
http://sourceforge.net/projects/subtitleripper - download

streamdvd [fastbackup to DVD on fly – can handle DVD9 to DVD5]
http://www.badabum.de/streamdvd.html

DVDRipOMatic [translate movie from DVD to XviD format]
http://pingwing.xs4all.nl/view.php/page/DVDRipOMatic

LINUX DVD SHRINKING TOOLS:

Video-DVDRip [also called dvd::rip - GUI to rip and transcode]
http://www.exit1.org/dvdrip/

ldvd [DVD backup tool with GUI]
[I myself never succeeded in getting this working]
http://ldvd9to5.gff-clan.net/

klvemkdvd [front end for lvemkdvd - build DVD file systems from mpeg files]
[It backs up only one user selectable video track, and one user selectable audio stream]
http://lvempeg.sourceforge.net/klvemkdvd.html

dvdshrink [xdvdshrink: BASH and Perl-Gtk2 to create archival copies of DVD content on single-layer writable DVDs]
[It backs up only one user selectable video track, audio stream, and subtitle]
http://dvdshrink.sourceforge.net/ and http://packman.links2linux.org/?action=630 and http://sourceforge.net/project/showf...roup_id=133818

LINUX DVD AUTHORING PROGRAMS:

dvdauthor [generates a DVD movie from a valid mpeg2 stream that should play when you put it in a DVD player]
http://dvdauthor.sourceforge.net/ - home
http://sourceforge.net/projects/dvdauthor

kmediafactory [authoring done by dvdauthor, ffmpeg, ImageMagick]
http://susku.pyhaselka.fi/damu/software/kmediafactory/

qdvdauthor [gui frontend for dvd-author and dvd-slideshow]
http://qdvdauthor.sourceforge.net/

dvd-slideshow [create standard DVD video from a batch of pictures]
http://dvd-slideshow.sourceforge.net/

lxdvdrip [command line rip, author, preview, burn]
http://openfacts.berlios.de/index-en...title=lxdvdrip – home
http://developer.berlios.de/projects/lxdvdrip – download

dvdwizard [wrapper-script automate creation of DVD chapters/menu's. Needs dvdauthor, [No home URL but there is a download for the script]:
http://www.wershofen.de/downloads/dvdwizard.tar.gz

DVDAuthorWizard [create video DVD with multiple titles & menu]
http://pingwing.xs4all.nl/view.php/page/DVDAuthor

lvemkdvd [linux video editor - part of lve package]
http://lvempeg.sourceforge.net/

klvemkdvd [front end for lvemkdvd - build DVD file systems from mpeg files]
http://lvempeg.sourceforge.net/klvemkdvd.html

dvdstyler [frontend for dvdauthor and dvd-slideshow – single movie/single menu]
http://dvdstyler.sourceforge.net/docs-linux.html
http://sourceforge.net/projects/dvdstyler/

varsha [java frontend to dvdauthor, dvd+rw-tools, mkisofs, mjpegtools etc...]
http://varsha.sourceforge.net/ and http://sourceforge.net/projects/varsha

DV Slideshow [creates slideshows from photos, adds music – stores in Sony DV format]
[Not yet released]
http://pingwing.xs4all.nl/view.php/page/DVSlideshow

pgcedit [A DVD IFO and Menu editor designed to allow the modification of the navigation commands and parameters of an already authored DVD structure].
http://home.tiscali.be/debie.roland/pgcedit/
[edited on 28-Aug-2005, after I got the package to run]


Top
 Profile WWW  
 PostPosted: Wed Dec 13, 2006 4:27 pm   

Joined: Wed Sep 06, 2006 12:19 pm
Posts: 54
Location: Covington, WA
I'm familiar with a lot of these apps, but which ones can handle the ARccOS or RipGuard DVD copy protection schemes..........a lot of those apps are frontends for the basic command line apps, and for dealing with copy protection, the only linux app I'm aware of is the libdvdcss library which cannot handle these newer schemes........ :?:

This is why I was looking at the Windows apps, those I mentioned *can* handle those copy protection schemes.........I've yet to find any Linux-based command line apps that will.......PgcEdit is not command line, it's a GUI app.......


Top
 Profile  
 PostPosted: Wed Dec 13, 2006 4:42 pm   

Joined: Mon Dec 11, 2006 3:26 pm
Posts: 18
In windows I use DVD CSS+ RegionFree

It's a middleware program to decrypt before it actually gets to the burning software so basically DVDShrink sees it as Not Encrypted... I've never not ben able to copy a movie since I got this

not really helpful in linux though... unless it will run through wine which given it nature i would doubt but i guess somebody could try


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP