Skip to content

How to set videoTimescale / the purpose of frameRate #326

@branks

Description

@branks

I was looking for how to set videoTimescale on an mp4 and it's led me to some confusion

In VideoTrackMetadata frameRate is the rate in hertz of the video

/**
 * Additional metadata for video tracks.
 * @group Output files
 * @public
 */
export type VideoTrackMetadata = BaseTrackMetadata & {
    ...
    /**
    * The expected video frame rate in hertz. If set, all timestamps and durations of this track will be snapped to
    * this frame rate. You should avoid adding more frames than the rate allows, as this will lead to multiple frames
    * with the same timestamp.
    */
    frameRate?: number;
};

But its later used in src/isobmff/isobmff-muxer.ts#getVideoTrackData to do:

// The frame rate set by the user may not be an integer. Since timescale is an integer, we'll approximate the
// frame time (inverse of frame rate) with a rational number, then use that approximation's denominator
// as the timescale.
const timescale = computeRationalApproximation(1 / (track.metadata.frameRate ?? 57600), 1e6).denominator;

So using 24 vs 57600 for frameRate on VideoTrackMetadata gives a very different values

computeRationalApproximation(1 / (24 ?? 57600), 1e6).denominator
24

vs

computeRationalApproximation(1 / (90000 ?? 57600), 1e6).denominator
90000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions