This page matches SDK 2.0.0. Makeup / reshape enums: Parameter enums.
Choose the right frame type
SetFBImageFrame.type before processImage:. There is no process-mode argument on the engine.
FBFrameTypeVideo(1): camera preview, live, calls — lower latency.FBFrameTypeImage(0): still photos — higher quality.
Large stills (preview vs export)
Do not feed full-resolution pixels intoprocessImage: on every slider change, and do not throw the original away after scaling.
When the photo opens, keep the full UIImage and build one preview frame (long edge about 1280–1440, createWithUIImage:). Slider changes process the preview (FBFrameTypeImage). Export processes a full-resolution frame with the same setters. Output size matches the input. Camera preview stays capture resolution + FBFrameTypeVideo.
Parameter ranges
- Skin / makeup / filter intensity:
[0.0, 1.0].0turns that effect off. - Reshape (
setReshape:intensity:):[-1.0, 1.0].0is off. Positive and negative are opposite directions.
One engine, one serial queue
createEngineWithConfig: returns an instance, not a process-wide singleton. Keep one engine per session and call it from a serial queue (or the GL thread when externalContext = YES).
Memory
- Prefer ARC. Drop
FBImageFramereferences when a frame is done. - Reuse pixel buffers from the camera; avoid allocating a new RGBA buffer every frame if the capture format is already NV12 / BGRA.
- Filters and stickers load on the next
processImage:(GL thread). Do not reload the same.fbdevery frame — callsetFilter:/setSticker:once, thensetFilterIntensity:as needed. - Use
clearFilter,clearSticker,clearVirtualBackground, andclearChromaKeyinstead of creating a second engine.
External OpenGL ES
When the app already owns a GL context:- Set
config.externalContext = YES. - Create the engine on that GL thread.
- Wrap the texture with
createWithTexture:width:height:stride:. - Read the output with
[output texture].
Monitor with getStats
Prefer FBEngineStats over a homemade timer:
avgProcessTimeMs under ~33 ms at 30 fps. If it climbs, drop resolution, switch to FBFrameTypeVideo, or turn off unused makeup / stickers.
Lifecycle
Hold the engine as a strong property on the view controller (or a session object). Nil it indealloc when the session ends. Pause capture in viewWillDisappear / applicationDidEnterBackground so you stop calling processImage: — you do not need a special “pause” API.
__weak in FBEngineCallbacks blocks to avoid retain cycles.
iOS capture
- Camera preview is usually
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange(NV12) or BGRA. CreateFBImageFramewithcreateWithNV12:...orcreateWithBGRA:...instead of converting to RGBA on the CPU. - Front camera:
setMirror:@"horizontal"on the frame (ormirror:if you need the pixels flipped before the engine). - Camera permission:
NSCameraUsageDescriptioninInfo.plist. Photo library:NSPhotoLibraryUsageDescriptionif you pick stills.
Testing
- Bind the test app’s Bundle ID and use a real
appId/appKeyorlicenseToken. Dummy strings fail with license events1/101. - Cover still (
FBFrameTypeImage+createWithUIImage:) and live (FBFrameTypeVideo) paths. - Assert setter return codes are
FBErrorCode_Success.

