Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
4) burn it
dvdrecord speed=2 -dao dev=/dev/scd0 /home/me/tmp-dvd/theimagetoburn.img
5) delete all files used
rm -fr /home/me/tmp-dvd
Now of course I would like to script this, but I'm a scripting newbie. The problem I have is that MOVIE_TITLE is dynamic, i.e. actually is the movie's title. So the shell script should be smart enough to plug in a variable obtained from listing the contents of /home/me/tmp-dvd at stage 1b. At stage 3 it could either be dumb, and present a dialog ("Is this OK?") or smart (and parse the directory listing).
[Incidentally to get dvdbackup working, you need libdvdread.so, which is packaged in libdvdread3-dev.deb, in the debian repositories; it is *not* in libdvdread3.deb, helpfully enough.]
Can some shell scripting wizard step up to the plate? Thanks!
I will take stab at it. Give me a few days. You say your problem is the dynamic movie title. Why not use the -n option and set a generic title for the movie everytime? It is going to be erased afterword, right!
I worked it out with a little prodding in the right direction (awk). Usage notes, required programs, TODOs, etc are in the comments at the top of the script. Please report any bugs, fixes, or improvements to this thread.
Code:
#!/bin/sh
DVDDEV=/dev/dvd
# This script will attempt to backup a DVD to your hard disk and
# prepare it for burning. If the source is less than 4.5GB AND you
# have enough space to create an ISO image in addition to a hard
# disk backup of the DVD, it will create a bit for bit ISO image
# which includes all menus, extras, etc. Otherwise, it will first
# strip the menus, and then if necessary compress the main title,
# and create a valid DVD structure for burning.
# TO DO
# 1) Provide option to split DVD instead of stripping and compression
# 2) Provide option to keep subtitles when stripping extras
# 3) Experiment with burning the bit for bit structure without
# creating the image. Is the ISO creation step necessary?
# USAGE
# dvddup backupdir [imagedir]
# NB that imagedir is only used if the movie if copied bit for bit;
# if it isn't specified, and the image is to be created, it will
# be created in backupdir.
# REQUIRED programs
# streamanalyze, streamdvd -- http://www.badabum.de/streamdvd.html
# mkisofs, isoinfo -- provided in cdrtools package???
# dvdbackup
# dvdauthor
# something to burn with, e.g. k3b
# libdvdread-dev -- needed to compile streamanalyze
# tcprobe (provided with transcode)
analyzetrack() {
awk '/MPEG/ {VPOS=$2}
/Audio/ {if (APOS == "") APOS=$2}
/Factor/ {FACTOR=$3}
END {
printf("FACTOR=%s; APOS=%s; VPOS=%s\n", FACTOR, APOS, VPOS);}'
}
analyzesize() {
awk '/CD:/ || /A:/{DVDSIZE += $3}
END {printf("%d", DVDSIZE)}'
}
analyzeiso() {
awk 'BEGIN{minsize="999999"; minname="none"}
{if ($12 != "." && $12 != ".." && $12 != "VIDEO_TS" &&
$12 > 0 && $10 >0 && minsize>$10)
{minname=$12;minsize=$10}}
END{printf("%s",minname)}'
}
b4b() {
echo ---------------
echo Creating backup
echo ---------------
dvdbackup -M -i${DVDDEV} -o${OUTFILE} -n backup
echo -------------------------------------------------
echo Made backup of dvd at $OUTFILE
echo Now creating image for burning at $IMAGEFILE
echo You may remove the dvd from $DVDDEV if you wish
echo -------------------------------------------------
mkisofs -dvd-video -o ${IMAGEFILE}/burnme.img ${OUTFILE}/backup/
FIRSTFILE=$(isoinfo -i ${IMAGEFILE}/burnme.img -l | analyzeiso)
if [ $FIRSTFILE == "VIDEO_TS.BUP;1" ]
then
echo --------------------------------------------------------
echo An ISO image has been created at $IMAGEFILE
echo You may delete the temporary backup files at $OUTFILE
echo "Burn the burnme.img file to DVD (e.g. using k3b) "
echo "and you're done"
echo --------------------------------------------------------
else
echo -------------------------------------------------------------
echo An ISO image has been created at $IMAGEFILE
echo "However, it doesn't appear to check out using isoinfo -i,"
echo "since the first file in the image is ${FIRSTFILE}; it should"
echo "be named VIDEO_TS.BUP;1. If you feel that this is OK, go "
echo "ahead and burn the image named burnme.img. The temporary"
echo "dvd backup is located at ${OUTFILE}/backup. It might burn"
echo "correctly also."
echo -------------------------------------------------------------
fi
}
shrink() {
echo ----------------------------------------------------------
echo Preparing to shrink
echo Analyzing "(stage 1)"...
TRACK=$(tcprobe -i ${DVDDEV} 2>&1 | grep 'title set' | tail -c 2)
echo Analyzing "(stage 2)"...
eval $(streamanalyze -i ${DVDDEV} -t ${TRACK} 2>&1 | analyzetrack)
echo Ripping "(please go watch a movie or something)"
if [ $FACTOR=="not" ]
then
echo Preparing main title for burning without shrinkage
echo dvdauthor -t -o ${OUTFILE} -f \
"'streamdvd -i ${DVDDEV} -t ${TRACK} -s ${VPOS},${APOS} |'";
echo ------------------------------------------------------------
dvdauthor -t -o $OUTFILE -f \
"streamdvd -i ${DVDDEV} -t ${TRACK} -s ${VPOS},${APOS} |"
else
echo Preparing main title for burning with shrinkage factor $FACTOR
echo dvdauthor -t -o ${OUTFILE} -f \
"'streamdvd -i ${DVDDEV} -t ${TRACK} -s ${VPOS},${APOS} -f ${FACTOR} |'";
echo -----------------------------------------------------------
dvdauthor -t -o ${OUTFILE} -f \
"streamdvd -i ${DVDDEV} -t ${TRACK} -s ${VPOS},${APOS} -f ${FACTOR} |"
fi
echo ----------------------------------------------------
echo Complete structure has been created at $OUTFILE
echo Burn the video_ts and audio_ts folders to a dvd
echo "(e.g. using k3b) and you're done"
echo ----------------------------------------------------
}
############################################################
#-------------------------------START
############################################################
PROG=$(basename $0)
DVDDEV=/dev/dvd
# 1) read in the destination from the command line
if [ -z $1 ]
then
echo "Usage: $PROG outfile [imagefile]" 1>&2
exit 1
else
OUTFILE=$1
# the second parameter (optional) defines where
# to create an image, if appropriate
if [ $# -gt 1 ]
then
IMAGEFILE=$2
else
IMAGEFILE=$OUTFILE
fi
fi
echo Looking at source...
# 2) check the size of the dvd, and the amount of free space in
# the destination
THESIZE=$(tcprobe -i $DVDDEV 2>&1 | analyzesize)
FREESPACE=$(df -k $OUTFILE | awk '(NR > 1) {printf("%d",$4/1000)}')
OUTFILESYSTEM=$(df -k $OUTFILE | awk '(NR > 1) {printf("%s",$1)}')
IMAGEFILESYSTEM=$(df -k $IMAGEFILE | awk '(NR > 1) {printf("%s",$1)}')
if [ $IMAGEFILESYSTEM == $OUTFILESYSTEM ]
then
echo Using same filesystem to generate image
IMAGESIZE=$(expr 2 \* $THESIZE)
IMAGESPACE=$FREESPACE
else
echo Using different filesystem to generate image
IMAGESIZE=$THESIZE
IMAGESPACE=$(df -k $IMAGEFILE | awk '(NR > 1) {printf("%d",$4/1000)}')
fi
# 3.1 If the hard disk doesn't have enough space for our purposes
if [ $FREESPACE -lt 4500 ]
then
echo "Sorry, you don't have enough disk space free at $OUTFILE"
# 3.2 If the DVD size is 0
elif [ $THESIZE -eq 0 ]
then
echo "Can't find movie!"
echo "Perhaps you haven't put a movie in the DVD drive yet?"
# 3.3 If the free space on the hard disk is > 4500 but less than the dvd size
elif [ $FREESPACE -lt $THESIZE ]
then
echo --------------------------------------------------------------
echo $FREESPACE MBs is free. The movie is $THESIZE MBs.
echo "You do not have enough free space to copy the movie bit for bit"
echo "Stripping extras, may need to shrink"
echo --------------------------------------------------------------
shrink
# 3.4 If the dvd size is more than one blank dvd
elif [ $THESIZE -gt 4400 ]
then
echo --------------------------------------------------------------
echo $FREESPACE MBs is free. The movie is $THESIZE MBs.
echo "The movie will not fit on one DVD as is (burnables have less"
echo "capacity.) Stripping extras, may need to shrink."
echo --------------------------------------------------------------
shrink
# 3.5 If the dvd would fit a blank dvd but we don't have space to create an
# image to burn with (XXX: is an image necessary anyway in the b4b method?)
elif [ $IMAGESPACE -lt $IMAGESIZE ]
then
echo -----------------------------------------------------------------
echo $IMAGESPACE MBs is free. However, creating a bit for bit image
echo would require $IMAGESIZE MBs. Try specifying a folder on an
echo "alternate partition for the image if you'd prefer a bit for bit"
echo copy. Stripping extras, may need to shrink movie.
echo -----------------------------------------------------------------
shrink
# 3.6 Otherwise do a bit for bit copy
else
echo ----------------------------------------------------
echo $FREESPACE MBs is free. The movie is $THESIZE MBs.
echo Copying movie bit for bit. This will take a while.
echo ----------------------------------------------------
b4b
fi
echo Done.
Can you explain why you have to strip subtitles while shrinking? Are there any
difficulties preventing you from implementing an option for keeping the subtitles?
I am really tired this night, so I will go to bed now. I'll have a closer look on the script
tomorrow.
Huh, I didn't realize there might be different versions of df floating around. OK, I'll see what I can do.
The issue with subtitles is not mine but the StreamDVD code; while potentially that software supports subpictures, it doesn't yet (in turn SD's author is waiting for the mplex coders to implement it ). I just came across a script this morning which does requantization using transcode, so I'll experiment with that and see whether it works well enough, and includes subtitles.
lxdvdrip supports one subtitle in the ripped title however you can choose only one subtitle per title. It would be nice to be able to have more than one subtitle in the ripped dvds.
Turns out tcprobe isn't accurate for ascertaining the entire size of the DVD; only for the size of the title.
< DVDDEV=/dev/dvd
> DVDDEV=/dev/dvd
> # XXX - generate this from fstab?
> DVDDRIVE=/cdrom1
< THESIZE=$(...
> #All awks on df -k will have to be tailored to your system
> THESIZE=$(df -k $DVDDRIVE | awk '(NR > 1) {printf("%d",$3/1000)}')
Second, here is the requantization script using transcode. It uses more hard disk space that either of the above methods, but may be more complete. The following isn't written by me, but could be useful.
Code:
#!/bin/sh
title=`tcprobe -i /dev/dvd 2>&1 | grep "DVD title" \
| cut -d " " -f 4 | cut -d "/" -f 1`
echo "Detected feature title .. $title"
track=`lsdvd -t 1 -a 2>&1 | egrep -m 1 \
'Language: en - English, Format: ac3.*' \
| cut -d " " -f 2 \
| cut -d "," -f 1`
track=`echo "$track - 1" | bc`
echo "Detected audio track .... $track"
echo ""
echo "Copy with these settings will begin in 10 seconds."
echo "If these values look wrong, cancel now."
sleep 10
echo ""
echo "Copying the main feature to drive.."
mkfifo vid.fifo
mkfifo aud.fifo
tcextract -i aud.fifo -t vob -x ac3 -a $track > ofile.ac3 &
tcextract -i vid.fifo -t vob -x mpeg2 > ofile.m2v &
tccat -i /dev/dvd -T $title,-1 -L | tee aud.fifo vid.fifo > /dev/null &&
echo "Retrieving chapter list from disc.."
tcprobe -i /dev/dvd -T $title -H 10 2>&1 | egrep "\[Chapter ..\] " | \
cut -d " " -f 4 | perl -pi -e 's/\n/,/' | \
perl -pi -e 's/,$//' > chap.list &&
echo "Copying complete, please remove DVD and insert blank disc."
eject /dev/dvd
echo ""
# Calculate the requantization factor
vsize=`ls -l ofile.m2v | awk '{print $5 / 1048576}'`
asize=`ls -l ofile.ac3 | awk '{print $5 / 1048576}'`
req=`echo "1.05 * $vsize / (4400 - $asize)" | bc -ql`
echo Calculated requantization value: $req
if [ `echo "$req > 1.0" | bc` -ne 0 ]; then
echo Performing requantization..
tcrequant -i ofile.m2v -o movie.m2v -f $req
else
echo No requantization required.
mv ofile.m2v movie.m2v
fi
echo "Multiplexing audio and video.."
mplex -f 8 -S 0 -o movie.mpeg movie.m2v ofile.ac3 &&
echo "Creating DVD filesystem.."
mkdir -p dvd/VIDEO_TS &&
dvdauthor -t -a ac3+en -c `cat chap.list` -o dvd movie.mpeg &&
dvdauthor -T -o dvd &&
# Cleanup
rm *.fifo
Obligatory explanation of some things:
- Introductory extraction is tied in with the catting of the vob,
something that was previously a longer two-step process. Downside is,
if the a/v track/title selection was wrong you have to re-read from the
DVD.
- The end with burning and deleting is commented out, as I am still
paranoid things won't work right every time, so I like to do a quick
once-over before I commit to burning and cleaning up files.
- The thorough &&'ing of commands is not there, I don't care.
- `lsdvd` is a program that comes with acidrip or dvd::rip.
The main point is to automate the ripping process as completely as
possible, and this is my step towards that. Questions and comments are
welcome, hope this is useful!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.