Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MPEG-1 video pixel aspect ratio #411

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion getid3/module.audio-video.mpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,20 @@ public static function videoFramerateLookup($rawframerate) {
* @return float
*/
public static function videoAspectRatioLookup($rawaspectratio, $mpeg_version=1, $width=0, $height=0) {
// Per http://forum.doom9.org/archive/index.php/t-84400.html
// 0.9157 is commonly accepted to mean 11/12 or .9166, the reciprocal of 12/11 (1.091) and,
// 1.0950 is commonly accepted to mean 11/10 or 1.1, the reciprocal of 10/11 (0.909)
$lookup = array(
1 => array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 0.9157, 0.9815, 1.0255, 1.0695, 1.0950, 1.1575, 1.2015, 0),
1 => array(0, 1, 0.6735, 0.7031, 0.7615, 0.8055, 0.8437, 0.8935, 11/12, 0.9815, 1.0255, 1.0695, 11/10, 1.1575, 1.2015, 0),
2 => array(0, 1, 1.3333, 1.7778, 2.2100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
);
$ratio = (float) (isset($lookup[$mpeg_version][$rawaspectratio]) ? $lookup[$mpeg_version][$rawaspectratio] : 0);
if ($mpeg_version == 2 && $ratio != 1 && $width != 0) {
// Calculate pixel aspect ratio from MPEG-2 display aspect ratio
$ratio = $ratio * $height / $width;
} else if ($mpeg_version == 1 && $ratio != 0 && !is_nan($ratio)) {
// The MPEG-1 tables store the reciprocal of the pixel aspect ratio.
$ratio = 1 / $ratio;
}
return $ratio;
}
Expand Down