annotate TOOLS/calcbpp.pl @ 12404:5ca00576a26c

more wishes
author diego
date Mon, 03 May 2004 01:27:48 +0000
parents 650dda2e4bbb
children 03d14c999d2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8464
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
1 #!/usr/bin/perl -w
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
2
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
3 use POSIX;
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
4
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
5 sub round {
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
6 my $v = shift;
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
7
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
8 return floor($v + 0.5) != floor($v) ?
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
9 floor($v + 0.5) :
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
10 floor($v);
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
11 }
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
12
8476
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
13 $raw_aspect = 720/576;
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
14
8464
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
15 if (scalar(@ARGV) < 4) {
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
16 print("Please provide a) the cropped but unscaled resolution (e.g. " .
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
17 "716x524), b) the aspect ratio (either 4/3 or 16/9 for most DVDs), " .
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
18 "c) the video bitrate in kbps (e.g. 800) and d) the movie's fps.\n");
8476
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
19 print("If your DVD is not encoded at 720x576 then change the \$raw_aspect" .
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
20 "variable at the beginning of this script.\n");
8464
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
21 exit(1);
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
22 }
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
23
8476
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
24 ($unscaled_width, $unscaled_height) = split('x', $ARGV[0]);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
25 $encoded_at = $ARGV[1];
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
26 if ($encoded_at =~ /\//) {
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
27 my @a = split(/\//, $encoded_at);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
28 $encoded_at = $a[0] / $a[1];
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
29 }
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
30 $scaled_width = $unscaled_width * ($encoded_at / ($raw_aspect));
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
31 $scaled_height = $unscaled_height;
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
32 $picture_ar = $scaled_width / $scaled_height;
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
33 ($bps, $fps) = @ARGV[2, 3];
8464
85ebbeeb913b scripts mentioned by DOCS/tech/encoding-tips.txt
arpi
parents:
diff changeset
34
8476
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
35 printf("Prescaled picture: %dx%d, AR %.2f\n", $scaled_width, $scaled_height,
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
36 $picture_ar);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
37 for ($width = 720; $width >= 320; $width -= 16) {
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
38 $height = 16 * round($width / $picture_ar / 16);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
39 $diff = round($width / $picture_ar - $height);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
40 $new_ar = $width / $height;
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
41 $picture_ar_error = abs(100 - $picture_ar / $new_ar * 100);
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
42 printf("${width}x${height}, diff % 3d, new AR %.2f, AR error %.2f%% " .
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
43 "scale=%d:%d bpp: %.3f\n", $diff, $new_ar, $picture_ar_error, $width,
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
44 $height, ($bps * 1000) / ($width * $height * $fps));
650dda2e4bbb bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents: 8464
diff changeset
45 }