Extract samples
With parseMedia()
, you can extract video and audio samples from a variety of media formats.
Getting tracks
Use onVideoTrack
and/or onAudioTrack
to get information about a video track.
Extract tracks from a videotsx
import {parseMedia } from '@remotion/media-parser';constsamples = awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track ,container }) => {console .log (track .codecEnum )return null}});
See the type definitions for MediaParserVideoTrack
and MediaParserAudioTrack
for more information.
Return null
if you are not interested in getting samples from the track.
Getting samples
If you return a callback from onVideoTrack
and/or onAudioTrack
, you can get samples from the track.
Extract samples from a videotsx
import {parseMedia } from '@remotion/media-parser';constsamples = awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track ,container }) => {return (sample ) => {console .log (sample )}}});
See the type definitions for MediaParserVideoSample
and MediaParserAudioSample
for more information.
Check if a sample was the last onev4.0.307
If you would like to execute code when the last sample of a track has been parsed, you can return a callback from the sample callback that will be called when the last sample has been parsed.
Execute code when the last sample of a track has been parsedtsx
import {parseMedia } from '@remotion/media-parser';constsamples = awaitparseMedia ({src : 'https://parser.media/video.mp4',onVideoTrack : ({track ,container }) => {return (sample ) => {return () => {console .log (sample , 'is the last sample')}}}});
Seeking in callbacks
In all types of callbacks, you can pause, resume, seek and abort.
Looping the parsetsx
import {parseMedia ,mediaParserController } from '@remotion/media-parser';constcontroller =mediaParserController ()constsamples = awaitparseMedia ({src : 'https://parser.media/video.mp4',controller ,onVideoTrack : ({track ,container }) => {return (sample ) => {return () => {// When it's the last sample, seek to the beginningcontroller .seek (0)}}}});
See: mediaParserController()
and Seeking.