[MPlayer-users] Re: Changing aspect ratio while playing a file

Tony Houghton h at realh.co.uk
Wed Nov 16 22:27:58 CET 2005


In <m3zmo4z70h.fsf at toyland.sauerland.de>, Sebastian Kaps wrote:

> That is correct, but think about it for a second. In order to make a 4:3
> video look correct on a 16:9 screen in 16:9 mode, you have to scale it
> horizontally by a factor of roughly 0.7. If you wouldn't downscale the
> video, it would fill the whole screen.
> But when you do, you lose 30% of the horizontal resolution, because the
> video is no longer 720 pixels wide (PAL), but 504 pixels. The 16:9 mode
> of the TV then stretches these 504 pixels to fit into 720 pixels on the
> actual screen.
> That's nuts, since all 16:9 TVs I know do have a 4:3 mode where 4:3
> videos are displayed in a 4:3 area on the center of the screen (i.e.
> black bars left and right). So you won't lose anything if you leave 4:3
> videos unscaled and switch the TV into 4:3 mode.

That's as long as the TV has enough phosphor to still show all the
detail, but I think you're right to want to do it that way anyway: if
you can tell any difference, the "natural" scaling of the TV should in
theory look better than software scaling.

I've snipped some relevant bits out of a script, so this may not work
correctly. It needs perl for some calculations, so you'd probably be
better off writing the whole thing in perl; I wrote it in sh because it
was for a VDR script. It also relies on the file to play being the first
argument.


#!/bin/bash

# Possible values for WIDESCREEN:
# 0: 4:3 TV
# 1: 16:9 TV, always scale for that
# 2: 16:9 TV, but scale for 4:3 if aspect is below ASPECT_SWITCH
WIDESCREEN=2

# See WIDESCREEN=2 above
ASPECT_SWITCH=1.555

LOGFILE=~/mplayer-log
echo -n "" > "$LOGFILE"

# Shouldn't need to change anything below here

function dbglog ()
{
    echo $* >&2
    echo $* >>"$LOGFILE"
    return;
}

# Need to use perl for FP arithmetic
function perleval ()
{
    perl -e "print $*"
    return;
}

SOURCE="$1"

# Analyse video to be played ($SOURCE)
dbglog "Analysing $SOURCE"
VIDEO_INFO=`$MPLAYER -nolirc -identify -vo null -ao null -frames 0 "$SOURCE" 2>>"$LOGFILE" </dev/null | grep -i -e "^ID_"`
FORMAT=`echo "$VIDEO_INFO" | grep ID_VIDEO_FORMAT | cut -d"=" -f2`
SRC_W=`echo "$VIDEO_INFO" | grep ID_VIDEO_WIDTH | cut -d"=" -f2`
SRC_H=`echo "$VIDEO_INFO" | grep ID_VIDEO_HEIGHT | cut -d"=" -f2`
FPS=`echo "$VIDEO_INFO" | grep ID_VIDEO_FPS | cut -d"=" -f2 | sed -e 's/\.00*$//'`
dbglog "Format $FORMAT, size ${SRC_W}"'*'"${SRC_H} "'@'" $FPS fps"
SRC_ASPECT=`echo "$VIDEO_INFO" | grep ID_VIDEO_ASPECT | cut -d"=" -f2`

ACTUAL_ASPECT=`perleval "$SRC_W / $SRC_H"`
PE=`perleval "$SRC_ASPECT == 0"`
if [ "$PE" == 1 ] ; then
    SRC_ASPECT=$ACTUAL_ASPECT
fi
dbglog "Source aspect ratio ${SRC_ASPECT}, pixel aspect ratio ${ACTUAL_ASPECT}"
PE=`perleval "$SRC_ASPECT < $ASPECT_SWITCH"`
if [ "$WIDESCREEN" == 0 -o \
    \( "$WIDESCREEN" == 2 -a "$PE" == 1 \) ] ; then
    MONITORASPECT=4:3
else
    MONITORASPECT=16:9
fi
dbglog "Using monitoraspect $MONITORASPECT"

exec mplayer -monitoraspect $MONITORASPECT "$@" >> "$LOGFILE" 2>&1 </dev/null

-- 
TH * http://www.realh.co.uk




More information about the MPlayer-users mailing list