Docs / iOS / Agora

Agora on iOS

Beautify the published camera of an Agora RTC 4.x call with an AgoraVideoFrameDelegate that processes the capture CVPixelBuffer in place.

Demo app: facevity-ios-demo on GitHub

Agora hands a video frame delegate each captured frame as a CVPixelBuffer when you ask for one. Facevity processes it in place and returns true, and Agora encodes the result, so remote users receive the beautified video.

1. Requirements

  • Facevity for iOS set up as in the quick start
  • Agora RTC SDK 4.x (pod 'AgoraRtcEngine_iOS' or the Swift package)
  • Licence feature beauty.basic (pixel buffers in place)

2. The delegate

import AgoraRtcKit
import Facevity

final class FacevityAgoraVideoFrameDelegate: NSObject, AgoraVideoFrameDelegate {
    let facevity: Facevity

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

    func getVideoFormatPreference() -> AgoraVideoFormat { .cvPixelBufferBGRA }
    func getObservedFramePosition() -> AgoraVideoFramePosition { .postCapture }
    func getRotationApplied() -> Bool { false }
    func getMirrorApplied() -> Bool { false }

    func onCapture(_ videoFrame: AgoraOutputVideoFrame, sourceType: AgoraVideoSourceType) -> Bool {
        guard facevity.isActive, let pb = videoFrame.pixelBuffer else { return true }
        // rotation: how far the raw frame turns clockwise to be upright (Agora reports it per frame)
        _ = facevity.processPixelBuffer(pb, rotation: Int(videoFrame.rotation),
                                        timestampNs: Int64(videoFrame.renderTimeMs) * 1_000_000)
        return true
    }

    func onRenderVideoFrame(_ videoFrame: AgoraOutputVideoFrame, uid: UInt, channelId: String) -> Bool { true }
}

3. Register it before joining

let beauty = try FacevityAgoraVideoFrameDelegate()   // keep a strong reference
agoraKit.setVideoFrameDelegate(beauty)
agoraKit.enableVideo()
agoraKit.startPreview()
agoraKit.joinChannel(byToken: token, channelId: channel, info: nil, uid: 0)

Change the look during the call with beauty.facevity.setParams(...), setLipstick, setProp and so on.

4. Tear down

agoraKit.setVideoFrameDelegate(nil)
agoraKit.leaveChannel(nil)
beauty.facevity.release()

Notes

  • .cvPixelBufferNV12 also works; Facevity processes BGRA and NV12 pixel buffers in place.
  • Never mirror the published frame. Agora mirrors the local preview for the front camera.

Next: ZEGOCLOUD on iOS · all platforms

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