From ed5ccc1dfa01e1d92e1a02eb811c6ab197cbeddd Mon Sep 17 00:00:00 2001 From: Arlin Date: Wed, 19 Jan 2022 12:44:39 +0800 Subject: [PATCH] add feature video enhancement and virtual background base on v3.6.2 --- .../Base.lproj/VideoProcess.storyboard | 280 +++++++++++++++--- .../Advanced/VideoProcess/VideoProcess.swift | 111 +++++-- .../zh-Hans.lproj/VideoProcess.strings | 56 ++-- 3 files changed, 345 insertions(+), 102 deletions(-) diff --git a/iOS/APIExample/Examples/Advanced/VideoProcess/Base.lproj/VideoProcess.storyboard b/iOS/APIExample/Examples/Advanced/VideoProcess/Base.lproj/VideoProcess.storyboard index 7575139b5..128a68f9a 100644 --- a/iOS/APIExample/Examples/Advanced/VideoProcess/Base.lproj/VideoProcess.storyboard +++ b/iOS/APIExample/Examples/Advanced/VideoProcess/Base.lproj/VideoProcess.storyboard @@ -1,9 +1,9 @@ - + - + @@ -72,7 +72,6 @@ - @@ -95,25 +94,28 @@ - + - + @@ -121,14 +123,8 @@ - - + @@ -137,13 +133,13 @@ - + @@ -152,13 +148,13 @@ - + @@ -166,42 +162,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + - + + + - - - - - - + + + + + + + + + + + + + + - - - - - + + + + + + + - - - + + + + + - + + - - - - + + diff --git a/iOS/APIExample/Examples/Advanced/VideoProcess/VideoProcess.swift b/iOS/APIExample/Examples/Advanced/VideoProcess/VideoProcess.swift index 6ceea24c7..e1d8cb302 100644 --- a/iOS/APIExample/Examples/Advanced/VideoProcess/VideoProcess.swift +++ b/iOS/APIExample/Examples/Advanced/VideoProcess/VideoProcess.swift @@ -12,9 +12,7 @@ import AGEVideoLayout class VideoProcessEntry : UIViewController { - @IBOutlet weak var joinButton: AGButton! @IBOutlet weak var channelTextField: AGTextField! - let identifier = "VideoProcess" override func viewDidLoad() { super.viewDidLoad() @@ -22,11 +20,10 @@ class VideoProcessEntry : UIViewController @IBAction func doJoinPressed(sender: AGButton) { guard let channelName = channelTextField.text else {return} - //resign channel text field channelTextField.resignFirstResponder() + let identifier = "VideoProcess" let storyBoard: UIStoryboard = UIStoryboard(name: identifier, bundle: nil) - // create new view controller every time to ensure we get a clean vc guard let newViewController = storyBoard.instantiateViewController(withIdentifier: identifier) as? BaseViewController else {return} newViewController.title = channelName newViewController.configs = ["channelName":channelName] @@ -34,30 +31,24 @@ class VideoProcessEntry : UIViewController } } + class VideoProcessMain : BaseViewController { - var localVideo = Bundle.loadVideoView(type: .local, audioOnly: false) - var remoteVideo = Bundle.loadVideoView(type: .remote, audioOnly: false) - @IBOutlet weak var container: AGEVideoContainer! - var agoraKit: AgoraRtcEngineKit! - - @IBOutlet weak var beauty: UISwitch! - @IBOutlet weak var lightness: UISwitch! - @IBOutlet weak var colorful: UISwitch! - @IBOutlet weak var denoiser: UISwitch! + @IBOutlet weak var beautySwitch: UISwitch! + @IBOutlet weak var colorEnhanceSwitch: UISwitch! + @IBOutlet weak var virtualBgSwitch: UISwitch! + @IBOutlet weak var virtualBgSegment: UISegmentedControl! - @IBOutlet weak var lightenSlider: UISlider! - @IBOutlet weak var rednessSlider: UISlider! - @IBOutlet weak var sharpnessSlider: UISlider! - @IBOutlet weak var smoothSlider: UISlider! + var agoraKit: AgoraRtcEngineKit! + var localVideo = Bundle.loadVideoView(type: .local, audioOnly: false) + var remoteVideo = Bundle.loadVideoView(type: .remote, audioOnly: false) // indicate if current instance has joined channel var isJoined: Bool = false var beautifyOption = AgoraBeautyOptions() - var skinProtect = 1.0 - var strength = 0.5 - + var colorEnhanceOption = AgoraColorEnhanceOptions() + override func viewDidLoad(){ super.viewDidLoad() // layout render view @@ -74,7 +65,7 @@ class VideoProcessMain : BaseViewController let logConfig = AgoraLogConfig() logConfig.level = .info config.logConfig = logConfig - + agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self) // get channel name from configs @@ -82,7 +73,7 @@ class VideoProcessMain : BaseViewController let resolution = GlobalSettings.shared.getSetting(key: "resolution")?.selectedOption().value as? CGSize, let fps = GlobalSettings.shared.getSetting(key: "fps")?.selectedOption().value as? AgoraVideoFrameRate, let orientation = GlobalSettings.shared.getSetting(key: "orientation")?.selectedOption().value as? AgoraVideoOutputOrientationMode else {return} - + // make myself a broadcaster agoraKit.setChannelProfile(.liveBroadcasting) agoraKit.setClientRole(.broadcaster) @@ -90,10 +81,10 @@ class VideoProcessMain : BaseViewController // enable video module and set up video encoding configs agoraKit.enableVideo() agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: resolution, - frameRate: fps, - bitrate: AgoraVideoBitrateStandard, - orientationMode: orientation)) - + frameRate: fps, + bitrate: AgoraVideoBitrateStandard, + orientationMode: orientation)) + // set up local video to render your local camera preview let videoCanvas = AgoraRtcVideoCanvas() videoCanvas.uid = 0 @@ -133,24 +124,80 @@ class VideoProcessMain : BaseViewController } } + @IBAction func onChangeBeauty(_ sender:UISwitch){ + agoraKit.setBeautyEffectOptions(sender.isOn, options: beautifyOption) + } + @IBAction func onLightenSlider(_ sender:UISlider){ beautifyOption.lighteningLevel = sender.value - agoraKit.setBeautyEffectOptions(beauty.isOn, options: beautifyOption) + agoraKit.setBeautyEffectOptions(beautySwitch.isOn, options: beautifyOption) } + @IBAction func onRednessSlider(_ sender:UISlider){ beautifyOption.rednessLevel = sender.value - agoraKit.setBeautyEffectOptions(beauty.isOn, options: beautifyOption) + agoraKit.setBeautyEffectOptions(beautySwitch.isOn, options: beautifyOption) } + @IBAction func onSharpnessSlider(_ sender:UISlider){ beautifyOption.sharpnessLevel = sender.value - agoraKit.setBeautyEffectOptions(beauty.isOn, options: beautifyOption) + agoraKit.setBeautyEffectOptions(beautySwitch.isOn, options: beautifyOption) } + @IBAction func onSmoothSlider(_ sender:UISlider){ beautifyOption.smoothnessLevel = sender.value - agoraKit.setBeautyEffectOptions(beauty.isOn, options: beautifyOption) + agoraKit.setBeautyEffectOptions(beautySwitch.isOn, options: beautifyOption) } - @IBAction func onChangeBeauty(_ sender:UISwitch){ - agoraKit.setBeautyEffectOptions(sender.isOn, options: beautifyOption) + + @IBAction func onChangeLowLightEnhance(_ sender: UISwitch) { + agoraKit.setLowlightEnhanceOptions(sender.isOn, options: nil) + } + + @IBAction func onChangeVideoDenoise(_ sender: UISwitch) { + agoraKit.setVideoDenoiserOptions(sender.isOn, options: nil) + } + + @IBAction func onChangeColorEnhance(_ sender: UISwitch) { + agoraKit.setColorEnhanceOptions(sender.isOn, options: colorEnhanceOption) + } + + @IBAction func onStrengthSlider(_ sender:UISlider){ + colorEnhanceOption.strengthLevel = sender.value; + agoraKit.setColorEnhanceOptions(colorEnhanceSwitch.isOn, options: colorEnhanceOption) + } + + @IBAction func onSkinProtectSlider(_ sender:UISlider){ + colorEnhanceOption.skinProtectLevel = sender.value; + agoraKit.setColorEnhanceOptions(colorEnhanceSwitch.isOn, options: colorEnhanceOption) + } + + @IBAction func onChangeVirtualBgSwtich(_ sender: UISwitch) { + changeVirtualBackground() + } + + @IBAction func onChangeVirtualBgSegment(_ sender: UISegmentedControl) { + changeVirtualBackground() + } + + func changeVirtualBackground() { + let source = AgoraVirtualBackgroundSource() + switch virtualBgSegment.selectedSegmentIndex { + case 0: + let imgPath = Bundle.main.path(forResource: "agora-logo", ofType: "png") + source.backgroundSourceType = .img + source.source = imgPath + break + case 1: + source.backgroundSourceType = .color + source.color = 0xFFFF + break + case 2: + source.backgroundSourceType = .blur + source.blur_degree = .high; + break + default: + break + } + agoraKit.enableVirtualBackground(virtualBgSwitch.isOn, backData: source) } } diff --git a/iOS/APIExample/Examples/Advanced/VideoProcess/zh-Hans.lproj/VideoProcess.strings b/iOS/APIExample/Examples/Advanced/VideoProcess/zh-Hans.lproj/VideoProcess.strings index fc209274c..76621ad69 100644 --- a/iOS/APIExample/Examples/Advanced/VideoProcess/zh-Hans.lproj/VideoProcess.strings +++ b/iOS/APIExample/Examples/Advanced/VideoProcess/zh-Hans.lproj/VideoProcess.strings @@ -1,51 +1,47 @@ - -/* Class = "UISwitch"; title = "Face Beautify"; ObjectID = "0lt-yn-0yl"; */ -"0lt-yn-0yl.title" = "美颜"; +/* Class = "UITextField"; placeholder = "Enter channel name"; ObjectID = "moa-hL-hhA"; */ +"moa-hL-hhA.placeholder" = "请输入频道名"; /* Class = "UIButton"; normalTitle = "Join"; ObjectID = "1Vr-cE-fQI"; */ "1Vr-cE-fQI.normalTitle" = "加入"; -/* Class = "UILabel"; text = "Lightening Enhance"; ObjectID = "2y0-8E-3Er"; */ -"2y0-8E-3Er.text" = "暗光增强"; +/* Class = "UILabel"; text = "Face Beautify"; ObjectID = "Ty6-YP-tus"; */ +"Ty6-YP-tus.text" = "美颜"; /* Class = "UILabel"; text = "Smoothness"; ObjectID = "3Cr-C9-PWm"; */ "3Cr-C9-PWm.text" = "平滑"; -/* Class = "UISwitch"; title = "Face Beautify"; ObjectID = "3jT-PF-fry"; */ -"3jT-PF-fry.title" = "美颜"; - /* Class = "UILabel"; text = "Lightening"; ObjectID = "6Yy-cm-VP3"; */ "6Yy-cm-VP3.text" = "美白"; -/* Class = "UIViewController"; title = "Simple Filter"; ObjectID = "8Zn-pj-gkm"; */ -"8Zn-pj-gkm.title" = "视频增强"; +/* Class = "UILabel"; text = "Redness"; ObjectID = "c7I-oU-1Ty"; */ +"c7I-oU-1Ty.text" = "红润"; -/* Class = "UISwitch"; title = "Face Beautify"; ObjectID = "HJK-u9-Pbi"; */ -"HJK-u9-Pbi.title" = "美颜"; +/* Class = "UILabel"; text = "Sharpness"; ObjectID = "nxu-z3-DfB"; */ +"nxu-z3-DfB.text" = "锐利"; -/* Class = "UILabel"; text = "Video Denoiser"; ObjectID = "IK4-hW-gbx"; */ -"IK4-hW-gbx.text" = "视频降噪"; +/* Class = "UILabel"; text = "Low light Enhancement"; ObjectID = "tw2-gf-2I6"; */ +"tw2-gf-2I6.text" = "暗光增强"; -/* Class = "UILabel"; text = "Colorful Enhance"; ObjectID = "Ijy-ys-cZf"; */ -"Ijy-ys-cZf.text" = "色彩增强"; +/* Class = "UILabel"; text = "Video Denoiser"; ObjectID = "147-rT-JTP"; */ +"147-rT-JTP.text" = "视频降噪"; -/* Class = "UILabel"; text = "Face Beautify"; ObjectID = "Ty6-YP-tus"; */ -"Ty6-YP-tus.text" = "美颜"; +/* Class = "UILabel"; text = "Color Enhancement"; ObjectID = "uW9-fr-9eC"; */ +"uW9-fr-9eC.text" = "色彩增强"; -/* Class = "UISwitch"; title = "Face Beautify"; ObjectID = "YBf-iq-ZSD"; */ -"YBf-iq-ZSD.title" = "美颜"; +/* Class = "UILabel"; text = "Strength"; ObjectID = "Tim-Kh-axW"; */ +"Tim-Kh-axW.text" = "强度"; -/* Class = "UILabel"; text = "Redness"; ObjectID = "c7I-oU-1Ty"; */ -"c7I-oU-1Ty.text" = "红润"; +/* Class = "UILabel"; text = "Skin Protect"; ObjectID = "OAR-9q-CrU"; */ +"OAR-9q-CrU.text" = "肤色保护"; -/* Class = "UITextField"; placeholder = "Enter channel name"; ObjectID = "moa-hL-hhA"; */ -"moa-hL-hhA.placeholder" = "请输入频道名"; +/* Class = "UILabel"; text = "Virtual Background"; ObjectID = "0N7-qv-24q"; */ +"0N7-qv-24q.text" = "虚拟背景"; -/* Class = "UILabel"; text = "Sharpness"; ObjectID = "nxu-z3-DfB"; */ -"nxu-z3-DfB.text" = "锐利"; +/* Class = "UISegmentedControl"; 64G-UU-8yO.segmentTitles[0] = "Image"; ObjectID = "64G-UU-8yO"; */ +"64G-UU-8yO.segmentTitles[0]" = "图片"; -/* Class = "UILabel"; text = "Strength"; ObjectID = "OIO-FL-y7u"; */ -"OIO-FL-y7u.text" = "强度"; +/* Class = "UISegmentedControl"; 64G-UU-8yO.segmentTitles[1] = "Color"; ObjectID = "64G-UU-8yO"; */ +"64G-UU-8yO.segmentTitles[1]" = "颜色"; -/* Class = "UILabel"; text = "Skin Protect"; ObjectID = "C1K-xQ-TKU"; */ -"C1K-xQ-TKU.text" = "肤色保护"; +/* Class = "UISegmentedControl"; 64G-UU-8yO.segmentTitles[2] = "Blur"; ObjectID = "64G-UU-8yO"; */ +"64G-UU-8yO.segmentTitles[2]" = "毛玻璃";