[Mint 18, 19] Backup DVD to ISO

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
rene
Level 8
Level 8
Posts: 2368
Joined: Sun Mar 27, 2016 6:58 pm

[Mint 18, 19] Backup DVD to ISO

Post by rene » Sun Nov 04, 2018 9:35 am

Although there are many transcoding DVD rippers available and a few non-transcoding ones such as dvdbackup, there seems a somewhat surprising lack of simple tools to just copy a DVD unaltered from its source to an ISO image directly. DVD burner applications such as Brasero can do this but are somewhat overblown.

The below tiny Python script dvdcopy aims to be useful in that sense. It copies the DVD with plain old dd after getting name and size information from isoinfo. Both those as well as the for most commercial movie DVD's necessary libdvdcss2 package are installed by default on both Mint 18.3 and Mint 19; isoinfo is from the genisoimage package if you do not yet have it.

I can not speak to usefulness of this script for Blu-ray; I have discs nor hardware. CSS on DVD is partly drive-based and if this is also the case for the newer systems on Blu-ray then usefulness will depend on libdvdcss2. That is, for all I know Blu-ray may or may not be supported --- although I would assume not.

Save the below as say ~/bin/dvdcopy, make it executable as chmod +x ~/bin/dvdcopy and use dvdcopy -h for a small usage screen. Simply dvdcopy will have it copy /dev/dvd to an after the volume id named iso in the current directory, dvdcopy -i will only show disc information.

Reports of success, failure and/or perceived usefulness welcome...

Code: Select all

#!/usr/bin/env python3
#
# dvdcopy (public domain, 2018)

import argparse
import ctypes
import locale
import subprocess

IBS = 128 * 1024
OBS = 4 * 1024 ** 2


def isoinfo(device):
    def val(tag, line):
        i = line.find(':')
        return '' if i < 0 or line[:i].strip() != tag else line[i + 1:].strip()

    id, bs, vs = '', '', ''
    p = subprocess.run(['isoinfo', '-d', '-i', device], stdout=subprocess.PIPE, universal_newlines=True, check=True)
    for line in p.stdout.splitlines():
        if vs and bs and id:
            break
        if not id:
            id = val('Volume id', line)
            if id:
                continue
        if not bs:
            bs = val('Logical block size is', line)
            if bs:
                continue
        if not vs:
            vs = val('Volume size is', line)
    try:
        bs = int(bs)
        vs = int(vs)
    except ValueError:
        bs = 0
        vs = 0
    return id, bs, vs


locale.setlocale(locale.LC_ALL, '')
parser = argparse.ArgumentParser(description='Backup DVD to ISO.')
group = parser.add_mutually_exclusive_group()
group.add_argument('-c', action='store_true', dest='copy', default=True, help='backup device to iso (default)')
group.add_argument('-i', action='store_false', dest='copy', help='show iso information')
parser.add_argument('-d', dest='device', default='/dev/dvd', help='device (default: /dev/dvd)')
args = parser.parse_args()

id, bs, vs = isoinfo(args.device)
if id and bs and vs:
    size = vs * bs
    i = 0 if size < 1024 ** 2 else 1 if size < 1024 ** 3 else 2
    unit = 'KMG'[i]
    print(locale.format_string('Volume %s, %d bytes (%.1f %cB, %.1f %ciB)',
                               (id, size, size / 1000 ** (i + 1), unit, size / 1024 ** (i + 1), unit)))
    if args.copy:
        libdvdcss = ctypes.CDLL('libdvdcss.so.2')
        libdvdcss.dvdcss_close(libdvdcss.dvdcss_open(args.device.encode()))
        i = IBS // bs
        while vs % i:
             i -= 1
        ibs = bs * i
        obs = OBS // ibs * ibs
        subprocess.run(['dd', 'if=%s' % args.device,
                              'iflag=direct',
                              'ibs=%d' % ibs,
                              'of=%s.iso' % id.lower(),
                              'obs=%d' % obs,
                              'count=%d' % (vs // i),
                              'status=progress'], check = True)

User avatar
all41
Level 13
Level 13
Posts: 4990
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: [Mint 18, 19] Backup DVD to ISO

Post by all41 » Sun Nov 04, 2018 10:39 am

rene wrote:
Sun Nov 04, 2018 9:35 am
I just use k3b to store a dvd image file. Perhaps this will not always be an option
Last edited by all41 on Sun Nov 04, 2018 10:57 am, edited 1 time in total.
Proud to be a supporter and monthly contributor to Mint.

rene
Level 8
Level 8
Posts: 2368
Joined: Sun Mar 27, 2016 6:58 pm

Re: [Mint 18, 19] Backup DVD to ISO

Post by rene » Sun Nov 04, 2018 10:50 am

Yes, sure; mentioned DVD burner applications as alternative possibilities. I'm not completely sure though if those will read at blockdevice or filesystem level and in the latter case just remake the ISO on the fly. Not that that matters much, but the script is by design minimal even if only for educational reasons (which it is not only; I'm using it to satisfaction :-)

Particularly felt educated by it being enough to open and immediately close the disc through libdvdcss2. But sure, feel free to have mileage vary.

User avatar
all41
Level 13
Level 13
Posts: 4990
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: [Mint 18, 19] Backup DVD to ISO

Post by all41 » Sun Nov 04, 2018 11:07 am

Rene,
Edit done.
Your bash instructions have been saved--thanks
Perhaps k3b and others are just gui to this code.
not certain re blocks, but an iso is after all--an iso
Proud to be a supporter and monthly contributor to Mint.

rene
Level 8
Level 8
Posts: 2368
Joined: Sun Mar 27, 2016 6:58 pm

Re: [Mint 18, 19] Backup DVD to ISO

Post by rene » Sun Nov 04, 2018 11:22 am

The script goes out of its way somewhat to use dd rather than a simple read/write loop; I trust k3b will be more sensible than that :-)

And yes, certainly an iso is an iso is an iso. I'm from the audio universe accustomed to being really pedantic about getting verifiably original bits off of a disc though. Makes very significantly less sense for DVD, but still.

Post Reply

Return to “Tutorials”