Skip to Content
Video measurementUse your own camera pipeline

Use your own camera pipeline

Use custom frames on Android or iOS when your app already operates the camera and you want to use that same feed for a scan. Your app starts and stops capture, then passes uncompressed frames to the SDK. If the SDK manages your camera, you can skip this setup.

On the web, pass your existing MediaStream to setMediaStream(stream, facingUser) after initialization. On headless Linux, use the frame input API for C or Python.

Android and iOS

Select custom frames mode when you initialize the session. Once initialization succeeds, submit each frame from your capture callback.

import ShenaiSDK let settings = InitializationSettings() settings.cameraMode = .customFrames let result = ShenaiSDK.initialize(credential, userID: userId, settings: settings)

In your capture callback, pass the packed I420 data and its dimensions in pixels.

let metadata = FrameMetadata() metadata.timestampUs = captureTimestampUs metadata.cameraFacingUser = isFrontFacingCamera let accepted = ShenaiSDK.handleNextFrame(i420FrameData, width: width, height: height, metadata: metadata)

If capture restarts during the same SDK session, call ShenaiSDK.setCameraMode(.customFrames) once before submitting frames from the new feed.

A return value of true means the SDK accepted the frame for processing. If frames are consistently rejected, check that the session is initialized, custom frames mode is active, and the buffer matches the dimensions below. Stop submitting frames when you deinitialize the SDK.

Frame format and timing

  • Pixel format. Supply 8-bit I420 in one contiguous buffer. Put the full-resolution Y plane first, then U and V at half the width and height. Width and height must both be positive and even. A packed frame uses width × height × 3 / 2 bytes. If the camera delivers padded planes or interleaved chroma (such as NV12 or NV21), repack them as I420 first.
  • Capture time. Supply the frame’s monotonic capture timestamp in microseconds. If you omit it or pass a negative value, the SDK assigns a timestamp at submission. Prefer the capture timestamp when frames can be delayed in transit from the camera. Aim for a steady 30 frames per second or higher and at least 640 × 480 pixels. See system requirements.
  • Rotation and size. Pass the dimensions of the buffer you submit. The native SDK first applies rotation, then resizes to frameWidth and frameHeight when both are set at initialization. If you already rotate or resize frames in your pipeline, leave the corresponding SDK settings at their defaults to avoid applying the transformation twice.

Flutter, React Native, Capacitor, and MAUI

Choose the camera mode in your framework’s initialization settings. Then submit frames from the native capture callback using the Android or iOS example. This keeps frame buffers in native code. Initialize the SDK once through the framework and use that session for frame submission.

FrameworkInitialization setting
FluttercameraMode: CameraMode.customFrames
React Native and CapacitorcameraMode: CameraMode.CUSTOM_FRAMES
MAUICameraMode = CameraMode.CUSTOM_FRAMES