Mercurial > mplayer.hg
annotate TOOLS/calcbpp.pl @ 34177:fadc00cc31d3
Optimize TranslateFilename().
Replace for loop with index by while loop with pointer.
Unite the if conditions.
author | ib |
---|---|
date | Wed, 26 Oct 2011 15:52:06 +0000 |
parents | 0f1b5b68af32 |
children |
rev | line source |
---|---|
8464 | 1 #!/usr/bin/perl -w |
2 | |
3 use POSIX; | |
4 | |
5 sub round { | |
6 my $v = shift; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
13033
diff
changeset
|
7 |
13033 | 8 return floor($v + 0.5); |
8464 | 9 } |
10 | |
8476
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
11 $raw_aspect = 720/576; |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
12 |
8464 | 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"); | |
8476
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
17 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
|
18 "variable at the beginning of this script.\n"); |
8464 | 19 exit(1); |
20 } | |
21 | |
8476
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
22 ($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
|
23 $encoded_at = $ARGV[1]; |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
24 if ($encoded_at =~ /\//) { |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
25 my @a = split(/\//, $encoded_at); |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
26 $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
|
27 } |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
28 $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
|
29 $scaled_height = $unscaled_height; |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
30 $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
|
31 ($bps, $fps) = @ARGV[2, 3]; |
8464 | 32 |
8476
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
33 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
|
34 $picture_ar); |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
35 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
|
36 $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
|
37 $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
|
38 $new_ar = $width / $height; |
650dda2e4bbb
bunkus: Restored sane line breaks. Added note about other DVD resolutions than 720x576.
mosu
parents:
8464
diff
changeset
|
39 $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
|
40 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
|
41 "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
|
42 $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
|
43 } |