|
| 1 | +--- |
| 2 | +title: Quickstart - Add video effects to your video calls (Web) |
| 3 | +titleSuffix: An Azure Communication Services quickstart |
| 4 | +description: Learn how to add video effects in your video calls using Azure Communication Services. |
| 5 | +author: sloanster |
| 6 | + |
| 7 | +ms.author: micahvivion |
| 8 | +ms.date: 01/09/2023 |
| 9 | +ms.topic: quickstart |
| 10 | +ms.service: azure-communication-services |
| 11 | +ms.subservice: calling |
| 12 | +ms.custom: mode-other |
| 13 | +--- |
| 14 | + |
| 15 | +You can use the Video effects feature to add effects to your video in video calls. |
| 16 | + |
| 17 | +>[!IMPORTANT] |
| 18 | +> The Calling Video effects are available starting on the public preview version [1.9.1-beta.1](https://www.npmjs.com/package/@azure/communication-calling/v/1.9.1-beta.1) of the Calling SDK. Please ensure that you use this or a newer SDK when using video effects. |
| 19 | +
|
| 20 | +> [!NOTE] |
| 21 | +> This API is provided as a preview ('beta') for developers and may change based on feedback that we receive. |
| 22 | +
|
| 23 | +> [!NOTE] |
| 24 | +> The calling effect library cannot be used standalone and can only work when used with the Azure Communication Calling client library for WebJS (https://www.npmjs.com/package/@azure/communication-calling). |
| 25 | +
|
| 26 | +## Prerequisites |
| 27 | +- Setup Azure Communication Services to be able to start video calls. [Follow this guide](../video-calling/video-calling-javascript.md). You'll need the `LocalVideoStream` to be able to start effects. |
| 28 | + |
| 29 | +## Using video effects |
| 30 | +### Install the package |
| 31 | +Use the `npm install` command to install the Azure Communication Services Effects SDK for JavaScript. |
| 32 | +> [!IMPORTANT] |
| 33 | +> This quickstart uses the Azure Communication Services Calling SDK version greater than `1.10.0` and the Azure Communication Services Calling Effects SDK version greater than `1.0.0`. |
| 34 | +```console |
| 35 | +npm install @azure/communication-calling-effects --save |
| 36 | +``` |
| 37 | + |
| 38 | +> [!NOTE] |
| 39 | +> Currently there are two available video effects: |
| 40 | +> - Background blur |
| 41 | +> - Background replacement with an image |
| 42 | +> |
| 43 | +
|
| 44 | +To use video effects with the Azure Communication Calling SDK, once you've created a `LocalVideoStream`, you need to get the `VideoEffects` feature API of the `LocalVideoStream` to start/stop video effects: |
| 45 | +```js |
| 46 | +import * as AzureCommunicationCallingSDK from '@azure/communication-calling'; |
| 47 | + |
| 48 | +import { BackgroundBlurEffect, BackgroundReplacementEffect } from '@azure/communication-calling-effects'; |
| 49 | + |
| 50 | +// Get the video effects feature api on the LocalVideoStream |
| 51 | +// (here, localVideoStream is the LocalVideoStream object you created while setting up video calling) |
| 52 | +const videoEffectsFeatureApi = localVideoStream.features(AzureCommunicationCallingSDK.Features.VideoEffects); |
| 53 | + |
| 54 | + |
| 55 | +// Subscribe to useful events |
| 56 | +videoEffectsFeatureApi.on(‘effectsStarted’, () => { |
| 57 | + // Effects started |
| 58 | +}); |
| 59 | + |
| 60 | +videoEffectsFeatureApi.on(‘effectsStopped’, () => { |
| 61 | + // Effects stopped |
| 62 | +}); |
| 63 | + |
| 64 | +videoEffectsFeatureApi.on(‘effectsError’, (error) => { |
| 65 | + // Effects error |
| 66 | +}); |
| 67 | +``` |
| 68 | + |
| 69 | +### Background blur: |
| 70 | +```js |
| 71 | +// Create the effect instance |
| 72 | +const backgroundBlurEffect = new BackgroundBlurEffect(); |
| 73 | + |
| 74 | +// Recommended: Check support |
| 75 | +const backgroundBlurSupported = await backgroundBlurEffect.isSupported(); |
| 76 | + |
| 77 | +if (backgroundBlurSupported) { |
| 78 | + // Use the video effects feature api we created to start effects |
| 79 | + await videoEffectsFeatureApi.startEffects(backgroundBlurEffect); |
| 80 | +} |
| 81 | +``` |
| 82 | + |
| 83 | +### Background replacement with an image: |
| 84 | +You need to provide the URL of the image you want as the background to this effect. |
| 85 | +> [!IMPORTANT] |
| 86 | +> The `startEffects` method will fail if the URL is not of an image or is unreachable/unreadable. |
| 87 | +> |
| 88 | +
|
| 89 | +> [!NOTE] |
| 90 | +> Current supported image formats are: png, jpg, jpeg, tiff, bmp. |
| 91 | +> |
| 92 | +
|
| 93 | +```js |
| 94 | +const backgroundImage = 'https://linkToImageFile'; |
| 95 | + |
| 96 | +// Create the effect instance |
| 97 | +const backgroundReplacementEffect = new BackgroundReplacementEffect({ |
| 98 | + backgroundImageUrl: backgroundImage |
| 99 | +}); |
| 100 | + |
| 101 | +// Recommended: Check support |
| 102 | +const backgroundReplacementSupported = await backgroundReplacementEffect.isSupported(); |
| 103 | + |
| 104 | +if (backgroundReplacementSupported) { |
| 105 | + // Use the video effects feature api as before to start/stop effects |
| 106 | + await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect); |
| 107 | +} |
| 108 | +``` |
| 109 | + |
| 110 | +Changing the image for this effect can be done by passing it via the configure method: |
| 111 | +```js |
| 112 | +const newBackgroundImage = 'https://linkToNewImageFile'; |
| 113 | + |
| 114 | +await backgroundReplacementEffect.configure({ |
| 115 | + backgroundImageUrl: newBackgroundImage |
| 116 | +}); |
| 117 | +``` |
| 118 | + |
| 119 | +Switching effects can be done using the same method on the video effects feature api: |
| 120 | +```js |
| 121 | +// Switch to background blur |
| 122 | +await videoEffectsFeatureApi.startEffects(backgroundBlurEffect); |
| 123 | + |
| 124 | +// Switch to background replacement |
| 125 | +await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect); |
| 126 | +``` |
| 127 | + |
| 128 | +To stop effects: |
| 129 | +```js |
| 130 | +await videoEffectsFeatureApi.stopEffects(); |
| 131 | +``` |
0 commit comments