提取样本
使用parseMedia(),你可以从各种媒体格式中提取视频和音频样本。
🌐 With parseMedia(), you can extract video and audio samples from a variety of media formats.
获取曲目
🌐 Getting tracks
使用 onVideoTrack 和/或 onAudioTrack 获取关于视频轨道的信息。
🌐 Use onVideoTrack and/or onAudioTrack to get information about a video track.
Extract tracks from a videoimport {parseMedia } from '@remotion/media-parser'; constsamples = awaitparseMedia ({src : 'https://remotion.media/video.mp4',onVideoTrack : ({track ,container }) => {console .log (track .codecEnum ); return null; }, });
有关更多信息,请参见 MediaParserVideoTrack 和 MediaParserAudioTrack 的类型定义。
🌐 See the type definitions for MediaParserVideoTrack and MediaParserAudioTrack for more information.
如果你对从这条曲目获取样本不感兴趣,请返回 null。
🌐 Return null if you are not interested in getting samples from the track.
获取样品
🌐 Getting samples
如果你从 onVideoTrack 和/或 onAudioTrack 返回一个回调,你可以从曲目中获取样本。
🌐 If you return a callback from onVideoTrack and/or onAudioTrack, you can get samples from the track.
Extract samples from a videoimport {parseMedia } from '@remotion/media-parser'; constsamples = awaitparseMedia ({src : 'https://remotion.media/video.mp4',onVideoTrack : ({track ,container }) => { return (sample ) => {console .log (sample ); }; }, });
有关更多信息,请参见 MediaParserVideoSample 和 MediaParserAudioSample 的类型定义。
🌐 See the type definitions for MediaParserVideoSample and MediaParserAudioSample for more information.
检查样本是否是最后一个v4.0.307
🌐 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 parsedimport {parseMedia } from '@remotion/media-parser'; constsamples = awaitparseMedia ({src : 'https://remotion.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 parseimport {parseMedia ,mediaParserController } from '@remotion/media-parser'; constcontroller =mediaParserController (); constsamples = awaitparseMedia ({src : 'https://remotion.media/video.mp4',controller ,onVideoTrack : ({track ,container }) => { return (sample ) => { return () => { // When it's the last sample, seek to the beginningcontroller .seek (0); }; }; }, });
参见:mediaParserController() 和 寻求。
🌐 See: mediaParserController() and Seeking.