Skip to content

Commit 5e2dc48

Browse files
authored
Create video-effects-javascript.md
1 parent 4435c12 commit 5e2dc48

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
## Prerequisites
18+
- 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.
19+
20+
## Using video effects
21+
### Install the package
22+
Use the `npm install` command to install the Azure Communication Services Effects SDK for JavaScript.
23+
> [!IMPORTANT]
24+
> 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`.
25+
```console
26+
npm install @azure/communication-calling-effects --save
27+
```
28+
29+
> [!NOTE]
30+
> Currently there are two available video effects:
31+
> - Background blur
32+
> - Background replacement with an image
33+
>
34+
35+
To use video effects with the Azure Communication Calling SDK, once you have created a `LocalVideoStream`, you need to get the `VideoEffects` feature API of the `LocalVideoStream` to start/stop video effects:
36+
```js
37+
import * as AzureCommunicationCallingSDK from '@azure/communication-calling';
38+
39+
import { BackgroundBlurEffect, BackgroundReplacementEffect } from '@azure/communication-calling-effects';
40+
41+
// Get the video effects feature api on the LocalVideoStream
42+
// (here, localVideoStream is the LocalVideoStream object you created while setting up video calling)
43+
const videoEffectsFeatureApi = localVideoStream.features(AzureCommunicationCallingSDK.Features.VideoEffects);
44+
45+
46+
// Subscribe to useful events
47+
videoEffectsFeatureApi.on(‘effectsStarted’, () => {
48+
// Effects started
49+
});
50+
51+
videoEffectsFeatureApi.on(‘effectsStopped’, () => {
52+
// Effects stopped
53+
});
54+
55+
videoEffectsFeatureApi.on(‘effectsError’, (error) => {
56+
// Effects error
57+
});
58+
```
59+
60+
### Background blur:
61+
```js
62+
// Create the effect instance
63+
const backgroundBlurEffect = new BackgroundBlurEffect();
64+
65+
// Recommended: Check support
66+
const backgroundBlurSupported = await backgroundBlurEffect.isSupported();
67+
68+
if (backgroundBlurSupported) {
69+
// Use the video effects feature api we created to start effects
70+
await videoEffectsFeatureApi.startEffects(backgroundBlurEffect);
71+
}
72+
```
73+
74+
### Background replacement with an image:
75+
You need to provide the URL of the image you want as the background to this effect.
76+
> [!IMPORTANT]
77+
> The `startEffects` method will fail if the URL is not of an image or is unreachable/unreadable.
78+
>
79+
80+
> [!NOTE]
81+
> Current supported image formats are: png, jpg, jpeg, tiff, bmp.
82+
>
83+
84+
```js
85+
const backgroundImage = 'https://linkToImageFile';
86+
87+
// Create the effect instance
88+
const backgroundReplacementEffect = new BackgroundReplacementEffect({
89+
backgroundImageUrl: backgroundImage
90+
});
91+
92+
// Recommended: Check support
93+
const backgroundReplacementSupported = await backgroundReplacementEffect.isSupported();
94+
95+
if (backgroundReplacementSupported) {
96+
// Use the video effects feature api as before to start/stop effects
97+
await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect);
98+
}
99+
```
100+
101+
Changing the image for this effect can be done by passing it in in the configure method:
102+
```js
103+
const newBackgroundImage = 'https://linkToNewImageFile';
104+
105+
await backgroundReplacementEffect.configure({
106+
backgroundImageUrl: newBackgroundImage
107+
});
108+
```
109+
110+
Switching effects can be done using the same method on the video effects feature api:
111+
```js
112+
// Switch to background blur
113+
await videoEffectsFeatureApi.startEffects(backgroundBlurEffect);
114+
115+
// Switch to background replacement
116+
await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect);
117+
```
118+
119+
To stop effects:
120+
```js
121+
await videoEffectsFeatureApi.stopEffects();
122+
```

0 commit comments

Comments
 (0)