Rational
FFmpeg's AVRational: an exact fraction. Use it for time-bases, frame rates and aspect ratios. Float conversion is lossy; do all arithmetic on the rational form when possible.
Always stored normalized: reduced by gcd, denominator positive. Rational(2, 4) == Rational(1, 2).
Functions
Link copied to clipboard
scalar * num / den with a Long intermediate. Multiplies after reducing scalar against den first, so e.g. pts * Rational(1, 1_000_000) stays exact far beyond what naive scalar * num would overflow at. For timestamp conversion between two arbitrary time-bases prefer the native av_rescale_q path (128-bit).
Link copied to clipboard
Negation, widened before it negates.