#!/bin/bash # You need transcode, mplayer, and lsdvd for this script. # It will not work on all dvd's. You will need to play with it sometimes. if [ -z "$3" ]; then echo -e "Enter arguments as follows: MovieName FinalsizeMB Device\n"; else FILENAME=$1 ; FINALSIZE=$2 ; DEVICE=$3 ; # NTSC output for the U.S. FRAMERATE="24000/1001"; # Finalsize in kilobytes. FINALKBSIZE=$(($FINALSIZE*1000)) ; # Grab the number of the longest title on the dvd. TITLE=`lsdvd -d /dev/$DEVICE | grep Longest | cut -c 16-17` # Collect information about the dvd, for use in determining # the english track number, and the length of the movie. tcprobe -T $TITLE -i /dev/$DEVICE > tcprobe.tempinfo # Grab the length of the movie and the index of the first english track. # I know this is probably a crappy way to do it...but I'm not a programmer, so there! :p SECONDS=`cat tcprobe.tempinfo | sed -e 's/ /\n/g' | grep -B 1 sec | head -n 1` ; EN_TRACK=`grep kHz tcprobe.tempinfo | grep -n "ac3 en" | head -c1` EN_INDEX=$(($EN_TRACK-1)) ; # The following are used for debugging. # ES_TRACK=`grep kHz tcprobe.tempinfo | grep -n "ac3 es" | head -c1` # EN_INDEX=0 ; # ES_INDEX=$(($ES_TRACK-1)) ; # Calculate the framerate based on desired final size. AUDIOSIZE=$(($SECONDS*24)) ; DIFFERENCE=$(($FINALKBSIZE - $AUDIOSIZE)) ; RATE=$((($DIFFERENCE*8) / $SECONDS)) ; echo -e "Title: $FILENAME" ; echo -e "Longest title is: $TITLE" echo -e "Length: $SECONDS seconds" ; echo -e "Rate is $RATE bps" ; echo -e "English track is: $EN_INDEX $EN_TRACK" # echo -e "Spanish track is: $ES_INDEX $ES_TRACK" echo -e "A $FINALSIZE MB mpeg-2 of $FILENAME is going to be created in 10 sec...." ; sleep 10 ; # These are also used for debugging sometimes... # tccat -i /dev/$DEVICE -T 1,-1 -P > $FILENAME ; # dumpstream.sh $FILENAME $DEVICE mplayer dvd://$TITLE -dvd-device /dev/$DEVICE -dumpstream -dumpfile $FILENAME ; eject $DEVICE ; # Here's the beef. The export_asr 3 is widescreen (16:9) # Get rid of -u 30,3 if you don't have SMP. (not sure it works anyway) nice -+19 transcode -i $FILENAME -y ffmpeg --export_prof dvd-ntsc --export_asr 3 \ -F mpeg2video -o temp -D0 -b224 -N 0x2000 -s2 -u 30,3 -s on,1,1,1 -M 4 \ -m temp.ac3 -J modfps=clonetype=3 --export_fps 29.97 -a $EN_INDEX -w $RATE ; # Joins the video and audio streams. mplex -f8 -o $FILENAME.mpg temp.m2v temp.ac3 ; # I've commented this out because sometimes (1 in 50) the AV sync is bad. # I'll mplex them by hand using something like # this: mplex -f8 -o My_Favorite_Movie.mpg -O -6250ms temp.m2v temp.ac3 # which adds a delay of 6.25 seconds to the final movie. # rm temp.m2v temp.ac3 fi exit