From 07ea8451969cbfa0ab0a58250934f438bf055853 Mon Sep 17 00:00:00 2001 From: gpoirier Date: Mon, 12 Sep 2005 16:35:58 +0000 Subject: Adds the script psnr-video.sh to calculate the PSNR between two existing video files. Script by Matthias Wieser < mwieser AH gmx POUM de > Original thread: Date: Aug 25, 2005 1:54 PM Subject: [MEncoder-users] [Script] PSNR between two video files git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@16463 b3059339-0415-0410-9bf9-f77b7e298cf2 --- TOOLS/README | 45 ++++++++++++++++ TOOLS/psnr-video.sh | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100755 TOOLS/psnr-video.sh (limited to 'TOOLS') diff --git a/TOOLS/README b/TOOLS/README index aa10e2f522..b4813b13f4 100644 --- a/TOOLS/README +++ b/TOOLS/README @@ -254,6 +254,51 @@ Note: Requires gnuplot. Comparison is based on file2. Comparison assumes that the frame numbers of both files fit. +psnr-video.sh + +Author: Matthias Wieser + +Description: Calculates the PSNR between two existing video files. + The PSNR is calculated frame by frame. + Prints also the overall PSNR. + The script can be used to: + * compare different softwarescalers (should I use + -sws 1 or -sws 2) ? + * compare different resolutions (is it better to scale + down to 640x360 or to 560x320) + * compare different deinterlacers + * compare different video codecs + * compare video filters (is it better to use -vf hqdn3d + or lavcopts:nr=400) + * [...] + +Usage: psnr-video.sh [] [] [] + + and are the video files for which the PSNR + should be calculated. + [] is the number of frames to process, starting + from frame 1. + [] are additional MPlayer options for + [] are additional MPlayer options for + + A file called psnr.dat will be created with the following + content: + + File;Y;Cb;Cr + 00000001.ppm;34.23;39.54;40.06;35.426 + 00000002.ppm;33.03;38.71;39.26;34.271 + 00000003.ppm;33.45;38.91;39.28;34.655 + 00000004.ppm;32.72;38.69;38.85;33.972 + [...] + 00000247.ppm;35.55;40.84;42.15;36.785 + PSNR:;35.9887 + +Note: This script relies on the the tool "pnmpsnr" for the + frame-by-frame PSNR calculation. + Be aware that psnr-video.sh needs a lot of temporal space + inside /temp/. + + asfinfo Author: Arpi diff --git a/TOOLS/psnr-video.sh b/TOOLS/psnr-video.sh new file mode 100755 index 0000000000..1fdc8c106e --- /dev/null +++ b/TOOLS/psnr-video.sh @@ -0,0 +1,150 @@ +#!/bin/sh +# Helper script to ease comparing two video files +# Copyleft 2001 by Matthias Wieser +# This file comes under GPL, see http://www.gnu.org/copyleft/gpl.html for more +# information on it's licensing. + +TEMPDIR="/tmp/psnr_video" +WORKDIR=`pwd`/ +if [ $# -le 1 ]; then + echo + echo "Usage: `basename $0` [] [] []" + echo + echo " and are the video files for which the PSNR should be calculated." + echo " [] is the number of frames to process, starting from frame 1." + echo " [] are additional MPlayer options for " + echo " [] are additional MPlayer options for " + echo + echo " Be aware that `basename $0` needs a lot of temporal space inside /temp/." + echo + echo "Example:" + echo " ./`basename $0` ./orig.avi ./test.avi 250 \"\" \"-vf pp=ac\"" + echo + + exit 1 +fi + +FILE1=$1 +FILE2=$2 + +LastFrame=-1 +if [ $# -ge 3 ]; then + LastFrame=$3 + echo + echo "Will process $LastFrame frames" +fi + +if [ $# -ge 4 ]; then + FILE1Opts=$4 + echo "Mplayer options for ${FILE1}: $FILE1Opts" +fi + +if [ $# -ge 5 ]; then + FILE2Opts=$5 + echo "Mplayer options for ${FILE2}: $FILE2Opts" +fi + +mkdir -p ${TEMPDIR}/FILE1 +mkdir -p ${TEMPDIR}/FILE2 + +### File 1 +echo +echo "############## $FILE1 #################" + +cd ${TEMPDIR}/FILE1 + +rm *ppm 2> /dev/null +rm *del 2> /dev/null + +if [ $LastFrame -ge 0 ]; then + mplayer $FILE1Opts -frames $LastFrame -nosound -vo pnm ${WORKDIR}$FILE1 >/dev/null +else + mplayer $FILE1Opts -nosound -vo pnm ${WORKDIR}$FILE1 >/dev/null +fi +### File 2 + +echo +echo "############## $FILE2 #################" + +cd ${TEMPDIR}/FILE2 + +rm *ppm 2> /dev/null + +if [ $LastFrame -ge 0 ]; then + mplayer $FILE2Opts -frames $LastFrame -nosound -vo pnm ${WORKDIR}$FILE2 >/dev/null +else + mplayer $FILE2Opts -nosound -vo pnm ${WORKDIR}$FILE2 >/dev/null +fi + + +### PSNR + +echo +echo "############## Calculation PSNR #################" + +if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm|wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm|wc -l` ]] +then + echo +else + 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." + echo +fi + + +cd ${TEMPDIR}/FILE2 +#rm ../psnr.dat +echo "File;Y;Cb;Cr" >../psnr.dat +echo "0" > errorsum.del +i=0 +for FILE in `ls -1 *.ppm` + do + echo $FILE + echo -n "$FILE">>../psnr.dat + echo -n ";">>../psnr.dat + pnmpsnr ../FILE1/$FILE $FILE 2> del.del + grep "Y" del.del | dd bs=1c count=5 skip=29 of=del2.del 2>/dev/null + Y=`cat del2.del` + echo -n "$Y;">>../psnr.dat + grep "Cb" del.del | dd bs=1c count=5 skip=29 of=del2.del 2>/dev/null + CB=`cat del2.del` + echo -n "$CB;">>../psnr.dat + grep "Cr" del.del | dd bs=1c count=5 skip=29 of=del2.del 2>/dev/null + CR=`cat del2.del` + echo -n "$CR;">>../psnr.dat + 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">>../psnr.dat + 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 errorsum.del` + echo `echo "scale=30; $ERROR + $ERRORSUM"|bc -l` > errorsum.del + i=$(($i+1)) + if [[ $i = $LastFrame ]] + then + break + fi +done +ERRORSUM=`cat errorsum.del` +PSNR=`echo "-10*l($ERRORSUM/$i)/l(10)"|bc -l` +echo "PSNR:;$PSNR">>../psnr.dat +cd .. +mv psnr.dat ${WORKDIR} + +if [[ `ls -1 ${TEMPDIR}/FILE1/*ppm|wc -l` = `ls -1 ${TEMPDIR}/FILE2/*ppm|wc -l` ]] +then + echo +else + 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 "Processed the first `ls -1 ${TEMPDIR}/FILE2/*ppm|wc -l` frames." + echo +fi + +cd .. +rm -r ${TEMPDIR} + +echo "Created ${WORKDIR}psnr.dat" +echo + -- cgit v1.2.3