SDK 2.0.0. Auth: Auth & License.
Auth in production
Keepapp_id / app_key on the server. Fetch a short-lived licenseToken from your backend, then pass it to the engine.
.lic.
One engine per page
Create oneBeautyEffectEngine, call init() once, reuse it for the session. Do not construct a new engine every frame.
Frame loop
- Drive video with
requestAnimationFrame, not an unboundedwhile. - Use
FrameType.Videofor camera;FrameType.Imagefor stills. - Match canvas size to the processed
ImageDatato avoid extra scaling. - Skip frames until
video.readyState >= 2andvideoWidth > 0. - Prefer
processImagefor camera and canvas.processTexturedoes not apply mirror.
Large stills (preview vs export)
For gallery photos and retouching apps, do not send full-resolution pixels intoprocessImage on every slider change. When the file opens, keep two buffers:
- Preview frame — a downscaled
ImageData(long edge about 1280–1440, or the display canvas CSS size ×devicePixelRatio, whichever is smaller). Use this while the user adjusts effects. - Original — the
HTMLImageElement(or an unscaled bitmap). RunprocessImageon it once, when the user exports.
FrameType.Image for both. Same engine, same setters. Output size matches input size: preview output is small; export output is full resolution. Do not upscale the preview result to fake an export.
Do not pass an unscaled <img> into the preview loop — processImage reads naturalWidth / naturalHeight.
FrameType.Video. Debounce slider-driven processImage. Show a busy state before export; full-resolution processing is synchronous and can hitch the page.
Parameters
Start low in real-time preview (smoothing ~ 0.2–0.5). Reshape is [-1, 1]; small values look more natural on camera.
Do not register onFaceLandmarks unless the UI needs them — it forces per-frame detection.
setBeautySkinOnly(true) avoids smearing backgrounds when smoothing is high.
Resources
- Host filter / sticker
.fbdand background jpg/png as static files; pass the URL intosetFilter/setSticker/setVirtualBackground. - Runtime resources are loaded by the SDK during
init(). Do not put a site-rootresource.fbdfor the engine. - Switch filter / sticker on user input, not every frame.
Memory
- Call
destroy()on unmount /beforeunload. - Reuse the display canvas; do not allocate a new canvas per frame.

