English | 中文
This document provides a comprehensive guide on how to quickly set up and run the Beauty API sample code.
- iOS Version: 11 and above
- Xcode Version: 13 and above
- Create an Account: Sign up at agora.io.
- Access Dashboard: Navigate to Projects > Project List.
- Save App ID: Copy your App ID for later use.
- Contact Support: Reach out to FaceUnity for the latest Beauty SDK, resources, and certificate.
- Download Resources: Extract and add the following files to your project:
Resource Files | Project Path |
---|---|
Model Files | iOS/FULib/Resources/model/*.bundle |
Graphics Files | iOS/FULib/Resources/graphics/*.bundle |
Makeup Resources (e.g., naicha.bundle) | iOS/FULib/Resources/makeup/*.bundle |
Sticker Resources (e.g., fashi.bundle) | iOS/FULib/Resources/stickers/*.bundle |
authpack.h |
iOS/BeautyAPi/FUBeauty/authpack.h |
-
Add Pod Dependency: Update your Podfile with:
pod 'fuLib', :path => 'fu.podspec'
-
Install Pods: Run the following command:
pod install
-
Configure App ID: Edit
KeyCenter.swift
:static let AppId: String = "YOUR_APP_ID"
-
Update Bundle Identifier: Change the
Bundle Identifier
in the BeautyAPI Project settings. -
Run the Project: Launch the project in Xcode.
- Include Files: Add the
iOS/BeautyAPi/BeautyAPI
directory,Render/FURender
folder, andBeautyAPI.h
&BeautyAPI.m
files to your project.
-
Update Podfile: Modify your Podfile as follows:
platform :ios, '9.0' target 'Your_App_Name' do pod 'AgoraRtcEngine_iOS', 'x.y.z' pod 'fuLib', :path => 'fu.podspec' end
-
Install Pods: Execute:
pod install
-
Initialize AgoraRtcEngineKit:
private lazy var rtcEngine: AgoraRtcEngineKit = { let config = AgoraRtcEngineConfig() config.appId = KeyCenter.AppId config.channelProfile = .liveBroadcasting let rtc = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self) rtc.setClientRole(.broadcaster) rtc.enableAudio() rtc.enableVideo() rtc.setDefaultAudioRouteToSpeakerphone(true) return rtc }()
-
Initialize Beauty API:
private lazy var fuRender = FUBeautyRender() private lazy var beautyAPI = BeautyAPI() let config = BeautyConfig() config.rtcEngine = rtcEngine config.captureMode = capture == "Custom" ? .custom : .agora config.cameraConfig = cameraConfig config.beautyRender = fuRender config.statsEnable = false config.statsDuration = 1 config.eventCallback = { stats in print("Stats: min=\(stats.minCostMs), max=\(stats.maxCostMs), avg=\(stats.averageCostMs)") } let result = beautyAPI.initialize(config) if result != 0 { print("Initialization error: \(result)") }
-
Enable Beauty Effects:
beautyAPI.enable(true)
-
Start Video Capture:
beautyAPI.setupLocalVideo(localView, renderMode: .hidden)
-
Custom Video Capture:
- Register a raw video data observer when using custom video capture:
if capture == "Custom" { rtcEngine.setVideoFrameDelegate(self) } extension BeautyViewController: AgoraVideoFrameDelegate { func onCapture(_ videoFrame: AgoraOutputVideoFrame, sourceType: AgoraVideoSourceType) -> Bool { guard let pixelBuffer = videoFrame.pixelBuffer else { return true } beautyAPI.onFrame(pixelBuffer) { pixelBuffer in videoFrame.pixelBuffer = pixelBuffer } return true } func getMirrorApplied() -> Bool { beautyAPI.getMirrorApplied() } func getObservedFramePosition() -> AgoraVideoFramePosition { .postCapture } }
-
Join a Channel:
let mediaOption = AgoraRtcChannelMediaOptions() mediaOption.clientRoleType = isBroadcast ? .broadcaster : .audience mediaOption.autoSubscribeAudio = true mediaOption.autoSubscribeVideo = true mediaOption.publishCameraTrack = mediaOption.clientRoleType == .broadcaster mediaOption.publishCustomVideoTrack = false mediaOption.publishMicrophoneTrack = mediaOption.clientRoleType == .broadcaster let result = rtcEngine.joinChannel(byToken: nil, channelId: channelName ?? "", uid: 0, mediaOptions: mediaOption) if result != 0 { print("Join channel failed") }
-
Update Camera Configuration (Optional):
beautyAPI.switchCamera() let cameraConfig = BeautyManager.shareManager.cameraConfig if self.beautyAPI?.isFrontCamera ?? false { cameraConfig.frontMirror = Configs.mirrorTypes[value] ?? .LOCAL_REMOTE } else { cameraConfig.backMirror = Configs.mirrorTypes[value] ?? .NONE } self.beautyAPI?.update(cameraConfig)
-
Leave the Channel:
rtcEngine.leaveChannel()
-
Destroy Resources:
beautyAPI.destroy() AgoraRtcEngineKit.destroy()
If you have any problems or suggestions regarding the sample projects, feel free to file an issue.
- Check our FAQ to see if your issue has been recorded.
- Dive into Agora SDK Samples to see more tutorials.
- Take a look at Agora Use Case for more complicated real use cases.
- Repositories managed by developer communities can be found at Agora Community.
- If you encounter problems during integration, feel free to ask questions in Stack Overflow.
The sample projects are under the MIT license.