Skip to content

Commit 5db7366

Browse files
Merge pull request #221409 from sloanster/patch-8
Create video-effects.md
2 parents 02e5a04 + 680f146 commit 5db7366

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
ms.author: micahvivion
3+
title: Azure Communication Services Calling video WebJS video effects
4+
titleSuffix: An Azure Communication Services document
5+
description: In this document, you'll learn how to create video effects on an Azure Communication Services call.
6+
author: sloanster
7+
services: azure-communication-services
8+
9+
ms.date: 1/9/2023
10+
ms.topic: conceptual
11+
ms.service: azure-communication-services
12+
ms.subservice: calling
13+
---
14+
15+
# Adding visual effects to a video call
16+
17+
[!INCLUDE [Public Preview](../../includes/public-preview-include-document.md)]
18+
19+
>[!IMPORTANT]
20+
> 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.
21+
22+
> [!NOTE]
23+
> This API is provided as a preview ('beta') for developers and may change based on feedback that we receive.
24+
25+
> [!NOTE]
26+
> This 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).
27+
28+
The Azure Communication Calling SDK allows you to create video effects that other users on a call will be able to see. For example, for a user doing ACS calling using the WebJS SDK you can now enable that the user can turn on background blur. When background blur enabled a user can feel more comfortable in doing a video call that the output video will just show a user and all other content will be blurred.
29+
30+
## Prerequisites
31+
### Install the Azure Communication Services Calling SDK
32+
- An Azure account with an active subscription is required. See [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) on how to create an Azure account.
33+
- [Node.js](https://nodejs.org/) active Long Term Support(LTS) versions are recommended.
34+
- An active Communication Services resource. [Create a Communication Services resource](../../quickstarts/create-communication-resource.md).
35+
- A User Access Token to instantiate a call client. Learn how to [create and manage user access tokens](../../quickstarts/access-tokens.md). You can also use the Azure CLI and run the command below with your connection string to create a user and an access token. (Need to grab connection string from the resource through Azure portal.)
36+
- Azure Communication Calling client library is properly set up and configured (https://www.npmjs.com/package/@azure/communication-calling).
37+
38+
An example using the Azure CLI to
39+
```azurecli-interactive
40+
az communication identity token issue --scope voip --connection-string "yourConnectionString"
41+
```
42+
For details on using the CLI, see [Use Azure CLI to Create and Manage Access Tokens](../../quickstarts/access-tokens.md?pivots=platform-azcli).
43+
44+
## Install the Calling effects SDK
45+
Use ‘npm install’ command to install the Azure Communication Calling Effects SDK for JavaScript.
46+
47+
'npm install @azure/communication-calling-effects –save'
48+
49+
## Supported video effects:
50+
Currently the video effects support the following ability:
51+
- Background blur
52+
- Replace the background with a custom image
53+
54+
## Browser support:
55+
56+
Currently creating video effects is only supported on Chrome Desktop Browser and Mac Safari Desktop.
57+
58+
## Class model:
59+
60+
| Name | Description |
61+
|---|---|
62+
| BackgroundBlurEffect | The background blur effect class. |
63+
| BackgroundReplacementEffect | The background replacement with image effect class. |
64+
65+
To use video effects with the Azure Communication Calling client library, once you've created a LocalVideoStream, you need to get the VideoEffects feature API of from the LocalVideoStream.
66+
67+
### Code examples
68+
```js
69+
import * as AzureCommunicationCallingSDK from '@azure/communication-calling';
70+
import { BackgroundBlur, BackgroundReplacement } from '@azure/communication-calling-effects';
71+
72+
/** Assuming you have initialized the Azure Communication Calling client library and have created a LocalVideoStream
73+
(reference <link to main SDK npm>)
74+
*/
75+
76+
// Get the video effects feature api on the LocalVideoStream
77+
const videoEffectsFeatureApi = localVideoStream.features(AzureCommunicationCallingSDK.Features.VideoEffects);
78+
79+
// Subscribe to useful events
80+
videoEffectsFeatureApi.on(‘effectsStarted’, () => {
81+
// Effects started
82+
});
83+
84+
85+
videoEffectsFeatureApi.on(‘effectsStopped’, () => {
86+
// Effects stopped
87+
});
88+
89+
90+
videoEffectsFeatureApi.on(‘effectsError’, (error) => {
91+
// Effects error
92+
});
93+
94+
// Create the effect instance
95+
const backgroundBlurEffect = new BackgroundBlur();
96+
97+
// Recommended: Check if backgroundBlur is supported
98+
const backgroundBlurSupported = await backgroundBlurEffect.isSupported();
99+
100+
if (backgroundBlurSupported) {
101+
// Use the video effects feature api we created to start/stop effects
102+
103+
await videoEffectsFeatureApi.startEffects(backgroundBlurEffect);
104+
105+
}
106+
107+
108+
/**
109+
To create a background replacement with a custom image you need to provide the URL of the image you want as the background to this effect. The 'startEffects' method will fail if the URL is not of an image or is unreachable/unreadable.
110+
111+
Supported image formats are – png, jpg, jpeg, tiff, bmp.
112+
*/
113+
114+
const backgroundImage = 'https://linkToImageFile';
115+
116+
// Create the effect instance
117+
const backgroundReplacementEffect = new BackgroundReplacement({
118+
119+
backgroundImageUrl: backgroundImage
120+
121+
});
122+
123+
// Recommended: Check if background replacement is supported:
124+
const backgroundReplacementSupported = await backgroundReplacementEffect.isSupported();
125+
126+
if (backgroundReplacementSupported) {
127+
// Use the video effects feature api as before to start/stop effects
128+
await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect);
129+
}
130+
131+
You can change the image used for this effect by passing it in the a new configure method:
132+
133+
const newBackgroundImage = 'https://linkToNewImageFile';
134+
await backgroundReplacementEffect.configure({
135+
136+
backgroundImageUrl: newBackgroundImage
137+
138+
});
139+
140+
You can switch the effects using the same method on the video effects feature api:
141+
142+
// Switch to background blur
143+
await videoEffectsFeatureApi.startEffects(backgroundBlurEffect);
144+
145+
146+
// Switch to background replacement
147+
await videoEffectsFeatureApi.startEffects(backgroundReplacementEffect);
148+
149+
//To stop effects:
150+
await videoEffectsFeatureApi.stopEffects();
151+
152+
```

0 commit comments

Comments
 (0)