Skip to content

Commit

Permalink
Create video-filters.mdx (#1993)
Browse files Browse the repository at this point in the history
* Create video-filters.mdx

* Update video-filters.mdx

* Update video-filters.mdx

* Update video-filters.mdx

* Update video-filters.mdx
  • Loading branch information
pawan-100ms authored Feb 9, 2024
1 parent 5908a3d commit fbc7408
Showing 1 changed file with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}]
```

0 comments on commit fbc7408

Please sign in to comment.