Skip to main content

WEBCODECS_TIMESCALE

@remotion/media-parser returns all samples with normalized timestamps in microseconds.
This means the global timescale is 1_000_000.

By hardcoding the timescale to 1_000_000, the samples can be directly passed to EncodedVideoChunk and EncodedAudioChunk, which expect the input to be in microseconds.

The WEBCODECS_TIMESCALE constant is exported:

Using WEBCODECS_TIMESCALE
import {WEBCODECS_TIMESCALE} from '@remotion/media-parser'; const timescale = WEBCODECS_TIMESCALE; // 1_000_000

To get the time in seconds of a sample, you can divide the timestamp by the WEBCODECS_TIMESCALE constant.

Getting the native timescale
import {parseMedia, WEBCODECS_TIMESCALE} from '@remotion/media-parser'; const result2 = await parseMedia({ src: 'https://remotion.media/video.mp4', onVideoTrack: ({track}) => { return (sample) => { const timeInSeconds = sample.timestamp / WEBCODECS_TIMESCALE; console.log(timeInSeconds); }; }, });

Getting the native timescale

If you are interested in the native timescale of a track, you can get it from the originalTimescale property.
Not all container formats may support this, some may return 1_000_000 instead.

Getting the native timescale
import {parseMedia} from '@remotion/media-parser'; const result2 = await parseMedia({ src: 'https://remotion.media/video.mp4', onVideoTrack: ({track}) => { console.log(track.timescale); // 1_000_000, always console.log(track.originalTimescale); // 12800 return null; }, });