GuidesAPI Reference

API Reference

The entire public surface is one function, one result type, and one error class.

import { createThumbnail, ThumbnailError } from 'react-native-nitro-thumbnail';
import type { CreateThumbnailOptions, Thumbnail, ThumbnailErrorCode } from 'react-native-nitro-thumbnail';
ExportKindSummary
createThumbnailfunctionGenerate a thumbnail. Returns Promise<Thumbnail>.
ThumbnailErrorclassTyped error (extends Error) with a .code.
CreateThumbnailOptionstypeThe options object you pass in.
ThumbnailtypeThe result object you get back.
ThumbnailErrorCodetypeUnion of the seven possible error codes.
VideoThumbnailcomponentOptional ready-made tile (server-first, shimmer, play button). See Recipes.
VideoThumbnailPropstypeProps for VideoThumbnail.
default exportobject{ createThumbnail } — for drop-in compatibility.

createThumbnail(options)

function createThumbnail(options: CreateThumbnailOptions): Promise<Thumbnail>;

Extracts a single frame from a local or remote video, scales it to fit your bounds, encodes it to JPEG or PNG, writes it to the platform cache directory, and resolves with metadata about the file.

Options

interface CreateThumbnailOptions {
  url: string;
  timeStamp?: number;
  format?: 'jpeg' | 'png';
  maxWidth?: number;
  maxHeight?: number;
  quality?: number;
  cacheName?: string;
  dirSize?: number;
  headers?: Record<string, string>;
  timeToleranceMs?: number;
  onlySyncedFrames?: boolean;
}
OptionTypeDefaultDescription
urlstringrequiredA local file:// URL, an absolute path (/…), or a remote http(s):// URL.
timeStampnumber0The frame to capture, in milliseconds. 1000 = the frame at 1.0 s.
format'jpeg' | 'png''jpeg'Output encoding.
maxWidthnumber512Upper bound on output width. Aspect ratio preserved; never upscaled.
maxHeightnumber512Upper bound on output height. Aspect ratio preserved; never upscaled.
qualitynumber0.9JPEG quality in 0..1 (clamped). Ignored for PNG (lossless).
cacheNamestringDeterministic output filename. If a file with this name exists, it’s returned without re-decoding. See Caching.
dirSizenumber100Cache cap in MB. After each write, oldest thumbnails are evicted (LRU) until under the cap.
headersRecord<string, string>HTTP headers sent when fetching a remote video. Values must be strings.
timeToleranceMsnumber2000How far from timeStamp the decoder may pick a frame. Larger = faster, less exact.
onlySyncedFramesbooleantruePrefer the nearest keyframe (faster decode, slightly less precise timestamp).
🌐

Platform note: cacheName and dirSize are no-ops on Web — browsers have no persistent disk cache the library can manage, so each call produces a fresh in-memory object URL.

How sizing works

maxWidth and maxHeight define a box. The frame is scaled down to fit inside that box while preserving its aspect ratio, and never enlarged:

scale = min(maxWidth / sourceWidth, maxHeight / sourceHeight, 1)

A 1280×720 frame with the default 512×512 box becomes 512×288. A 320×240 frame with the same box stays 320×240 (it already fits — no upscaling). The width/height in the result are the actual output dimensions.

Result — Thumbnail

interface Thumbnail {
  path: string;   // native: file:// URL · web: blob: object URL
  size: number;   // file size in bytes
  mime: string;   // 'image/jpeg' | 'image/png'
  width: number;  // actual output width  (≤ maxWidth)
  height: number; // actual output height (≤ maxHeight)
}
FieldTypeNotes
pathstringOn native, a file:// URL inside the app cache directory. On web, an object URL — call URL.revokeObjectURL(path) when done.
sizenumberEncoded file size in bytes.
mimestring'image/jpeg' or 'image/png'.
widthnumberActual width of the produced image.
heightnumberActual height of the produced image.

Use it directly as an image source:

const thumb = await createThumbnail({ url });
 
<Image source={{ uri: thumb.path }} style={{ width: thumb.width, height: thumb.height }} />;

ThumbnailError

class ThumbnailError extends Error {
  code: ThumbnailErrorCode;
}

Every rejection from createThumbnail is a ThumbnailError. Because it extends the built-in Error, existing try/catch and logging keep working — you just also get a typed .code to branch on.

try {
  await createThumbnail({ url });
} catch (e) {
  if (e instanceof ThumbnailError) {
    switch (e.code) {
      case 'FILE_NOT_FOUND':      /* show "video missing" */ break;
      case 'REMOTE_FETCH_FAILED': /* offer retry */          break;
      default:                    /* log e.message */
    }
  }
}

The seven codes and what they mean are documented in Error Handling → The error codes.

Quick recipes

Capture at a specific time, as PNG

await createThumbnail({ url, timeStamp: 2500, format: 'png' });

Remote video behind auth

await createThumbnail({
  url: 'https://media.example.com/clip.mp4',
  headers: { Authorization: `Bearer ${token}` },
});

Small avatar-sized JPEG with aggressive compression

await createThumbnail({ url, maxWidth: 96, maxHeight: 96, quality: 0.6 });

Stable, reusable poster (decode once, reuse forever)

await createThumbnail({ url, cacheName: `poster-${videoId}` });