[mythtv-users] Calculating aspect ratios for DVDs

Yan Seiner yan at seiner.com
Thu Jan 7 20:02:14 UTC 2010


On Thu, January 7, 2010 9:45 am, jedi wrote:
> On Thu, Jan 07, 2010 at 09:24:06AM -0800, Yan Seiner wrote:
>>
>> This is slightly OT, but I'm hoping someone can enlighten me.  I'm
>> trying
>> to work out a script that automatically detects the aspect ratio of a
>> cropped DVD.
>>
>> It seems that DVDs report either 1.33:1 aspect or 1.78:1 aspect.  If the
>> movie is 2.33:1, black bars are added top and bottom.  (leaving aside
>> the
>> odd-ball ones for the moment.)
>>
>> So to get the proper aspect, one would have to:
>>
>> Take the DVD size, either 720x480 or 720x576, and figure out the crop
>> box.
>>
>> Take the reported DVD aspect ratio, divide by 1.33, multiply the width
>> of
>> the crop box and divide the result by the height of the crop box.
>>
>> This seems weirdly byzantine and possibly inaccurate.  Is there some
>> simple way to use mplayer, lsdvd, or dvdscan to get this information?
>
> ...it's perfectly reasonable given how the stuff was intended to be used.
>
> You seem to want something that can pull the aspect ratio direct from the
> video itself even accounting for embedded letterboxes. I am not aware of
> anything that does that. It would be somewhat cool if there were such a
> tool. I do this manually for 4:3 content that is letterboxed.

Without further ado, here's the alpha version.  You will need
mplayer/mencoder compiled with libdvdnav support, lsdvd, and dvdscan from
DVDRipOMatic.  It also uses bc.

It should automagically detect frame rates, crop sizes, aspect ratios, etc
for both NTSC and PAL DVDs.  Comments to my email.

===cut here===
#!/bin/sh

DVD=/dev/sr0

TRACKS=`dvdscan -scan-dvd $DVD | grep MainTitle | cut -d= -f2`
TITLE=`lsdvd $DVD | grep 'Disc Title:' | cut -f3 -d\  `

mplayer dvdnav://$TRACKS  -dvd-device $DVD -ss 600 -frames 30 -vf
cropdetect -ao null -vo null > /tmp/encode.out

CROP=`cat /tmp/encode.out | grep crop | tail -n 1 | sed -s
's/^.*=//;s/).*$//'`
LANG=`cat /tmp/encode.out | grep 'audio stream: 0' | tail -n 1 | sed
's/^.*language: //' | sed 's/ aid:.*$//'`
OFPS=`cat /tmp/encode.out | grep VIDEO | awk '{print $6}'`
NRES=`cat /tmp/encode.out | grep VIDEO | awk '{print $3}'`
NRESX=`echo $NRES | cut -f1 -dx`
NRESY=`echo $NRES | cut -f2 -dx`

DFPS=`cat /tmp/encode.out | grep demux_mpg | awk '{print $2}' | sed s/fps//`

if [ "$DFPS" != "" ] ; then
        OFPS=$DFPS
fi

MASPECT=`cat /tmp/encode.out | grep "Movie-Aspect" | sed s/^.*Movie// |
awk '{print $3}' | sed s/:.*$//`

echo TRACKS: $TRACKS
echo TITLE: $TITLE
echo CROP: $CROP
echo LANG: $LANG
echo OFPS: $OFPS

X=`echo $CROP | cut -f1 -d:`
Y=`echo $CROP | cut -f2 -d:`

NASPECT=`echo "scale=4;${MASPECT}*$X/(($NRESX/$NRESY)*$Y)" | bc`

echo NATIVE ASPECT: $NASPECT
AS=`echo "scale=0;${NASPECT}*100" | bc`

if [ $AS -ge 210 ] ; then ASPECT="7/3"
elif [ $AS -ge 150] ; then ASPECT="16/9"
else ASPECT="4/3"
fi

echo ASPECT: $ASPECT

if [[ "$LANG" < "en" ]] ; then
        AVILANG="-alang $LANG -slang en"
else
        AVILANG="-alang en"
fi

echo $AVILANG

if [ $OFPS -lt 25 ] ; then
        VF=pullup,softskip,hqdn3d,crop=$CROP
elif [ $IFPS -lt 26 ] ; then
        VF=pullup,softskip,hqdn3d,crop=$CROP
else
        VF=kerndeint,softskip,hqdn3d,crop=$CROP
fi

echo mencoder dvdnav://$TRACKS  -dvd-device $DVD \
                -vf $VF -ovc lavc -oac mp3lame \
                -lavcopts
vcodec=mpeg4:vpass=1:aspect=$ASPECT:vbitrate=$BITRATE \
                -ofps $OFPS $AVILANG -o  ~/tmp/$TITLE.avi

BITRATE=1800

for TRACK in $TRACKS ; do

        echo TITLE: $TITLE
        echo TRACK: $TRACK
        lsdvd $DVD -t $TRACK -x

        mencoder dvdnav://$TRACK  -dvd-device $DVD \
                -vf $VF -ovc lavc -oac mp3lame \
                -lavcopts
vcodec=mpeg4:vpass=1:aspect=$ASPECT:vbitrate=$BITRATE \
                -ofps $OFPS $AVILANG -o  ~/tmp/$TITLE.avi

        mencoder dvdnav://$TRACK  -dvd-device $DVD \
                -vf $VF -ovc lavc -oac mp3lame \
                -lavcopts
vcodec=mpeg4:vpass=2:aspect=$ASPECT:vbitrate=$BITRATE \
                -ofps $OFPS $AVILANG -o ~/tmp/$TITLE.avi

        done
===cut here===
-- 
If you have eight hours to chop down a tree
spend six sharpening your axe.
--Abraham Lincoln



More information about the mythtv-users mailing list