Docs

Beauty filter for Flutter and React Native

Add live skin smoothing, looks, face reshape and makeup to the camera in your rooms, with the Gravix RTC SDKs. The filter runs on the phone, before the video is sent.

What you get

The Gravix beauty filter is built into the Flutter SDK, gravix_rtc, and is an optional add-on for the React Native SDK, gravix-rtc-react-native. It works on the camera the room publishes, so viewers see the filtered video on every platform, web included.

  1. Install

    Flutter: nothing extra. React Native: add the two Gravix effects packages.

  2. Create the effect

    One GravixBeautyEffect with your licence token. Without a token the filter works with a watermark.

  3. Go live

    Join the room with the effect on the camera, then set a look and sliders at any time.

The filter runs on Android today. On iOS the same code publishes the normal camera, so one app works on both.

1. Install

terminal
flutter pub add gravix_rtc
# the beauty filter is included
terminal
npm install react-native-gravix-effects@^1.5.0 react-native-gravix-effects-webrtc@^1.5.0

React Native needs gravix-rtc-react-native 0.2.0 or later first (see React Native). Without the two effects packages the app builds and runs, and the room uses its normal camera.

2. Android setup

android/gradle.properties
# android/gradle.properties
# Download the face models (about 5 MB) on first use instead of shipping them in the app.
gravixEffectsPack=models
  • gravixEffectsPack=models keeps the app smaller: the face models (about 5 MB) download once, on first use. The code below waits for that download.
  • Minimum Android 7.0 (API 24). The camera screen must be portrait.
  • Ship one APK or app bundle per ABI (Google Play does this for you with an app bundle): a universal APK carries the native code four times.
  • Ask for the camera and microphone permissions before going live: see device permissions.

3. Go live with the filter

Create the effect once, warm it up while the screen opens, make sure the face models are on the phone, then join. The filtered camera is what the room publishes.

lib/live.dart
import 'package:gravix_rtc/gravix_rtc.dart';

// licenseToken: from the console's Effects page, sent by your server. null = watermark.
final beauty = GravixBeautyEffect(licenseToken: effectsToken);
final room = GravixRoomService(videoEffect: beauty);

Future<void> goLive(String url, String token) async {
  if (await beauty.canOwnCamera()) {          // false on iOS: the normal camera is used
    await beauty.preload();                   // warm the engine while the screen opens
    final pack = await GravixEffects.availability();
    if (!pack.isReady) {
      await GravixEffects.download(onProgress: (p) => debugPrint('effects pack ${(p * 100).round()}%'));
    }
  }
  await room.connect(url: url, token: token, publishMic: true, enableVideo: true);
  // 0.12.2 restores only the last call after a camera restart: send the look and sliders together.
  await room.setVideoEffectParams({
    'look': 'glow',
    'tone': {'smoothness': 0.6, 'whiten': 0.3},
    'reshape': {'faceSlim': 0.4, 'bigEyes': 0.3},
  });
}

// Your own preview of the filtered camera, once the camera is on:
Widget preview() {
  final cam = beauty.camera;
  return cam == null ? const SizedBox.shrink() : GravixPreview(cam);
}

Future<void> filterOff() => room.setVideoEffectEnabled(false); // the camera keeps running
Future<void> filterOn() => room.setVideoEffectEnabled(true);
Future<void> flip() => room.switchCamera();
Future<void> leave() => room.dispose();
live.tsx
import {
  AudioSession, GravixBeautyEffect, GravixRoomCamera, GravixTokenProvider, Room,
} from 'gravix-rtc-react-native';
import { GravixPreview } from 'react-native-gravix-effects-webrtc';

// licenseToken: from the console's Effects page, sent by your server. null = watermark.
const beauty = new GravixBeautyEffect({ licenseToken });
const tokens = GravixTokenProvider.endpoint('https://YOUR-BACKEND/rtc/token');

export async function goLive(roomId: string, userId: string) {
  if (GravixBeautyEffect.isAvailable()) {     // false on iOS: the normal camera is used
    beauty.preload();                         // warm the engine while the screen opens
    await GravixBeautyEffect.ensurePack((p) => console.log('effects pack', p));
  }
  const { url, token } = await tokens.getCredentials({ room: roomId, identity: userId, canPublish: true });
  await AudioSession.startAudioSession();
  const room = new Room({ adaptiveStream: true, dynacast: true });
  const camera = new GravixRoomCamera(room, { videoEffect: beauty });
  await camera.connect(url, token);           // joins; the filtered camera is published
  await room.localParticipant.setMicrophoneEnabled(true);
  await camera.setVideoEffectParams({
    look: 'glow',
    tone: { smoothness: 0.6, whiten: 0.3 },
    reshape: { faceSlim: 0.4, bigEyes: 0.3 },
  });
  return { room, camera };
}

// Your own preview of the filtered camera, once the camera is on:
// {beauty.camera ? <GravixPreview camera={beauty.camera} mirrorFront /> : null}

// camera.setVideoEffectEnabled(false)  filter off, the camera keeps running
// camera.switchCamera()                front / back
// camera.setCameraEnabled(false)       camera off; on again restores the look and sliders
// camera.dispose(); room.disconnect(); AudioSession.stopAudioSession()  leave
  • Flutter: pass the effect to GravixRoomService(videoEffect: ...); the room's camera controls (setCameraEnabled, switchCamera) work as before.
  • React Native: open the camera with GravixRoomCamera, not localParticipant.setCameraEnabled; both together open two cameras. Call camera.dispose() when the screen goes away.
  • One GravixBeautyEffect can serve every room the user joins, for example when a host moves into a PK battle.

