2005-09-12 16:35:58 +00:00
|
|
|
#!/bin/sh
|
2005-09-13 11:38:39 +00:00
|
|
|
# Helper script to ease comparing the PSNR between two video files
|
|
|
|
# Copyleft 2005 by Matthias Wieser
|
2005-10-02 18:03:08 +00:00
|
|
|
# Copyleft 2005 by Ivo
|
2005-09-12 16:35:58 +00:00
|
|
|
# This file comes under GPL, see http://www.gnu.org/copyleft/gpl.html for more
|
2005-09-13 11:38:39 +00:00
|
|
|
# information on its licensing.
|
2005-09-12 16:35:58 +00:00
|
|
|
|
2005-10-04 16:04:28 +00:00
|
|
|
warning_frame_number () {
|
2005-10-02 18:03:08 +00:00
|
|
|
echo "Files have differing numbers of frames!"
|
|
|
|
echo "$FILE1 has `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` frames,"
|
|
|
|
echo "$FILE2 has `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` frames."
|
|
|
|
echo "Processing the first `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` frames."
|
2005-10-04 16:04:28 +00:00
|
|
|
}
|
2005-10-02 18:03:08 +00:00
|
|
|
|
|
|
|
|
2005-09-12 16:35:58 +00:00
|
|
|
TEMPDIR="/tmp/psnr_video"
|
2005-10-02 18:03:08 +00:00
|
|
|
WORKDIR=`pwd`
|
2005-10-04 16:04:28 +00:00
|
|
|
OUTFILE=psnr.dat
|
|
|
|
ERRFILE=errorsum.del
|
2005-10-02 18:03:08 +00:00
|
|
|
|
|
|
|
exit=0
|
|
|
|
if [[ `which pnmpsnr 2> /dev/null` = "" ]]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "To use this script you have to install the program \"pnmpsnr\" which is"
|
|
|
|
echo " included in the netpbm package."
|
|
|
|
echo
|
|
|
|
exit=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ `which bc 2> /dev/null` = "" ]]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "To use this script you have to install the GNU command line calculator \"bc\"."
|
|
|
|
echo
|
|
|
|
exit=1
|
|
|
|
fi
|
|
|
|
|
2005-09-12 16:35:58 +00:00
|
|
|
if [ $# -le 1 ]; then
|
|
|
|
echo
|
|
|
|
echo "Usage: `basename $0` <file1> <file2> [<frames>] [<options1>] [<options2>]"
|
|
|
|
echo
|
2005-09-13 11:38:39 +00:00
|
|
|
echo " <file1> and <file2> are the files for which the PSNR should be calculated."
|
2005-09-12 16:35:58 +00:00
|
|
|
echo " [<frames>] is the number of frames to process, starting from frame 1."
|
2005-09-13 11:38:39 +00:00
|
|
|
echo " [<options1>] are additional MPlayer options for <file1>."
|
|
|
|
echo " [<options2>] are additional MPlayer options for <file2>."
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
2005-09-13 11:38:39 +00:00
|
|
|
echo " Be aware that `basename $0` needs a lot of temporary space inside /tmp/."
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
|
|
|
echo "Example:"
|
|
|
|
echo " ./`basename $0` ./orig.avi ./test.avi 250 \"\" \"-vf pp=ac\""
|
|
|
|
echo
|
|
|
|
|
2005-10-02 18:03:08 +00:00
|
|
|
exit=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$exit" -eq 1 ]; then
|
|
|
|
exit 1
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
FILE1=$1
|
|
|
|
FILE2=$2
|
|
|
|
|
|
|
|
LastFrame=-1
|
|
|
|
if [ $# -ge 3 ]; then
|
|
|
|
LastFrame=$3
|
|
|
|
echo
|
2005-09-13 11:38:39 +00:00
|
|
|
echo "Will process $LastFrame frames."
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -ge 4 ]; then
|
2005-09-13 11:38:39 +00:00
|
|
|
FILE1_Options=$4
|
|
|
|
echo "MPlayer options for ${FILE1}: $FILE1_Options"
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -ge 5 ]; then
|
2005-09-13 11:38:39 +00:00
|
|
|
FILE2_Options=$5
|
2005-10-04 16:04:28 +00:00
|
|
|
echo "MPlayer options for ${FILE2}: $FILE2_Options"
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
2005-10-02 18:03:08 +00:00
|
|
|
|
2005-09-12 16:35:58 +00:00
|
|
|
mkdir -p ${TEMPDIR}/FILE1
|
|
|
|
mkdir -p ${TEMPDIR}/FILE2
|
|
|
|
|
|
|
|
### File 1
|
|
|
|
echo
|
|
|
|
echo "############## $FILE1 #################"
|
|
|
|
|
|
|
|
cd ${TEMPDIR}/FILE1
|
|
|
|
|
2005-09-13 11:38:39 +00:00
|
|
|
rm -f *ppm
|
|
|
|
rm -f *del
|
2005-09-12 16:35:58 +00:00
|
|
|
|
|
|
|
if [ $LastFrame -ge 0 ]; then
|
2005-10-04 16:04:28 +00:00
|
|
|
mplayer $FILE1_Options -frames $LastFrame -nosound -vo pnm ${WORKDIR}/$FILE1 > /dev/null
|
2005-09-12 16:35:58 +00:00
|
|
|
else
|
2005-10-02 18:03:08 +00:00
|
|
|
mplayer $FILE1_Options -nosound -vo pnm ${WORKDIR}/$FILE1 > /dev/null
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
2005-10-02 18:03:08 +00:00
|
|
|
### File 2
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
|
|
|
echo "############## $FILE2 #################"
|
|
|
|
|
|
|
|
cd ${TEMPDIR}/FILE2
|
|
|
|
|
2005-10-04 16:04:28 +00:00
|
|
|
rm -f *ppm
|
2005-09-12 16:35:58 +00:00
|
|
|
|
|
|
|
if [ $LastFrame -ge 0 ]; then
|
2005-10-04 16:04:28 +00:00
|
|
|
mplayer $FILE2_Options -frames $LastFrame -nosound -vo pnm ${WORKDIR}/$FILE2 > /dev/null
|
2005-09-12 16:35:58 +00:00
|
|
|
else
|
2005-10-04 16:04:28 +00:00
|
|
|
mplayer $FILE2_Options -nosound -vo pnm ${WORKDIR}/$FILE2 > /dev/null
|
2005-09-12 16:35:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
### PSNR
|
|
|
|
|
|
|
|
echo
|
2005-09-13 11:38:39 +00:00
|
|
|
echo "############## PSNR Calculation #################"
|
2005-09-12 16:35:58 +00:00
|
|
|
|
2005-09-13 11:38:39 +00:00
|
|
|
if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` ]]
|
2005-09-12 16:35:58 +00:00
|
|
|
then
|
2005-10-04 16:04:28 +00:00
|
|
|
echo
|
2005-09-12 16:35:58 +00:00
|
|
|
else
|
2005-10-02 18:03:08 +00:00
|
|
|
warning_frame_number
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
cd ${TEMPDIR}/FILE2
|
2005-10-04 16:04:28 +00:00
|
|
|
#rm ../$OUTFILE
|
|
|
|
echo "File;Y;Cb;Cr" > ../$OUTFILE
|
|
|
|
echo "0" > $ERRFILE
|
2005-09-12 16:35:58 +00:00
|
|
|
i=0
|
|
|
|
for FILE in `ls -1 *.ppm`
|
|
|
|
do
|
|
|
|
echo $FILE
|
2005-10-04 16:04:28 +00:00
|
|
|
echo -n "$FILE" >> ../$OUTFILE
|
|
|
|
echo -n ";" >> ../$OUTFILE
|
2005-10-02 18:03:08 +00:00
|
|
|
|
|
|
|
YCBCR=`pnmpsnr ../FILE1/$FILE $FILE 2>&1 | tail -n 3 | cut -f 3 -d ':' | \
|
|
|
|
( read Y X; read CB X; read CR X; echo "$Y;$CB;$CR;")`
|
2005-10-04 16:04:28 +00:00
|
|
|
Y=`echo $YCBCR | cut -f 1 -d ';'`
|
2005-10-02 18:03:08 +00:00
|
|
|
CB=`echo $YCBCR | cut -f 2 -d ';'`
|
|
|
|
CR=`echo $YCBCR | cut -f 3 -d ';'`
|
2005-10-04 16:04:28 +00:00
|
|
|
echo $YCBCR >> ../$OUTFILE
|
2005-10-02 18:03:08 +00:00
|
|
|
|
2005-10-04 16:04:28 +00:00
|
|
|
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`
|
|
|
|
echo "$ALL" >> ../$OUTFILE
|
|
|
|
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`
|
|
|
|
ERRORSUM=`cat $ERRFILE`
|
|
|
|
echo `echo "scale=30; $ERROR + $ERRORSUM" | bc -l` > $ERRFILE
|
2005-10-02 18:03:08 +00:00
|
|
|
|
|
|
|
i=$(($i+1))
|
2005-09-12 16:35:58 +00:00
|
|
|
if [[ $i = $LastFrame ]]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2005-10-02 18:03:08 +00:00
|
|
|
|
2005-10-04 16:04:28 +00:00
|
|
|
ERRORSUM=`cat $ERRFILE`
|
2005-09-13 11:38:39 +00:00
|
|
|
PSNR=`echo "-10*l($ERRORSUM/$i)/l(10)" | bc -l`
|
2005-10-04 16:04:28 +00:00
|
|
|
echo "PSNR:;$PSNR" >> ../$OUTFILE
|
2005-10-02 18:03:08 +00:00
|
|
|
|
2005-09-12 16:35:58 +00:00
|
|
|
cd ..
|
2005-10-04 16:04:28 +00:00
|
|
|
mv $OUTFILE ${WORKDIR}/
|
2005-09-12 16:35:58 +00:00
|
|
|
|
2005-09-13 11:38:39 +00:00
|
|
|
if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm | wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm | wc -l` ]]
|
2005-09-12 16:35:58 +00:00
|
|
|
then
|
|
|
|
echo
|
|
|
|
else
|
2005-10-02 18:03:08 +00:00
|
|
|
warning_frame_number
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
rm -r ${TEMPDIR}
|
|
|
|
|
2005-10-04 16:04:28 +00:00
|
|
|
echo "Created ${WORKDIR}/$OUTFILE"
|
2005-09-12 16:35:58 +00:00
|
|
|
echo
|
|
|
|
|