Skip to content

VideoStreamMetadata.sample_aspect_ratio: new metadata field (#733) #737

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carandraug
Copy link

New field to VideoStreamMetadata to at least get information about the stream sample/pixel aspect ratio. Getting this information is the minimum required to support non-square pixels.


This addresses issue #733 (which was deemed "reasonable" which is why I'm implementing it, thank you for considering this).

There is one thing that annoys me about this PR. The names for properties in C++ StreamMetadata and json returned by get_stream_json_metadata match. I could have separate num/den properties in StreamMetadata but I don't think that's quite right because they're actually two parts of the same value. On the json side of things I made it two separate properties because it's std::map<std::string, std::string> (although it would be trivial to make it a colon separated string and parse it on the python side of things).

)

New field to VideoStreamMetadata to at least get information about the
stream sample/pixel aspect ratio.  Getting this information is the
minimum required to support non-square pixels.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 22, 2025
@scotts
Copy link
Contributor

scotts commented Jun 23, 2025

@carandraug, thanks for tackling this! This PR actually raises an interesting design question: so far, we've only exposed metadata as strings, floats or ints. The value that's closest to the SAR that we currently have is the FPS, which we return as a float. In FFmpeg, it's an AVRational. We have not yet returned a rational as-is, without turning it into a float.

For your use-case, is it easier to have a rational, or a float? If we keep a rational, I think we should actually make it a numbers.Rational rather than just a tuple. @NicolasHug, thoughts?

@NicolasHug
Copy link
Member

I think it would have to be a fractions.Fraction because Rational is an ABC, but agreed this is better than a plain tuple as it supports natural operations like +, float(.), etc.

Now that I think about it, we could have exposed fps as a fraction as well, but it's probably too late to do so without breaking BC?

@carandraug
Copy link
Author

@scotts writes:

For your use-case, is it easier to have a rational, or a float? If we keep a rational, I think we should actually make it a numbers.Rational rather than just a tuple. @NicolasHug, thoughts?

From afar, I guess using a rational would be slightly simpler but I see no reason why I couldn't work a float though. However, it is trivial to get a float from a rational but not the inverse. If someone ever really needs the fraction, it will be too late to change so I'd suggest to return a rational now.

Shall I add a commit to this PR to use a fractions.Fraction instead of a tuple? Is the rest of the PR ok?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants