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_TIMESCALEtsx
import {WEBCODECS_TIMESCALE } from '@remotion/media-parser';consttimescale =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 timescaletsx
import {parseMedia ,WEBCODECS_TIMESCALE } from '@remotion/media-parser';constresult2 = awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track }) => {return (sample ) => {consttimeInSeconds =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 timescaletsx
import {parseMedia } from '@remotion/media-parser';constresult2 = awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track }) => {console .log (track .timescale ); // 1_000_000, alwaysconsole .log (track .originalTimescale ); // 12800return null;},});