getVideoMetadata()
@remotion/media-utils 工具函数包的一部分。
🌐 Part of the @remotion/media-utils package of helper functions.
不推荐:在 Linux 上不支持 H.265 视频,并且在某些其他格式上也会失败。 更好的解决方案:使用 Mediabunny 获取元数据
仅在浏览器中有效。
将 src 拿到视频中,加载它并返回指定源的元数据。
🌐 Takes a src to a video, loads it and returns metadata for the specified source.
参数
🌐 Arguments
src
指向资源的字符串。
🌐 A string pointing to an asset.
返回值
🌐 Return value
Promise<VideoMetadata> - 包含关于视频数据的信息的对象:
durationInSeconds:number视频的时长,以秒为单位。width:number视频的像素宽度。height:number视频的像素高度。aspectRatio:number视频宽度除以视频高度。isRemote:boolean视频是本地导入还是来自不同来源。
durationInSeconds 可能返回 Infinity。如果视频的时长没有存储在文件开头,就会发生这种情况。
例如,对于使用网络摄像头录制并在录制过程中进行编码的视频,就会出现这种情况。
请确保对用户提供的视频处理 Infinity,并使用 FFmpeg 重新编码视频,将时长移动到文件开头。
示例
🌐 Example
import {getVideoMetadata } from '@remotion/media-utils';
await getVideoMetadata (staticFile ('video.mp4')); /* {
durationInSeconds: 100.00,
width: 1280,
height: 720,
aspectRatio: 1.77777778,
isRemote: false
} */
await getVideoMetadata ('https://example.com/remote-audio.webm'); /* {
durationInSeconds: 40.213,
width: 1920,
height: 1080,
aspectRatio: 1.77777778,
isRemote: true
} */缓存行为
🌐 Caching behavior
此函数正在对其返回的结果进行记忆化。如果你多次向 src 传递相同的参数,它将从第二次开始返回缓存的版本,无论文件是否已更改。要清除缓存,你必须重新加载页面。
🌐 This function is memoizing the results it returns.
If you pass in the same argument to src multiple times, it will return a cached version from the second time on, regardless of if the file has changed. To clear the cache, you have to reload the page.
另请参阅
🌐 See also