5 # 2003/02/09 Jonas Jermann <jjermann@gmx.net>
7 # Script: Draw PSNR log graphs using gnuplot
15 my $dem_file="psnr.dem";
20 system ("gnuplot $dem_file");
21 system("rm $dem_file $options{file}.[IPB] $options{file}.diff* 2>/dev/null");
28 if ($options{file2
}) {
33 open(LIST_IN
, "$options{file}"); while( <LIST_IN
> ) {
35 @
$NewRow = split(/[ ,]+/, $_);
36 push( @file1_cont, $NewRow );
40 open(LIST_IN2
, "$options{file2}"); while( <LIST_IN2
> ) {
42 @
$NewRow = split(/[ ,]+/, $_);
43 push( @file2_cont, $NewRow );
47 open(LIST_OUT
, ">$options{file}.diff");
48 for($i=0; $i<=$#file2_cont; $i++) {
49 print LIST_OUT
" $file2_cont[$i]->[1],\ ";
50 for($j=2; $j<=7; $j++) {
51 $file2_cont[$i]->[$j] -= $file1_cont[$i]->[$j];
52 print LIST_OUT
" $file2_cont[$i]->[$j],\ ";
54 print LIST_OUT
" $file2_cont[$i]->[8]\n";
57 $options{file
}="$options{file}.diff";
60 if ($options{iframes
}) { system("cat $options{file} | grep I > $options{file}.I"); }
61 if ($options{pframes
}) { system("cat $options{file} | grep P > $options{file}.P"); }
62 if ($options{bframes
}) { system("cat $options{file} | grep B > $options{file}.B"); }
64 open(DEM_FILE
,">$dem_file");
66 print DEM_FILE
"#PSNR Statistics
69 set title \"PSNR Statistics\"
77 if ($options{quant
}) {
78 print DEM_FILE
"# Quantizers
80 if ($options{pframes
}) {
82 \"$options{file}.P\" using 1:2 t \"Quantizer: P frames\" w $options{qs}";
83 if ($options{bframes
} || $options{iframes
}) { print DEM_FILE
",\\"; }
85 if ($options{bframes
}) {
87 \"$options{file}.B\" using 1:2 t \"Quantizer: B frames\" w $options{qs}";
88 if ($options{iframes
}) { print DEM_FILE
",\\"; }
90 if ($options{iframes
}) {
92 \"$options{file}.I\" using 1:2 t \"Quantizer: I frames\" w $options{qs}";
94 if (!($options{pframes
} || $options{bframes
} || $options{iframes
})) {
96 \"$options{file}\" using 1:2 t \"Quantizer\" w $options{qs}";
106 if ($options{size
}) {
107 print DEM_FILE
"# Frame size
109 if ($options{pframes
}) {
111 \"$options{file}.P\" using 1:3 t \"Size: P frames\" w $options{ss}";
112 if ($options{bframes
}||$options{iframes
}) { print DEM_FILE
",\\"; }
114 if ($options{bframes
}) {
116 \"$options{file}.B\" using 1:3 t \"Size: B frames\" w $options{ss}";
117 if ($options{iframes
}) { print DEM_FILE
",\\"; }
119 if ($options{iframes
}) {
121 \"$options{file}.I\" using 1:3 t \"Size: I frames\" w $options{ss}";
123 if (!($options{pframes
}||$options{bframes
}||$options{iframes
})) {
125 \"$options{file}\" using 1:3 t \"Size\" w $options{ss}";
134 if ($options{psnr
}) {
135 print DEM_FILE
"# PSNR
137 if ($options{pframes
}) {
139 \"$options{file}.P\" using (\$1):(\$7) t \"PSNR (All): P frames\" w $options{ps}";
140 if ($options{bframes
}||$options{iframes
}) { print DEM_FILE
",\\"; }
142 if ($options{bframes
}) {
144 \"$options{file}.B\" using (\$1):(\$7) t \"PSNR (All): B frames\" w $options{ps}";
145 if ($options{iframes
}) { print DEM_FILE
",\\"; }
147 if ($options{iframes
}) {
149 \"$options{file}.I\" using (\$1):(\$7) t \"PSNR (All): I frames\" w $options{ps}";
151 if (!($options{pframes
}||$options{bframes
}||$options{iframes
})) {
153 \"$options{file}\" using (\$1):(\$7) t \"PSNR (All)\" w $options{ps}";
157 #\"$options{file}\" using (\$1):(\$4) t \"PSNR (Y)\" w $options{ps} \\
158 #\"$options{file}\" using (\$1):(\$5) t \"PSNR (Cb)\" w $options{ps} \\
159 #\"$options{file}\" using (\$1):(\$6) t \"PSNR (Cr)\" w $options{ps}
177 Usage: plotpsnr.pl [options] 'file'
180 -h, --help Display this help message
181 -quant Display quantizers
184 -iframes Display I frames
185 -pframes Display P frames
186 -bframes Display B frames
187 -aframes Display all frames in different colors
188 -cmp <file2> Compare two files
189 -qs <style> Quantizer style
190 -ss <style> Size style
191 -ps <style> PSNR style
193 Default: -quant -size -psnr -qs "p" -ss "i" -ps "p"
196 Comparison is based on file2.
197 Comparison assumes that the frame numbers of both files fit.
212 "quant" => \
$options{quant
},
213 "size" => \
$options{size
},
214 "psnr" => \
$options{psnr
},
215 "cmp=s" => \
$options{file2
},
216 "iframes" => \
$options{iframes
},
217 "pframes" => \
$options{pframes
},
218 "bframes" => \
$options{bframes
},
219 "aframes" => sub { $options{iframes
} = 1;
220 $options{pframes
} = 1;
221 $options{bframes
} = 1; },
222 "qs=s" => \
$options{qs
},
223 "ss=s" => \
$options{ss
},
224 "ps=s" => \
$options{ps
},
227 if (!($options{quant
}||$options{size
}||$options{psnr
})) {
233 $options{file
}="@ARGV";