Nosmai  Effects Nosmai  Moderation Nosmai Try-ons coming soon
Docs menu iOS
How-to guide

Process external frames on iOS

Send BGRA pixel buffers through the Nosmai off-screen pipeline and receive processed output for your own encoder or renderer.

Platform iOS SDK version 3.0.4 Updated Aug 22, 2026 Time 7 min

Prerequisites

  • A working iOS quickstart
  • An app-owned BGRA CVPixelBuffer source with stable dimensions

When to use this guide

Use off-screen mode when the host supplies external frames. If Nosmai owns the camera and another component only needs processed output, use NosmaiCore.liveFrameStreamCallback instead.

Prepare the output callback

NosmaiSDK *sdk = [NosmaiSDK sharedInstance];

[sdk setCVPixelBufferCallback:^(CVPixelBufferRef output, double timestamp) {
    CVPixelBufferRetain(output);
    dispatch_async(encoderQueue, ^{
        [consumer consumePixelBuffer:output timestamp:timestamp];
        CVPixelBufferRelease(output);
    });
}];

Retain the output only when the consumer continues after the callback returns.

Initialize off-screen mode

BOOL ready = [sdk initializeOffscreenWithWidth:width height:height];
if (ready) {
    [sdk setProcessingMode:NosmaiProcessingModeOffscreen];
}

Input buffers must use kCVPixelFormatType_32BGRA and keep stable dimensions.

Submit a frame

BOOL accepted = [sdk processFrame:inputPixelBuffer mirror:NO];

You can pass a CMSampleBufferRef with processSampleBuffer:mirror:. For asynchronous submission, retain the input until processFrameAsync:mirror:completion: finishes.

Return to live camera mode

Stop the external source first, then clear its callback:

[sdk setCVPixelBufferCallback:nil];
[sdk setProcessingMode:NosmaiProcessingModeLive];

Verify it worked

Apply a visible effect and confirm the output buffer orientation, colors, timestamps, and ownership on a physical device. Use getProcessingMetrics during development to inspect processed and dropped frames.

Common errors

SymptomCauseFix
processFrame returns NOOff-screen mode is not ready or the pixel format is unsupportedInitialize the exact dimensions and submit kCVPixelFormatType_32BGRA
Output crashes after the callbackThe consumer kept a borrowed buffer without retaining itRetain before asynchronous use and release after consumption

Next steps

References

Was this page helpful?

Your response helps us prioritize documentation improvements.

Nosmai

An AR and AI company. Founded on the idea that the next decade of software will be visual, and that the tools for it should be within reach of anyone building.

Newsletter

Product updates and release notes. No spam.

© 2026 nosmai, inc · all rights reserved