[MPlayer-dev-eng] [PATCH] countquant.pl
Loren Merritt
lorenm at u.washington.edu
Mon Sep 20 09:52:14 CEST 2004
On Mon, 20 Sep 2004, Diego Biurrun wrote:
> Loren Merritt writes:
>>
>> 1) See those entries in divx2pass.log that look like "q:236"?
>> Those are lagrange multipliers, and 236 is the lambda used then you
>> select vqscale=2. (That space used to contain quantizers, which is why
>> it's labelled "q" and why countquant.pl is obsolete.)
>
> Does it really have no use at all anymore? I'll remove it then.
I didn't say it was useless, only out of date.
Here's the script I use, if you want to update it.
(works on psnr.log, not divx2pass.log)
--Loren Merritt
-------------- next part --------------
#!/usr/bin/env perl
# counts quantizer and psnr statistics from the log generated by mencoder/lavc
$^W=1;
use strict;
my $usage = "usage: countquant.pl psnr_??????.log [...]\n";
if(grep {$_ eq '-h'} @ARGV) {
die $usage;
}
# show $mult fractional qp partitions.
# (framewise qp may be fractional with qprd or *_mask).
my $mult = 1;
if(@ARGV and $ARGV[0] =~ /^-(\d+)$/) {
$mult = $1;
shift @ARGV;
}
sub mse2psnr($) {
my $d = shift;
return "inf" if !$d;
return -10*log($d)/log(10);
}
sub psnr2mse($) {
my $p = shift;
return 0 if $p eq "inf";
return 10**(-$p/10);
}
sub proc_file($) {
my $fh = shift;
my(%count, @qp_count, %qp_avg, %mse, $size);
%count = %qp_avg = (I=>0, P=>0, B=>0, A=>0);
@qp_count = (0) x (31*$mult);
# parse input file
while(<$fh>) {
/^\s*(\d+),\s+(\d+\.\d+),\s+(\d+), (\S+), (\S+), (\S+), (\S+) ([IPB])/ or next;
$count{$8} ++;
$qp_count[int($2*$mult+.5)] ++;
$qp_avg{$8} += $2;
$size += $3;
$mse{$8}{Y} += psnr2mse($4);
$mse{$8}{U} += psnr2mse($5);
$mse{$8}{V} += psnr2mse($6);
}
close($fh);
# compute stat averages
foreach my $t (qw(I P B)) {
$count{$t} or next;
$count{A} += $count{$t};
$qp_avg{A} += $qp_avg{$t};
$mse{$t}{A} = (4*$mse{$t}{Y} + $mse{$t}{U} + $mse{$t}{V}) / 6;
for(qw(Y U V A)) {
$mse{A}{$_} += $mse{$t}{$_};
}
}
foreach my $t (qw(I P B A)) {
$count{$t} or next;
$qp_avg{$t} /= $count{$t};
for(qw(Y U V A)) {
$mse{$t}{$_} /= $count{$t};
}
}
if(!$count{A}) {
warn "no frames found\n";
die $usage;
}
# print stats
for(0 .. 31*$mult) {
next unless $qp_count[$_] or ($_>0 and $qp_count[$_-1] and $qp_count[$_+1]);
printf( ($mult == 1 ? "q%2d" : "q%4.1f") . ": %6d (%4.1f%%)\n",
$_/$mult, $qp_count[$_], 100*$qp_count[$_]/$count{A} );
}
print "\n";
my $count_digits = int(log($count{A}+1)/log(10))+2;
$count_digits += 2 if $mult>1;
foreach my $t (qw(I P B)) {
printf "$t: %${count_digits}d (%4.1f%%) q:%5.2f psnr: %5.2f\n",
$count{$t}, 100*$count{$t}/$count{A}, $qp_avg{$t}, mse2psnr($mse{$t}{A});
}
printf "All: %${count_digits}d q:%5.2f psnr: %5.2f (Y:%5.2f Cb:%5.2f Cr:%5.2f)\n",
$count{A}, $qp_avg{A}, (map {mse2psnr($mse{A}{$_})} qw(A Y U V));
print "\n";
printf "total size: %d = %.1f MiB = %.2f kbps @ 23.976 fps\n",
$size, $size/2**20, (8*24/1001)*$size/$count{A};
}
# decompress a file if it's compressed, otherwise just open it
sub openz($) {
my $fn = shift;
my $fh;
if($fn =~ /\.bz2$/) {
open $fh, "-|", "bzcat", $fn
or warn "can't bunzip2 '$fn': $!\n" and return undef;
} elsif($fn =~ /\.gz$/) {
open $fh, "-|", "zcat", $fn
or warn "can't zcat '$fn': $!\n" and return undef;
} else {
open $fh, "<", $fn
or warn "can't open '$fn': $!\n" and return undef;
}
return $fh;
}
if(@ARGV) {
foreach(@ARGV) {
print "\n$_:\n" if @ARGV > 1;
proc_file(openz($_)||next);
}
} else {
proc_file(*STDIN);
}
More information about the MPlayer-dev-eng
mailing list