快速和慢速操作
@remotion/media-parser 允许你指定想要获取的信息。
然后它会尽量少地读取数据以实现目标。
有三种类型的字段:
🌐 There are three types of fields:
- 仅头部:只需要读取文件的前几个字节。
- 仅元数据:只需要解析元数据部分
- 需要完整解析:整个文件将被读取和处理。
显然,处理文件的量越少越快,你应该尽量只读取所需的信息。
🌐 Obviously, processing less of the file is faster and you should aim to read only the information you require.
完整解析操作
🌐 Full parsing operations
以下 fields 需要读取完整文件:
🌐 The following fields require the full file to be read:
slowStructureslowKeyframesslowFpsslowDurationInSecondsslowNumberOfFramesslowAudioBitrateslowVideoBitrate
通常,如果一个字段被标记为 slow,则需要读取整个文件。
🌐 Generally, if a field is marked as slow, it will require the full file to be read.
此外,如果传入了onVideoTrack或onAudioTrack处理器,并且任何函数返回一个回调函数,则需要完整解析。
🌐 Also, if an onVideoTrack or onAudioTrack handler is passed, and any function returns an callback function, full parsing is required.
仅元数据操作
🌐 Metadata-only operations
以下 fields 仅需要解析视频的元数据部分:
🌐 The following fields require only the metadata section of the video to be parsed:
dimensionsdurationInSecondsfpsvideoCodecaudioCodectracksunrotatedDimensionsisHdrrotationlocationkeyframessampleRatenumberOfAudioChannelsm3uStreamsmetadataimages
此外,如果传入了 onVideoTrack 或 onAudioTrack 处理程序,则仅在处理程序函数返回 null 时才需要解析元数据部分。
🌐 Also, if an onVideoTrack or onAudioTrack handler is passed, only the parsing of the metadata section is required if null is returned from the handler function.
仅头文件操作
🌐 Header-only operations
以下 fields 仅需要解析媒体的前几个字节:
🌐 The following fields require only the first few bytes of the media to be parsed:
寻求必需
🌐 Seeking required
如果你从 URL 加载视频,请确保它们支持 Range 头。
否则,如果元数据位于文件的末尾,@remotion/media-parser 将不得不读取整个文件。
🌐 If you load videos from a URL, make sure that they support the Range header.
Otherwise, @remotion/media-parser has no choice but to read the full file if the metadata is at the end of it.
示例
🌐 Example
Reading header only// Some fields only require the first few bytes of the file to be read: constresult = awaitparseMedia ({src : 'https://remotion.media/video.mp4',fields : {size : true,container : true,internalStats : true, }, });console .log (result .internalStats .finalCursorOffset ); // 12 // Reading the metadata of the video will only require the metadata section to be parsed. // You can also use onVideoTrack() and return null to retrieve track information but to not get the samples. constresult2 = awaitparseMedia ({src : 'https://remotion.media/video.mp4',fields : {durationInSeconds : true,dimensions : true,internalStats : true, },onVideoTrack : ({track }) => {console .log (track ); return null; }, });console .log (result2 .internalStats .finalCursorOffset ); // 4000console .log (result2 .dimensions ); // Asking for all video samples requires parsing the whole file constresult3 = awaitparseMedia ({src : 'https://remotion.media/video.mp4',fields : {internalStats : true, },onVideoTrack : () => { return (videoSample ) =>console .log (videoSample ); }, });console .log (result3 .internalStats .finalCursorOffset ); // 1870234802
另请参阅
🌐 See also