2 # Helper script to ease comparing the PSNR between two video files
3 # Copyleft 2005 by Matthias Wieser
5 # This file comes under GPL, see http://www.gnu.org/copyleft/gpl.html for more
6 # information on its licensing.
8 warning_frame_number
() {
9 echo "Files have differing numbers of frames!"
10 echo "$FILE1 has `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` frames,"
11 echo "$FILE2 has `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` frames."
12 echo "Processing the first `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` frames."
16 TEMPDIR
="/tmp/psnr_video"
22 if [[ `which pnmpsnr 2> /dev/null` = "" ]]
25 echo "To use this script you have to install the program \"pnmpsnr\" which is"
26 echo " included in the netpbm package."
31 if [[ `which bc 2> /dev/null` = "" ]]
34 echo "To use this script you have to install the GNU command line calculator \"bc\"."
41 echo "Usage: `basename $0` <file1> <file2> [<frames>] [<options1>] [<options2>]"
43 echo " <file1> and <file2> are the files for which the PSNR should be calculated."
44 echo " [<frames>] is the number of frames to process, starting from frame 1."
45 echo " [<options1>] are additional MPlayer options for <file1>."
46 echo " [<options2>] are additional MPlayer options for <file2>."
48 echo " Be aware that `basename $0` needs a lot of temporary space inside /tmp/."
51 echo " ./`basename $0` ./orig.avi ./test.avi 250 \"\" \"-vf pp=ac\""
57 if [ "$exit" -eq 1 ]; then
68 echo "Will process $LastFrame frames."
73 echo "MPlayer options for ${FILE1}: $FILE1_Options"
78 echo "MPlayer options for ${FILE2}: $FILE2_Options"
82 mkdir
-p ${TEMPDIR}/FILE1
83 mkdir
-p ${TEMPDIR}/FILE2
87 echo "############## $FILE1 #################"
94 if [ $LastFrame -ge 0 ]; then
95 mplayer
$FILE1_Options -frames $LastFrame -nosound -vo pnm
${WORKDIR}/$FILE1 > /dev
/null
97 mplayer
$FILE1_Options -nosound -vo pnm
${WORKDIR}/$FILE1 > /dev
/null
102 echo "############## $FILE2 #################"
108 if [ $LastFrame -ge 0 ]; then
109 mplayer
$FILE2_Options -frames $LastFrame -nosound -vo pnm
${WORKDIR}/$FILE2 > /dev
/null
111 mplayer
$FILE2_Options -nosound -vo pnm
${WORKDIR}/$FILE2 > /dev
/null
118 echo "############## PSNR Calculation #################"
120 if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` ]]
131 echo "File;Y;Cb;Cr" > ..
/$OUTFILE
134 for FILE
in `ls -1 *.ppm`
137 echo -n "$FILE" >> ..
/$OUTFILE
138 echo -n ";" >> ..
/$OUTFILE
140 YCBCR
=`pnmpsnr ../FILE1/$FILE $FILE 2>&1 | tail -n 3 | cut -f 3 -d ':' | \
141 ( read Y X; read CB X; read CR X; echo "$Y;$CB;$CR;")`
142 Y
=`echo $YCBCR | cut -f 1 -d ';'`
143 CB
=`echo $YCBCR | cut -f 2 -d ';'`
144 CR
=`echo $YCBCR | cut -f 3 -d ';'`
145 echo $YCBCR >> ..
/$OUTFILE
147 ALL
=`echo "(-10)*l((e(-$Y/10*l(10))+e(-$CB/10*l(10))/4+e(-$CR/10*l(10))/4)/1.5)/l(10)" | bc -l`
148 echo "$ALL" >> ..
/$OUTFILE
149 ERROR
=`echo "scale=30; (e(-1*$Y/10*l(10))+e(-1*$CB/10*l(10))/4+e(-1*$CR/10*l(10))/4)/1.5" | bc -l`
150 ERRORSUM
=`cat $ERRFILE`
151 echo `echo "scale=30; $ERROR + $ERRORSUM" | bc -l` > $ERRFILE
154 if [[ $i = $LastFrame ]]
160 ERRORSUM
=`cat $ERRFILE`
161 PSNR
=`echo "-10*l($ERRORSUM/$i)/l(10)" | bc -l`
162 echo "PSNR:;$PSNR" >> ..
/$OUTFILE
165 mv $OUTFILE ${WORKDIR}/
167 if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` ]]
178 echo "Created ${WORKDIR}/$OUTFILE"