Skip to main content
react-native-media-transformerv0.1.0
Getting startedQuick start

Quick start

Pass a readable local video from your app's picker or storage integration. Android also accepts a granted content:// URI. This helper compresses the video, reads the output metadata, and creates a JPEG preview. Call it from your app's start action.

TypeScript
import {
  compress,
  getVideoMetadata,
  createThumbnail,
} from "react-native-media-transformer";

export async function prepareVideo(inputUri: string) {
  try {
    const outputPath = await compress(
      inputUri,
      { quality: "medium", maxHeight: 720 },
      (progress) => console.log(`${Math.round(progress * 100)}%`),
    );
    const info = await getVideoMetadata(outputPath);
    const thumbnail = await createThumbnail(outputPath, {
      maxWidth: 480,
      maxHeight: 320,
    });
    return {
      outputPath,
      info,
      thumbnail,
      thumbnailUri: `file://${thumbnail.path}`,
    };
  } catch (error) {
    console.error("Video processing failed:", error);
    return null;
  }
}

Use the returned thumbnailUri with a React Native Image source. Outputs are absolute local cache paths; add file:// when a display component needs a URI. Copy outputs to permanent storage to keep them.

Units throughout this guide: times in seconds, sizes in bytes, dimensions in displayed pixels, and bitrates in bits per second. progressInterval uses milliseconds; export progress is a fraction from 0 to 1.