Command Palette

Search for a command to run...

Relottie Metadata API - Extract Lottie Info

Learn to use relottie-metadata plugin to extract dimensions, framerate, duration, colors, and more from Lottie animations with Relottie.

API Reference: @lottiefiles/relottie-metadata

@lottiefiles/relottie-metadata is a utility plugin for relottie that extracts common metadata from a Lottie animation during processing.

This metadata, such as dimensions, framerate, duration, and colors used, is attached to the processed VFile for easy access.

Installation

Install the package alongside @lottiefiles/relottie:

npm install @lottiefiles/relottie-metadata
# or
yarn add @lottiefiles/relottie-metadata

Usage

Add the plugin to your relottie pipeline using .use(). The extracted metadata will be available on the data.metadata property of the resulting VFile object.

import { relottie } from '@lottiefiles/relottie';
import relottieMetadata, { type MetadataFileData } from '@lottiefiles/relottie-metadata';

// Example Lottie JSON (replace with your actual Lottie data)
// Sourced from __fixtures__/features/auto-orient.json in the original docs
const inputLottie = '{
  "v": "5.5.7",
  "fr": 60,
  "ip": 0,
  "op": 180,
  "w": 512,
  "h": 512,
  "nm": "Metadata Example",
  "ddd": 0,
  "assets": [],
  "layers": [
      {
        "ty": 4, "ks": { "c": { "k": [0.196, 0.314, 0.69, 1] } } // Shape layer with color #3250B0
      }
  ],
  "markers": [],
  "g": "Test Generator v1.0"
}';

async function extractMetadata() {
  try {
    // Process with the plugin
    const file = await relottie()
      .use(relottieMetadata)
      .process(inputLottie);

    // Type assertion to access the data
    const fileData = file.data as MetadataFileData;
    const metadata = fileData.metadata; // Access the data

    if (metadata) {
      console.log('Extracted Metadata:');
      console.log(` - Version: ${metadata.version}`);
      console.log(` - Dimensions: ${metadata.width}x${metadata.height}`);
      console.log(` - Framerate: ${metadata.framerate}fps`);
      console.log(` - Duration: ${metadata.outPoint - metadata.inPoint} frames`);
      console.log(` - Colors: ${Array.from(metadata.colors).join(', ')}`);
      console.log(` - Generator: ${metadata.generator}`);
      // fileSize might require reading from an actual file,
      // not just a string, to be calculated by the plugin.
      // console.log(` - File Size (bytes): ${metadata.fileSize?.bytes}`);
    } else {
      console.log('No metadata extracted.');
    }

  } catch (error) {
    console.error('Error processing Lottie or extracting metadata:', error);
  }
}

extractMetadata();

Output Data (vfile.data.metadata)

The plugin attaches a metadata object to vfile.data. The structure, based on the MetadataFileData interface, includes:

interface MetadataFileData extends Data {
  // Data from vfile
  metadata: {
    /**
     * Set of unique color strings used in the animation.
     * Colors are represented as hex strings (e.g., "#RRGGBB" or "#RRGGBBAA" if alpha is present and not FF).
     */
    colors: Set<string>;
    /**
     * Size of the Lottie JSON. This is typically derived from `vfile.value.length`
     * if the input to `process()` was a string, or the actual file size if input was a file path
     * and the environment allows file system access during processing.
     * It might not be populated if processing a VFile that doesn't have its value set from a full file read.
     */
    fileSize?: FileSizeValue; // FileSizeValue includes bytes and formatted string
    /** Framerate in frames per second */
    framerate: number;
    /** Total number of frames in the animation (often same as outPoint). */
    frames: number;
    /** Generator tool string, if specified in Lottie JSON. */
    generator: string;
    /** Height of the animation. */
    height: number;
    /** Starting frame (usually 0). */
    inPoint: number;
    /** Ending frame (duration = outPoint - inPoint). */
    outPoint: number;
    /** Bodymovin version string. */
    version: string;
    /** Width of the animation. */
    width: number;
  };
}

// Structure for fileSize (if available)
interface FileSizeValue {
  bytes: number;
  formated: {
    exponent: number;
    symbol: string;
    unit: string;
    value: string;
  };
}

Options

The source documentation for @lottiefiles/relottie-metadata does not specify any configuration options for the plugin.

Next Steps

Last updated: April 10, 2026 at 9:12 AMEdit this page