demux_ogg.c: remove unused variable
[mplayer/glamo.git] / TOOLS / plotpsnr.pl
blob8124d317b5217e4981c58f21f51109bdbe84c44c
1 #!/usr/bin/perl
3 # Licence: GPL
5 # 2003/02/09 Jonas Jermann <jjermann@gmx.net>
7 # Script: Draw PSNR log graphs using gnuplot
9 # requires: gnuplot
11 use Getopt::Long;
13 # MAIN
14 my %options;
15 my $dem_file="psnr.dem";
17 commandline();
18 demo_file();
20 system ("gnuplot $dem_file");
21 system("rm $dem_file $options{file}.[IPB] $options{file}.diff* 2>/dev/null");
22 exit 0;
25 # DEMO FILE
26 sub demo_file {
28 if ($options{file2}) {
29 my @file1_cont = ();
30 my @file2_cont = ();
31 my $NewRow,$i,$j;
33 open(LIST_IN, "$options{file}"); while( <LIST_IN> ) {
34 $NewRow=[];
35 @$NewRow = split(/[ ,]+/, $_);
36 push( @file1_cont, $NewRow );
38 close(LIST_IN);
40 open(LIST_IN2, "$options{file2}"); while( <LIST_IN2> ) {
41 $NewRow=[];
42 @$NewRow = split(/[ ,]+/, $_);
43 push( @file2_cont, $NewRow );
45 close(LIST_IN2);
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";
56 close(LIST_OUT);
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
67 #---------------
69 set title \"PSNR Statistics\"
70 set data style fsteps
71 set xlabel \"Frames\"
72 set grid
77 if ($options{quant}) {
78 print DEM_FILE "# Quantizers
79 plot [] [0:] \\";
80 if ($options{pframes}) {
81 print DEM_FILE "
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}) {
86 print DEM_FILE "
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}) {
91 print DEM_FILE "
92 \"$options{file}.I\" using 1:2 t \"Quantizer: I frames\" w $options{qs}";
94 if (!($options{pframes} || $options{bframes} || $options{iframes})) {
95 print DEM_FILE "
96 \"$options{file}\" using 1:2 t \"Quantizer\" w $options{qs}";
99 print DEM_FILE "
100 pause -1
106 if ($options{size}) {
107 print DEM_FILE "# Frame size
108 plot \\";
109 if ($options{pframes}) {
110 print DEM_FILE "
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}) {
115 print DEM_FILE "
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}) {
120 print DEM_FILE "
121 \"$options{file}.I\" using 1:3 t \"Size: I frames\" w $options{ss}";
123 if (!($options{pframes}||$options{bframes}||$options{iframes})) {
124 print DEM_FILE "
125 \"$options{file}\" using 1:3 t \"Size\" w $options{ss}";
128 print DEM_FILE "
129 pause -1
134 if ($options{psnr}) {
135 print DEM_FILE "# PSNR
136 plot \\";
137 if ($options{pframes}) {
138 print DEM_FILE "
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}) {
143 print DEM_FILE "
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}) {
148 print DEM_FILE "
149 \"$options{file}.I\" using (\$1):(\$7) t \"PSNR (All): I frames\" w $options{ps}";
151 if (!($options{pframes}||$options{bframes}||$options{iframes})) {
152 print DEM_FILE "
153 \"$options{file}\" using (\$1):(\$7) t \"PSNR (All)\" w $options{ps}";
156 print DEM_FILE "
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}
160 pause -1
165 print DEM_FILE "
166 reset";
168 close (DEM_FILE);
173 # USAGE
174 sub usage {
175 print STDERR <<EOF;
177 Usage: plotpsnr.pl [options] 'file'
179 Options:
180 -h, --help Display this help message
181 -quant Display quantizers
182 -size Display size
183 -psnr Display PSNR
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"
195 Notes:
196 Comparison is based on file2.
197 Comparison assumes that the frame numbers of both files fit.
200 exit 1;
204 # COMMAND LINE
205 sub commandline {
206 $options{qs}="p";
207 $options{ss}="i";
208 $options{ps}="p";
210 GetOptions(
211 "help|h" => \&usage,
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},
225 ) || usage();
227 if (!($options{quant}||$options{size}||$options{psnr})) {
228 $options{quant}=1;
229 $options{size}=1;
230 $options{psnr}=1;
233 $options{file}="@ARGV";