# FaceUnity AR Filter (/en/realtime-media/marketplace/build/add-video-and-ar-effects/faceunity/android)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

The FaceUnity AR Filter extension uses 3D vision, 3D graphics, and deep learning technologies to provide advanced AR portrait video effects for the Agora Video SDK. It enables features such as:

* **Basic beauty**: Skin beautification, whitening, and rosy effects.
* **Advanced beauty**: Beauty effects for shape, face, and skin.
* **Number detection**: Detect the number of faces, humans, or gestures.

This page shows you how to integrate and use the FaceUnity AR Filter extension in your app.

      
    ## Understand the tech [#understand-the-tech]

    To quickly integrate FaceUnity AR filter capabilities in your app, set extension properties using the `key` and `value` parameters in the Video SDK. Calling `setExtensionProperty` with a pair of `key` and `value` parameters is equivalent to calling the corresponding FaceUnity API. The `key` is named after the FaceUnity API method, and `value` wraps the parameters required for that method in JSON.

    ## Prerequisites [#prerequisites]

    * Android Studio 4.1 or later.
    * A physical device (not an emulator) running Android 5.0 or later.
    * Implemented the [SDK quickstart](../../../video/quickstart.mdx).

    ## Project setup [#project-setup]

    To get started, use the FaceUnity sample project on GitHub:

    1. Clone the repository:

       ```bash
       git clone https://github.com/AgoraIO-Community/AgoraMarketPlace.git
       ```

    2. Complete the setup described in the [README](https://github.com/AgoraIO-Community/AgoraMarketplace/blob/master/FaceUnity/android/README.md).

    3. Contact [support@agora.io](mailto\:support@agora.io) for activation, provide your package name, and obtain the `authpack` certificate file.

    4. Download the FaceUnity AR Filter package and the FaceUnity resource package.

    ## Integrate the extension [#integrate-the-extension]

    ### Add the extension to your project [#add-the-extension-to-your-project]

    1. Unzip the AR Filter package and save all `.aar` files to `/app/libs`.

    2. Save `authpack.java` to the path that matches the package name you registered.

    3. Save the required model and prop files from the resource package to `/app/src/main/assets`.

    4. Add the following Gradle dependency:

       ```text
       implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
       ```

    5. Import the required Agora and FaceUnity classes.

    ### Enable the extension [#enable-the-extension]

    Call `enableExtension` before other APIs, including `enableVideo` and `joinChannel`.

    ```java
    RtcEngineConfig config = new RtcEngineConfig();
    config.addExtension("AgoraFaceUnityExtension");
    mRtcEngine = RtcEngine.create(config);
    mRtcEngine.enableExtension("FaceUnity", "Effect", enabled);
    ```

    ### Initialize the extension [#initialize-the-extension]

    After receiving the `onExtensionStarted` callback, call `setExtensionProperty` to load the certificate and AI models.

    ```java
    private void initExtension() {
      try {
        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (byte it : authpack.A()) {
          jsonArray.put(it);
        }
        jsonObject.put("authdata", jsonArray);
        setExtensionProperty("fuSetup", jsonObject.toString());
      } catch (JSONException e) {
        Log.e(TAG, e.toString());
      }
    }
    ```

    ### Configure beauty effects and body recognition [#configure-beauty-effects-and-body-recognition]

    Load props, adjust beautification intensity, and enable face, gesture, and human recognition by calling `setExtensionProperty` with the corresponding keys and values.

    ### Release resources [#release-resources]

    When you stop using FaceUnity, call `setExtensionProperty` with the `fuDestroyLibData` key, and after receiving the callback, destroy the engine.

    ## Reference [#reference]

    ### API reference [#api-reference]

    * [setExtensionProperty](https://api-ref.agora.io/en/video-sdk/android/4.x/API/class_irtcengine.html#api_irtcengine_setextensionproperty)
    * [RtcEngineConfig.addExtension](/en/api-reference/rtc/android/class-and-enum/classes/class-rtcengineconfig)
    * [ContentInspectConfig](/en/api-reference/rtc/android/class-and-enum/classes/class-contentinspectconfig)

    ### Error codes [#error-codes]

    | API                    | Error code                          | Description                                                                       |
    | ---------------------- | ----------------------------------- | --------------------------------------------------------------------------------- |
    | `enableExtension`      | `-3` (SDK layer)                    | The SDK cannot find the corresponding extension dynamic library.                  |
    | `setExtensionProperty` | `-1` (extension layer)              | Invalid or repeated extension initialization or model loading.                    |
    | `setExtensionProperty` | `-2` (SDK layer or extension layer) | The timing of the call is wrong or the parameter is invalid.                      |
    | `setExtensionProperty` | `-20` (extension layer)             | The incoming key is not supported or the resource is already loaded or destroyed. |

    
  
      
  
      
  
