Seekingv4.0.291
In parseMedia()
, parseMediaOnWebWorker()
and parseMediaOnServerWorker()
, you can seek to a different position in the media file.
Basic seekingtsx
import {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 ({type : 'keyframe-before-time',timeInSeconds : 5,});awaitparseMedia ({src : 'https://example.com/video.mp4',controller ,onVideoTrack : () => {return () => {// You can also seek inmidst a parse.controller .seek ({type : 'keyframe-before-time',timeInSeconds : 10,});};},});
Types of seek
keyframe-before-time
This will seek to the last keyframe that comes before the time you specified.
If there is a keyframe at exactly this time, it will seek to this one.
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 keyframetsx
import {mediaParserController } from '@remotion/media-parser';constcontroller =mediaParserController ();controller .seek ({type : 'keyframe-before-time',timeInSeconds : 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.
How smart is seeking?
The efficiency of seeking depends on the container format.
- ISO Base Media: Will use observed keyframes,
stsd
atoms andmfra
atoms in case of fragmented files. - WebM: Will use
Cues
and observed keyframes. - WAV: Will predict the sample number based on the sample rate and block align.
- Transport Stream: Not smart - can only use the previously observed PES headers.