From fbc7408e573121489e579acf44e7898cce1aeba3 Mon Sep 17 00:00:00 2001 From: Pawan Dixit <103245157+pawan-100ms@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:53:15 +0400 Subject: [PATCH] Create video-filters.mdx (#1993) * Create video-filters.mdx * Update video-filters.mdx * Update video-filters.mdx * Update video-filters.mdx * Update video-filters.mdx --- .../plugins/video-filters.mdx | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 docs/ios/v2/how-to-guides/extend-capabilities/plugins/video-filters.mdx diff --git a/docs/ios/v2/how-to-guides/extend-capabilities/plugins/video-filters.mdx b/docs/ios/v2/how-to-guides/extend-capabilities/plugins/video-filters.mdx new file mode 100644 index 0000000000..350c2b61f0 --- /dev/null +++ b/docs/ios/v2/how-to-guides/extend-capabilities/plugins/video-filters.mdx @@ -0,0 +1,129 @@ +--- +title: Video Filters (Beta) +nav: 12.3 +--- + +The HMSVideoFilterPlugin is a customizable video filter plugin designed to allow developers to apply various filters to a video stream in real-time. This plugin utilizes several Core Image filters to apply different effects to the video content. Below is the documentation for the parameters available to adjust in the HMSVideoFilterPlugin. + +## Minimum Requirements +- Minimum 100ms SDK version required is `1.5.0` + +## How to enable video filters in your app using HMSSDK + +1. Create an HMSVideoPlugin array + +```swift + var videoPlugins = [HMSVideoPlugin]() +``` + +2. Create an instance of HMSVideoFilterPlugin, activate it and append it to videoPlugins array, like below + +```swift + let videoFilterPlugin = HMSVideoFilterPlugin() + videoFilterPlugin?.activate() + videoPlugins.append(videoFilterPlugin) +``` + +3. Set videoPlugins instance while setting the trackSettings on HMSSDK + +```swift + hmsSDK = HMSSDK.build { sdk in + sdk.trackSettings = HMSTrackSettings.build { videoSettingsBuilder, audioSettingsBuilder in + videoSettingsBuilder.videoPlugins = self.videoPlugins + } + ... + } +``` + +That is all you need to do to enable video filters! + +## How to enable and disable video filters + +Hold on to a reference to the instance of HMSVideoFilterPlugin and use activate and deactivate functions on it to enable/disable the video filters. + +```swift + var videoFilterPlugin: HMSVideoPlugin? + + func setupPlugins() { + videoFilterPlugin = HMSVideoFilterPlugin() + ... + } + + func toggleVideoFilters() { + let isVideoFiltersActivated = UserDefaults.standard.bool(forKey: "VideoFilterPluginEnabled") + + if isVBActivated { + self?.interactor.videoFilterPlugin?.deactivate() + UserDefaults.standard.set(false, forKey: "VideoFilterPluginEnabled") + } + else { + _ = self?.interactor.videoFilterPlugin?.activate() + UserDefaults.standard.set(true, forKey: "VideoFilterPluginEnabled") + } + } +``` + +## How to adjust video filter paramerters + +let's take a look at the method signature of `HMSVideoFilterPlugin`. + +### Set Brightness + +Adjust brightness of the video. Value is from `0` to `1` default is `0.5`. + +```swift +videoFilterPlugin.brightness = 1 +``` + +### Set Contrast + +Adjust contrast of the video. Value is from `0` to `infinity` default is `1`. + +```swift +videoFilterPlugin.contrast = 2 +``` + +### Set Sharpeness + +Adjust sharpness of the video. Value is from `0` to `infinite` default is `0`. + +```swift +videoFilterPlugin.sharpness = 1 +``` + +### Set Redness + +Adjust redness in the video. Value is from `0` to `infinite` default is `1`. + +```swift +videoFilterPlugin.redness = 2 +``` + +### Set Smoothness + +Adjust smoothness in the video. Value is from `0` to `infinite` default is `0`. + +## I want to apply my own set of core image filters. How can I do that + +You can add your core image filtering logic in **coreImageTransformers** property of videoFilterPlugin like below. For example let's increase the exposure of the video. + +```swift +videoFilterPlugin?.coreImageTransformers = [{ inputImage in + + var outputImage: CIImage? + + if let filter = CIFilter(name: "CIExposureAdjust") { + + // Set input image + filter.setValue(inputImage, forKey: kCIInputImageKey) + + // Set exposure value + filter.setValue(2, forKey: "inputEV") + + // Get filtered image + outputImage = filter.outputImage + } + + return outputImage ?? inputImage +}] +```