Video Filters (Beta)

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
var videoPlugins = [HMSVideoPlugin]()
  1. Create an instance of HMSVideoFilterPlugin, activate it and append it to videoPlugins array, like below
let videoFilterPlugin = HMSVideoFilterPlugin() videoFilterPlugin?.activate() videoPlugins.append(videoFilterPlugin)
  1. Set videoPlugins instance while setting the trackSettings on HMSSDK
hmsSDK = { sdk in sdk.trackSettings = { 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.

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.

videoFilterPlugin.brightness = 1

Set Contrast

Adjust contrast of the video. Value is from 0 to infinity default is 1.

videoFilterPlugin.contrast = 2

Set Sharpeness

Adjust sharpness of the video. Value is from 0 to infinite default is 0.

videoFilterPlugin.sharpness = 1

Set Redness

Adjust redness in the video. Value is from 0 to infinite default is 1.

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.

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 }]

Have a suggestion? Recommend changes ->

Was this helpful?