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

MPEG-2 videos return wrong aspect ratio #148

Closed
bvibber opened this issue Feb 15, 2018 · 5 comments
Closed

MPEG-2 videos return wrong aspect ratio #148

bvibber opened this issue Feb 15, 2018 · 5 comments

Comments

@bvibber
Copy link
Contributor

bvibber commented Feb 15, 2018

Working on adding MPEG-2 video upload to MediaWiki I noticed that getid3 on this MPEG-2 file https://archive.org/download/FolgersCoffe/FolgersCoffe.mpeg returns an incorrect ['video']['pixel_aspect_ratio'] of 0.6735, which is the MPEG-1 interpretation of the value 2 for the aspect ratio field.

In MPEG-2, the field should be interpreted differently, as a key to a list of display aspect ratios, in this case 2 mapping to 4:3 (see eg https://web.archive.org/web/20170910202756/http://dvd.sourceforge.net/dvdinfo/mpeghdrs.html )

Workaround: pull the raw field value out from ['mpeg']['video']['raw']['aspect_ratio_information'] and interpret it directly.

Recommended fix: if the file is found to be MPEG-2, calculate the correct pixel aspect ratio from the given size and the display aspect ratio key and override the MPEG-1 mapping.

@JamesHeinrich
Copy link
Owner

Since you're familiar with the issue, are you able to submit a patch to correct the issue?

@bvibber
Copy link
Contributor Author

bvibber commented Feb 15, 2018

Yes, can do. :)

JamesHeinrich added a commit that referenced this issue Feb 15, 2018
@JamesHeinrich
Copy link
Owner

Actually don't worry about it, the problem was simpler than I thought, so I've fixed it in 97dd360

bvibber added a commit to bvibber/getID3 that referenced this issue Feb 15, 2018
@bvibber
Copy link
Contributor Author

bvibber commented Feb 15, 2018

One more tweak -- the MPEG-2 aspect ratios are display aspect ratios, not pixel aspect ratios, so the value from the lookup table needs to be multiplied by I believe $height / $width to get a pixel aspect ratio.

@bvibber
Copy link
Contributor Author

bvibber commented Feb 16, 2018

Specifically, the value for square pixels should return a pixel aspect ratio of 1, while the other values need to be scaled from display aspect to pixel aspect.

bvibber added a commit to bvibber/getID3 that referenced this issue Feb 16, 2018
(corrected after double-checking spec)

JamesHeinrich#148
bvibber added a commit to bvibber/getID3 that referenced this issue Feb 16, 2018
* fix array lookup
* calculate pixel aspect ratio from display aspect ratios
* delay calc of aspect ratio until after extended size is known
* mirror the updated pixel aspect ratio up to the 'video' section

Fixes remaining issues with JamesHeinrich#148
StudioMaX pushed a commit to StudioMaX/getID3 that referenced this issue May 26, 2019
StudioMaX pushed a commit to StudioMaX/getID3 that referenced this issue May 26, 2019
* fix array lookup
* calculate pixel aspect ratio from display aspect ratios
* delay calc of aspect ratio until after extended size is known
* mirror the updated pixel aspect ratio up to the 'video' section

Fixes remaining issues with JamesHeinrich#148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants