Docs / iOS / LiveKit

LiveKit on iOS

Beautify a LiveKit Swift camera track with a VideoProcessor that processes each CVPixelBuffer in place.

Demo app: facevity-ios-demo on GitHub

LiveKit’s Swift SDK lets a VideoProcessor see every camera frame before it is encoded. Facevity processes the frame’s pixel buffer in place and returns the same frame.

1. Requirements

  • Facevity for iOS set up as in the quick start
  • LiveKit Swift SDK 2.x (client-sdk-swift)
  • Licence feature beauty.basic

2. The processor

import LiveKit
import Facevity

final class FacevityLiveKitProcessor: NSObject, VideoProcessor {
    let facevity: Facevity

    init(options: FacevityOptions = FacevityOptions()) throws {
        facevity = try Facevity.initialize(options)
        facevity.setParams(.NATURAL)
        super.init()
    }

    func process(frame: VideoFrame) -> VideoFrame? {
        guard facevity.isActive, let buffer = frame.buffer as? CVPixelVideoBuffer else { return frame }
        _ = facevity.processPixelBuffer(buffer.pixelBuffer, rotation: frame.rotation.degrees,
                                        timestampNs: frame.timeStampNs)
        return frame
    }
}

private extension VideoRotation {
    var degrees: Int {
        switch self { case ._0: return 0; case ._90: return 90; case ._180: return 180; case ._270: return 270
        @unknown default: return 0 }
    }
}

3. Create the camera track with it

let beauty = try FacevityLiveKitProcessor()
let track = LocalVideoTrack.createCameraTrack(options: CameraCaptureOptions(), processor: beauty)
try await room.localParticipant.publish(videoTrack: track)

Beauty settings (beauty.facevity.setParams(...), setProp, …) apply to the published track live.

4. Tear down

try await room.localParticipant.unpublishAll()
beauty.facevity.release()

Notes

  • After a camera switch call beauty.facevity.resetTracking() so faces fade back in cleanly.
  • setBeautyEnabled(false) turns the effect off without touching the track: frames pass through untouched.

Next: WebRTC on iOS · all platforms

Need help with an integration? Contact the Facevity team. We answer integration questions during trials.