Resizer

interface Resizer extends HybridObject

Represents a GPU-accelerated Frame resizer and converter.

You can create instances of the Resizer via ResizerFactory.createResizer(...).

Discussion

The Resizer internally allocates a memory pool, which can grow quite large, depending on texture size. When you are done with the Resizer, it is recommended to dispose() it to free up resources.

Methods

resize()

resize(frame: Frame): GPUFrame

Resize the given frame using the options this Resizer was configured with.

Returns

A GPUFrame of the converted and resized pixel data. The returned GPUFrame must be disposed (via dispose()) to ensure the pipeline can run continuously.

Discussion

For maximum performance, the resolved CameraSessionConfig's nativePixelFormat should be 'yuv-420-8-bit-full' on iOS, and 'private' on Android. Then, set FrameOutputOptions.pixelFormat to 'native' on Android, and 'native' if the config's nativePixelFormat really is 'yuv-420-8-bit-full' (or 'yuv' otherwise) for iOS.

To configure your session with the target Pixel Format, use a PixelFormatConstraint.

For ML models that expect CHW / NCHW tensors, configure the Resizer with pixelLayout: 'planar'.

Examples

Simple resize

const resizer = ...
const frameOutput = useFrameOutput({
  pixelFormat: 'yuv',
  onFrame(frame) {
    'worklet'
    if (resizer != null) {
      const resized = resizer.resize(frame)
      const buffer = resized.getPixelBuffer()
      resized.dispose()
    }
    frame.dispose()
  }
})

Maximum performance resize

const targetPixelFormat = Platform.select<PixelFormat>({
  ios: 'yuv-420-8-bit-full',
  android: 'private'
})
const resizer = ...
const frameOutput = useFrameOutput({
  pixelFormat: 'native',
  onFrame(frame) {
    'worklet'
    if (resizer != null) {
      const resized = resizer.resize(frame)
      const buffer = resized.getPixelBuffer()
      resized.dispose()
    }
    frame.dispose()
  }
})
const constraints: Constraint[] = [
  { pixelFormat: targetPixelFormat }
]

On this page