寻找v4.0.291
🌐 Seekingv4.0.291
在 parseMedia()、parseMediaOnWebWorker() 和 parseMediaOnServerWorker() 中,你可以在媒体文件中寻找不同的位置。
🌐 In parseMedia(), parseMediaOnWebWorker() and parseMediaOnServerWorker(), you can seek to a different position in the media file.
Basic seekingimport {parseMedia ,mediaParserController } from '@remotion/media-parser'; constcontroller =mediaParserController (); // You can make a seek even before starting a parse // This will be considered before emitting the first samplecontroller .seek (5); // Seek to 5 seconds awaitparseMedia ({src : 'https://remotion.media/video.mp4',controller ,onVideoTrack : () => { return () => { // You can also seek inmidst a parse.controller .seek (10); // Seek to 10 seconds }; }, });
调用 .seek() 将定位到你指定时间之前的最佳关键帧。
🌐 Calling .seek() will seek to the best keyframe that comes before the time you specified.
如果在这个时间正好有一个关键帧,它可能会跳转到这个关键帧。
不能保证这是你指定时间之前的最后一个关键帧。
🌐 If there is a keyframe at exactly this time, it may seek to this one.
There is no guarantee that this is the last keyframe before the time you specified.
请记住,如果你想解码视频,你总是必须从关键帧开始。如果你对 time 之前的帧不感兴趣,你仍然需要解码它们,但可以丢弃它们。
🌐 Remember that if you want to decode a video, you always have to start at a keyframe. If you are not interested in the frames before time, you still need to decode them, but you may discard them.
Seeking to a keyframeimport {mediaParserController } from '@remotion/media-parser'; constcontroller =mediaParserController ();controller .seek (5);
当你无法寻求时
🌐 When you cannot seek
如果以下任一字段是必填的,则不允许向前查找:
🌐 It is not allowed to seek forward if any of the following fields are required:
原因是这些字段的计算需要对所有样本进行迭代。如果向前查找,一些样本会被跳过,从而导致结果出现偏差。
🌐 The reason for this is that all samples need to be iterated over for these fields to be calculated. By seeking forward, some samples would be skipped which would skew the results.
如果你尝试这样做,将会抛出一个错误。
🌐 An error will be thrown if you attempt to do this.
模拟搜索v4.0.312
🌐 Simulate a seekv4.0.312
你可以模拟如果你跳转到某个时间会发生什么。
🌐 You can simulate what would happen if you seeked to a certain time.
Basic seekingimport {parseMedia ,mediaParserController } from '@remotion/media-parser'; constcontroller =mediaParserController (); awaitparseMedia ({src : 'https://remotion.media/video.mp4',controller ,onVideoTrack : () => { return async () => { constresult = awaitcontroller .simulateSeek (3);console .log (result ); // { "type": "do-seek", byte: 5763, timeInSeconds: 0 } }; }, });
如果你正在考虑一次搜索,并且只想在结果符合预期时执行,它会很有用。结果将是一个 SeekResolution 对象。
🌐 This is useful if you are considering a seek and only want to execute it if the outcome is desired.
The result will be a SeekResolution object.
追求有多聪明?
🌐 How smart is seeking?
搜索的效率取决于容器的格式。
🌐 The efficiency of seeking depends on the container format.
- ISO 基本媒体:将使用观察到的关键帧、
stsd原子和mfra原子(在分段文件的情况下)。 - WebM:将使用
Cues和观察到的关键帧。 - WAV:将根据采样率和块对齐预测样本数量。
- 传输流:不智能——只能使用先前观察到的 PES 头。