countquant_x264.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/env perl
  2. # countquant_x264.pl: displays statistics from x264 multipass logfiles
  3. # by Loren Merritt, 2005-4-5
  4. @size{I,P,B} =
  5. @n{I,P,B} = (0)x3;
  6. sub proc_file {
  7. my $fh = shift;
  8. while(<$fh>) {
  9. /type:(.) q:(\d+\.\d+) tex:(\d+) mv:(\d+) misc:(\d+)/ or next;
  10. $type = uc $1;
  11. $n{$type} ++;
  12. $q[int($2+.5)] ++;
  13. $avgq += $2;
  14. $avgq{$type} += $2;
  15. my $bytes = ($3+$4+$5)/8;
  16. $size{$type} += $bytes;
  17. }
  18. $size = $size{I} + $size{P} + $size{B};
  19. $n = $n{I} + $n{P} + $n{B};
  20. $n or die "unrecognized input\n";
  21. }
  22. if(@ARGV) {
  23. foreach(@ARGV) {
  24. open $fh, "<", $_ or die "can't open '$_': $!";
  25. proc_file($fh);
  26. }
  27. } else {
  28. proc_file(STDIN);
  29. }
  30. for(0..51) {
  31. $q[$_] or next;
  32. printf "q%2d: %6d %4.1f%%\n", $_, $q[$_], 100*$q[$_]/$n;
  33. }
  34. print "\n";
  35. $digits = int(log($n+1)/log(10))+2;
  36. printf "All: %${digits}d %s avgQP:%5.2f avgBytes:%5d\n",
  37. $n, $n==$n{I}?" ":"", $avgq/$n, $size/$n;
  38. foreach(qw(I P B S)) {
  39. $n{$_} or next;
  40. printf "%s: %${digits}d (%4.1f%%) avgQP:%5.2f avgBytes:%5d\n",
  41. $_, $n{$_}, 100*$n{$_}/$n, $avgq{$_}/$n{$_}, $size{$_}/$n{$_};
  42. }
  43. print "\n";
  44. printf "total size: $size B = %.2f KiB = %.2f MiB\n",
  45. $size/2**10, $size/2**20;
  46. print "bitrate: ", join("\n = ",
  47. map sprintf("%.2f kbps @ %s fps", $_*$size*8/1000/$n, $_),
  48. 23.976, 25, 29.97), "\n";