Skip to main content

getLottieMetadata()

属于 @remotion/lottie 包。

使用此函数,您可以获取 Lottie 动画的基本元数据,如尺寸、持续时间和帧速率。

Animation.tsx
tsx
import { getLottieMetadata } from "@remotion/lottie";
 
// animationData is a JSON object, can be imported from a .json file, remote file or using staticFile()
const metadata = getLottieMetadata(animationData);
 
/*
{
durationInFrames: 90,
durationInSeconds: 3.0030030030030037,
fps: 29.9700012207031,
height: 1080,
width: 1920,
}
*/
Animation.tsx
tsx
import { getLottieMetadata } from "@remotion/lottie";
 
// animationData is a JSON object, can be imported from a .json file, remote file or using staticFile()
const metadata = getLottieMetadata(animationData);
 
/*
{
durationInFrames: 90,
durationInSeconds: 3.0030030030030037,
fps: 29.9700012207031,
height: 1080,
width: 1920,
}
*/

API

该函数接受一个参数,一个符合 Lottie 模式的 JavaScript 对象。

返回值

如果无法解析元数据,则此函数返回 null

如果可以解析元数据,则返回一个具有以下属性的对象:

height

动画的自然高度(以像素为单位)。

width

动画的自然宽度(以像素为单位)。

durationInSeconds

动画的持续时间(以秒为单位),如果使用此对象的 fps

durationInFrames

动画的持续时间(以帧为单位),如果使用此对象的 fps

note

此值向下舍入到最接近的整数,因为 Remotion 不支持 durationInFrames 的非整数值。

fps

Lottie 动画的自然帧速率。

另请参阅