Skip to main content

提取样本

使用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 video
import {parseMedia} from '@remotion/media-parser'; const samples = await parseMedia({ src: 'https://remotion.media/video.mp4', onVideoTrack: ({track, container}) => { console.log(track.codecEnum);
(property) codecEnum: MediaParserVideoCodec
return null; }, });

有关更多信息,请参见 MediaParserVideoTrackMediaParserAudioTrack 的类型定义。

🌐 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 video
import {parseMedia} from '@remotion/media-parser'; const samples = await parseMedia({ src: 'https://remotion.media/video.mp4', onVideoTrack: ({track, container}) => { return (sample) => { console.log(sample);
(parameter) sample: MediaParserVideoSample
}; }, });

有关更多信息,请参见 MediaParserVideoSampleMediaParserAudioSample 的类型定义。

🌐 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 parsed
import {parseMedia} from '@remotion/media-parser'; const samples = await parseMedia({ 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 parse
import {parseMedia, mediaParserController} from '@remotion/media-parser'; const controller = mediaParserController(); const samples = await parseMedia({ src: 'https://remotion.media/video.mp4', controller, onVideoTrack: ({track, container}) => { return (sample) => { return () => { // When it's the last sample, seek to the beginning controller.seek(0); }; }; }, });

参见:mediaParserController()寻求

🌐 See: mediaParserController() and Seeking.