My other main reason for doing this was that I wanted a single script DVD making solution. I don't intend to make it anywhere near as functional as nuv2disc. I guess this is specifically tailored to my needs, but I figured I would share it with anyone else who's interested.
So here is the new version. It now has a menu with up to 6 videos. I picked 6 because it fits nicely onto the menu and also six 30 minute shows fit pretty well onto a 4.7GB DVD. Everything is now integrated into the script so there's no need to download any extra files.
This assumes that you have used mythlink to make symbolic links to your nuv files, and that the original nuv files are located in /video directory. I altered mythlink a little so I will also post the slightly altered code for that. I used a lot of actual numbers rather than variables (eg. 720x480 for NTSC, sorry PAL users) but I may fix it a bit later on.
Code:
#!/bin/bash
# Run mythlink to create links to recorded programs
TMPDIR=DVD
ISONAME=$(basename $1 | sed 's/\.nuv/.iso/' | sed 's/\.mpg/.iso/')
DVDSIZE=4700000000
VIDSIZE=0
AUDSIZE=0
#--------------------------------------------------------------------------
doreplex()
{
for file in $*; do
outfile=$(basename $file | sed 's/\.nuv/.mpg/')
vidfile=$(basename $file | sed 's/\.nuv/.m2v/')
audfile=$(basename $file | sed 's/\.nuv/.mp2/')
eaudfile=$(basename $file | sed 's/\.nuv/2.mp2/')
if [ ! -f $vidfile ]; then
echo "Extracting video from $file"
tcextract -i $file -t vob -x mpeg2 > $vidfile
fi
if [ ! -f $audfile ]; then
echo "Extracting audio from $file"
tcextract -i $file -a 0 -x mp3 > $audfile
fi
if [ ! -f $eaudfile ]; then
echo "Re-encoding audio"
ffmpeg -vn -ab 256 -ar 48000 -ac 2 -acodec mp2 -i $audfile -vn -ab 256 -ar 48000 -ac 2 -acodec mp2 $eaudfile
fi
VSIZE=`ls -la | grep $vidfile | awk 'END { print $5 }'`
ASIZE=`ls -la | grep $eaudfile | awk 'END { print $5 }'`
VIDSIZE=$[VIDSIZE+VSIZE]
AUDSIZE=$[AUDSIZE+ASIZE]
done
echo "Total video size: $VIDSIZE"
echo "Total audio size: $AUDSIZE"
if [ $[VIDSIZE+AUDSIZE] -ge $DVDSIZE ]; then
echo "File size too large, resizing videos..."
echo "Calculating resize factor for a $DVDSIZE byte DVD"
reqfactor=$(echo "scale=2; $VIDSIZE/($DVDSIZE-$AUDSIZE)*1.04" | bc)
echo "Resize factor: $reqfactor"
for file in $*; do
outfile=$(basename $file | sed 's/\.nuv/.mpg/')
vidfile=$(basename $file | sed 's/\.nuv/.m2v/')
svidfile=$(basename $file | sed 's/\.nuv/2.m2v/')
audfile=$(basename $file | sed 's/\.nuv/.mp2/')
eaudfile=$(basename $file | sed 's/\.nuv/2.mp2/')
echo "Resizing $vidfile"
tcrequant -i $vidfile -o $svidfile -f $reqfactor
echo "Calculating offset between video and audio"
PTSb=`tcprobe -i $file | grep PTS | awk '{ print $1 }' | sed 's/PTS=//' | sed 's/,//'`
PTSv=`echo $PTSb | awk '{ print $1 }'`
PTSa=`echo $PTSb | awk '{ print $2 }'`
PTSoff=$(echo "scale=4; $PTSv-$PTSa" | bc)s
echo "Offset amount: $PTSoff"
echo "Re-multiplexing video and audio"
mplex -f 8 -O $PTSoff -o $outfile $svidfile $eaudfile
echo "Removing temporary files"
rm -f $vidfile
rm -f $audfile
rm -f $eaudfile
rm -f $svidfile
done
else
echo "File size is OK. No need to resize."
for file in $*; do
outfile=$(basename $file | sed 's/\.nuv/.mpg/')
vidfile=$(basename $file | sed 's/\.nuv/.m2v/')
eaudfile=$(basename $file | sed 's/\.nuv/2.mp2/')
echo "Calculating offset between video and audio"
PTSb=`tcprobe -i $file | grep PTS | awk '{ print $1 }' | sed 's/PTS=//' | sed 's/,//'`
PTSv=`echo $PTSb | awk '{ print $1 }'`
PTSa=`echo $PTSb | awk '{ print $2 }'`
PTSoff=$(echo "scale=4; $PTSv-$PTSa" | bc)s
echo "Offset amount: $PTSoff"
echo "Re-multiplexing video and audio"
mplex -f 8 -O $PTSoff -o $outfile $vidfile $eaudfile
echo "Removing temporary files"
rm -f $vidfile
rm -f $audfile
rm -f $eaudfile
done
fi
}
#--------------------------------------------------------------------------
# Get the list of files generated by replex
getmpglist()
{
for file in $*; do
echo $file | sed 's/\.nuv/.mpg/'
done
}
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# Create the thumbnail images for dvd menu
makemenu()
{
PICLIST=""
WHITELIST=""
REDLIST=""
for file in $*; do
realimg=`ls -la | grep $file | sed 's/.*\/video\//\/video\//' | sed 's/\.nuv/\.nuv\.png/'`
echo "text 7,7 \"$(getname $file)\"" > fname
convert $realimg -fill "#ffffff" -draw '@fname' $file.png
rm -f fname
PICLIST="$PICLIST $file.png"
WHITELIST="$WHITELIST whitemask.png"
REDLIST="$REDLIST redmask.png"
done
# Creating menu images
montage -background transparent -frame 6 -geometry +21+54 $PICLIST menu.png
for pic in $PICLIST; do
rm -f $pic
done
convert -size 720x480 xc:transparent png:- | composite -compose Over -gravity Center menu.png - menu2.png
convert -size 720x480 -density 81x72 xc:black png:menuBG.png
composite -compose Over -gravity Center menu2.png menuBG.png menu3.png
mogrify -depth 8 menu3.png
# Create empty menu audio
dd if=/dev/zero bs=4 count=2000 | lame -b 128 -s 48 /dev/stdin menu.mp3
ffmpeg -vn -ab 128 -ar 48000 -ac 2 -acodec mp2 -i menu.mp3 -vn -ab 128 -ar 48000 -ac 2 -acodec mp3 menu.mp2
# Creating menu mpeg
png2yuv -n 50 -I p -f 29.97 -j menu3.png | mpeg2enc -n n -f 8 -o menu.m2v
mplex -f 8 -o menu.mpg menu.m2v menu.mp2
# Creating menu masks
convert -size 720x480 xc:transparent -density 81x72 png:transparent.png
convert -size 214x240 xc:transparent -density 81x72 -units PixelsPerInch -fill white -draw 'line 20,53 20,188 line 21,54 21,187 line 20,53 195,53 line 21,54 194,54 line 21,187 194,187 line 20,188 195,188 line 194,54 194,187 line 195,53 195,188' whitemask.png
convert -size 214x240 xc:transparent -density 81x72 -units PixelsPerInch -fill red -draw 'line 20,53 20,188 line 21,54 21,187 line 20,53 195,53 line 21,54 194,54 line 21,187 194,187 line 20,188 195,188 line 194,54 194,187 line 195,53 195,188' redmask.png
montage -background transparent -geometry 214x240 $WHITELIST whitemon.png
montage -background transparent -geometry 214x240 $REDLIST redmon.png
convert -size 720x480 xc:transparent png:- | composite -compose Over -gravity Center whitemon.png - white.png
convert -size 720x480 xc:transparent png:- | composite -compose Over -gravity Center redmon.png - red.png
echo "<subpictures><stream><spu force=\"yes\" start=\"00:00:00.00\" image=\"transparent.png\" select=\"white.png\" highlight=\"red.png\" autooutline=\"infer\" outlinewidth=\"6\" autoorder=\"rows\"></spu></stream></subpictures>" > menu.xml
spumux menu.xml < menu.mpg > menu_final.mpg
MPGLIST=$(getmpglist $*)
i=0
for file in $MPGLIST; do
i=$[$i+1]
echo "<button>jump title $i;</button>" >> buttons.xml
echo "<titleset><titles><pgc><post>call vmgm menu 1;</post><vob file=\"$file\" /></pgc></titles></titleset>" >> titles.xml
done
dvdheader="<dvdauthor dest=\"DVD\"><vmgm><menus><pgc>"
dvdfooter="</dvdauthor>"
dvdmiddle="<vob file=\"menu_final.mpg\" pause=\"inf\" /></pgc></menus></vmgm>"
echo $dvdheader >> dvd.xml
cat buttons.xml >> dvd.xml
echo $dvdmiddle >> dvd.xml
cat titles.xml >> dvd.xml
echo $dvdfooter >> dvd.xml
echo "Removing temporary files"
rm -f buttons.xml
rm -f titles.xml
rm -f menu.xml
rm -f menu.png
rm -f menuBG.png
rm -f menu2.png
rm -f menu3.png
rm -f menu.m2v
rm -f menu.mp3
rm -f menu.mp2
rm -f menu.mpg
}
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# Get the proper showname for menu
getname()
{
ls | grep $* | sed 's/[0-9]*_//' | sed 's/\.nuv//' | sed 's/\([^_]*\)\(_\)\([^_]*\)\(_\)\([^_]*\)\(_\)/\1\2\3\4\5\n/g' | sed 's/_/ /g' | sed 's/-/\n/g'
}
#--------------------------------------------------------------------------
doreplex $*
# Create the temporary directory
if [ -d $TMPDIR ]; then
rm -r $TMPDIR
fi
mkdir $TMPDIR
makemenu $*
echo "Creating DVD structure"
dvdauthor -o $TMPDIR -x dvd.xml
echo "Creating ISO"
mkisofs -dvd-video -udf -r -o $ISONAME $TMPDIR
echo "Removing temporary files"
rm -f menu_final.mpg
rm -f dvd.xml
for file in $*; do
outfile=$(basename $file | sed 's/\.nuv/.mpg/')
rm -f $outfile
done
And here's the altered mythlink code:
Code:
#!/bin/sh
# mythlink.sh - Symlinks mythtv files to more readable versions
# by Dale Gass
if [ ! -d /video/tv ]; then mkdir /video/tv; fi
rm -f /video/dvd/*.nuv
echo "Done RM"
mysql -uroot -p mythconverg -B --exec "select chanid,starttime,endtime,title,subtitle from recorded;" >/tmp/mythlink.$$
perl -w -e '
my $mythpath= "/video";
my $altpath= "/video/dvd";
if (!-d $altpath) {
mkdir $altpath or die "Failed to make directory: $altpath\n";
}
<>;
while (<>) {
chomp;
my ($chanid,$start,$end,$title,$subtitle) = split /\t/;
$start =~ s/[^0-9]//g;
$end =~ s/[^0-9]//g;
$subtitle = "" if(!defined $subtitle);
my $ofn = "${chanid}_${start}_${end}.nuv";
do { print "Skipping $mythpath/$ofn\n"; next } unless -e "$mythpath/$ofn";
$start =~ /^....(........)/;
#my $nfn = "$1_${title}_${subtitle}";
my $nfn = "$1_${title}";
if ($subtitle) {$nfn="${nfn}-${subtitle}"}
$nfn =~ s/ /_/g;
$nfn =~ s/&/+/g;
$nfn =~ s/[^+0-9a-zA-Z_-]+/_/g;
$nfn = "${nfn}.nuv";
print "Creating $nfn\n";
unlink "$altpath/$nfn" if(-e "$altpath/$nfn");
symlink "$mythpath/$ofn", "$altpath/$nfn" or die "Failed to create symlink $altpath/$nfn: $!";
}
' /tmp/mythlink.$$
rm /tmp/mythlink.$$