Skip to main content

Seeking Hints

warning

This feature is experimental and not yet ready for production use.

When Media Parser wants to seek to a specific position in the media file, it can be expensive to find out where to go.

With Seeking Hints, you can provide a hint to the media parsing process upfront about the structure to the file, so that seeking can be short-circuited without needing to figure out the position.

Seeking hints are produced from previous parseMedia() calls.

To get seeking hints, you can call getSeekingHints() on the controller.

import {mediaParserController, parseMedia} from '@remotion/media-parser';

const controller = mediaParserController();

await parseMedia({
  controller,
  // Adding a callback so the full file is read
  onVideoTrack: (track) => {
    return (sample) => {
      console.log(sample);
    };
  },
  src: 'https://stream.mux.com/QkFQYWZ0ZS53ZWJ3aWQvc3RhdGlvbl9pbnRlcm5hbC5tM3U4Lm1wNA.m3u8',
});

const hints = await controller.getSeekingHints();

Using seeking hints

Once you have obtained seeking hints from a previous parse, you can pass them to a new parseMedia(), parseMediaOnWebWorker(), parseMediaOnServerWorker(), downloadAndParseMedia() or convertMedia() call.


await parseMedia({
  controller,
  src: 'https://stream.mux.com/QkFQYWZ0ZS53ZWJ3aWQvc3RhdGlvbl9pbnRlcm5hbC5tM3U4Lm1wNA.m3u8',
  // Seeking hints were obtained from the previous parse
  seekingHints,
});

Good to know

  • Seeking hints can be fetched at any time also during the parsing process, not only at the end.
  • The data structure of the seeking hints is not part of the public API and may change at any time.
  • After the parse, seeking hints are only available if the parse was successful or aborted, not when it failed.
  • Seeking hints are available for parseMediaOnWebWorker() and parseMediaOnServerWorker().
  • A mediaParserController() can only be attached to 1 parseMedia() call.
  • Seeking hints can be passed to convertMedia().