4. Looks and sliders

setVideoEffectParams takes a look and any number of slider values. Values are absolute, out-of-range values are clamped, and null removes one. Later calls add to earlier ones: a new look replaces only the look, sliders are kept.

Looks

Built-in looks: smooth, natural, glow, fresh, rosy, fair. glow is the default. A look designed in Gravix Studio and exported as a .gfx file goes in lookBytes (Flutter: the file's bytes; React Native: base64).

Skin and colour: tone

KeyRangeWhat it does
smoothness0 to 1Smoothing
whiten0 to 1Whitening
brightness0 to 1Brightness
redness0 to 1Redness
sharpen0 to 1Sharpening
vibrance0 to 1Vibrance
temp, tint-1 to 1Colour temperature and tint
blemish, spotRemove0 to 1Blemishes and spots
eyeBag, wrinkle0 to 1Eye bags and wrinkles
foundation, clarity0 to 1Even tone and clarity

Makeup: region

KeyRangeWhat it does
teeth0 to 1Teeth whitening
lipTint0 to 1Lipstick
blush0 to 1Blush
underEye0 to 1Dark circles
eyeBright0 to 1Eye brightening

Face shape: reshape

KeyRange
faceSlim-2.5 to 3
bigEyes-0.5 to 2.5
chin-0.5 to 1.25
jawV-1 to 1.25
nose-1 to 1
forehead-0.75 to 2
mouthWidth-0.85 to 1
cheekbones-0.9 to 1

reshape also takes eyeDistance, eyeTilt, eyeHeight, eyePosition, browHeight, browTilt, noseLength, noseTip, noseBridge, lipFullness, smileLift, mouthPosition, jawWidth and chinWidth (about -1 to 1). 0 leaves the face as it is; try each slider in the demo app or Gravix Studio to see what it does. React Native also has colour filters: lut (bright, cool, fade, natural, rose) with strength tone.lutIntensity.

The look and sliders come back by themselves after the camera is turned off and on or flipped. Fluttergravix_rtc 0.12.2 restores the last setVideoEffectParams call, so send the look and every slider in one call (as in the sample above); the next release keeps everything set by earlier calls. React Native keeps everything.

5. Preview and controls

  • Preview: GravixPreview(beauty.camera) in Flutter, <GravixPreview camera={beauty.camera} /> in React Native. beauty.camera is set once the room's camera is on.
  • Filter off and on: setVideoEffectEnabled(false) and (true). The camera keeps running, so turning it back on is instant.
  • Front and back camera: switchCamera(). The look and sliders stay.
  • Stickers, overlays and lip or blush colours are on the lower-level camera, beauty.camera. Values set there are not re-applied after a camera restart; use setVideoEffectParams for what must stay.

6. Licence token

  1. Open Effects in the console

    For your App ID, open the Effects page and turn it on.

  2. Register your app

    Add the Android package name and the SHA-256 of every signing certificate you ship, debug and release (./gradlew signingReport).

  3. Create the token

    Press Create token. Send it to the app from your server and pass it as licenseToken.

  • Without a token, or with one that does not match the app, the filter keeps working with a Gravix Cloud watermark and QR code on the video. Nothing stops or crashes.
  • The token is bound to your package name and signing certificate: another app gets WRONG_PACKAGE or WRONG_CERT.
  • The token lasts as long as your App ID's package, or 30 days at a time when you pay from your balance. The SDK renews it by itself about once a day, and offline the last token keeps working until it expires.
lib/live.dart
if (await beauty.canOwnCamera()) {               // Android only; throws elsewhere
  final status = await GravixCamera.licenseStatus(); // 'OK', 'MISSING', 'WRONG_CERT', ...
}
live.ts
const status = await GravixBeautyEffect.licenseStatus(); // 'OK', 'MISSING', 'WRONG_CERT', ...; null without the effects packages

The status is one of OK, MISSING, INVALID_SIGNATURE, MALFORMED, WRONG_PACKAGE, WRONG_CERT, EXPIRED, and after the online check LIMIT (over your plan's monthly effects users), REVOKED or UNKNOWN_APP.

App size and removing it

The filter adds about 13 MB on an arm64 Android phone, counting the face models downloaded on first use. React Native apps that do not install the two effects packages carry none of it. A Flutter app that does not use the filter can strip it:

android/app/build.gradle.kts
// android/app/build.gradle.kts: for an app that does not use beauty effects (about 13 MB)
configurations.all {
    exclude(group = "com.gravix", module = "gravix-effects")
    exclude(group = "com.google.mediapipe", module = "tasks-vision")
    exclude(group = "com.google.ai.edge.litert", module = "litert")
}
android/app/proguard-rules.pro
# android/app/proguard-rules.pro (R8)
-dontwarn com.gravix.effects.**
-dontwarn com.google.mediapipe.**

Limits

  • Android only for now. On iOS, canOwnCamera() (Flutter) and GravixBeautyEffect.isAvailable() (React Native) are false and the room publishes the normal camera.
  • Portrait only; the picture does not rotate with the phone.
  • On low-end phones the filter works at a lower resolution by itself to keep the frame rate.

See the filter on your own face

Install the free Beauty Effects Demo, or sign up and add the filter to your app today.