Skip to main content

WEBCODECS_TIMESCALE

@remotion/media-parser 返回所有带有微秒标准化时间戳的样本。 这意味着全局时间尺度是 1_000_000

通过将时间尺度硬编码为 1_000_000,样本可以直接传递给 EncodedVideoChunkEncodedAudioChunk,它们期望输入以微秒为单位。

🌐 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.

WEBCODECS_TIMESCALE 常量已导出:

🌐 The WEBCODECS_TIMESCALE constant is exported:

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

要获取样本的时间(以秒为单位),可以将时间戳除以 WEBCODECS_TIMESCALE 常量。

🌐 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

如果你对音轨的原生时间尺度感兴趣,可以从 originalTimescale 属性获取。并非所有的容器格式都支持这一点,有些可能会返回 1_000_000

🌐 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; }, });