codecs.conf: clarify XAN DPCM comment
[mplayer.git] / TOOLS / calcbpp.pl
blobe1626f8ce8a57ae17350b42f19afa5aaeb984f22
1 #!/usr/bin/perl -w
3 use POSIX;
5 sub round {
6 my $v = shift;
8 return floor($v + 0.5);
11 $raw_aspect = 720/576;
13 if (scalar(@ARGV) < 4) {
14 print("Please provide a) the cropped but unscaled resolution (e.g. " .
15 "716x524), b) the aspect ratio (either 4/3 or 16/9 for most DVDs), " .
16 "c) the video bitrate in kbps (e.g. 800) and d) the movie's fps.\n");
17 print("If your DVD is not encoded at 720x576 then change the \$raw_aspect" .
18 "variable at the beginning of this script.\n");
19 exit(1);
22 ($unscaled_width, $unscaled_height) = split('x', $ARGV[0]);
23 $encoded_at = $ARGV[1];
24 if ($encoded_at =~ /\//) {
25 my @a = split(/\//, $encoded_at);
26 $encoded_at = $a[0] / $a[1];
28 $scaled_width = $unscaled_width * ($encoded_at / ($raw_aspect));
29 $scaled_height = $unscaled_height;
30 $picture_ar = $scaled_width / $scaled_height;
31 ($bps, $fps) = @ARGV[2, 3];
33 printf("Prescaled picture: %dx%d, AR %.2f\n", $scaled_width, $scaled_height,
34 $picture_ar);
35 for ($width = 720; $width >= 320; $width -= 16) {
36 $height = 16 * round($width / $picture_ar / 16);
37 $diff = round($width / $picture_ar - $height);
38 $new_ar = $width / $height;
39 $picture_ar_error = abs(100 - $picture_ar / $new_ar * 100);
40 printf("${width}x${height}, diff % 3d, new AR %.2f, AR error %.2f%% " .
41 "scale=%d:%d bpp: %.3f\n", $diff, $new_ar, $picture_ar_error, $width,
42 $height, ($bps * 1000) / ($width * $height * $fps));