DEV Community

Malti Thakur for Ant Media

Posted on

πŸš€ Enhance Your Android Live Streams with DeepAR & Custom Overlays Using Ant Media SDK

Live streaming has come a long way. Viewers today expect engaging, interactive experiences β€” not just a static camera feed. With the Ant Media Android SDK, you can bring Augmented Reality (AR) effects and branded overlays right into your live streams. In this post, we’ll explore how to add DeepAR effects and Custom Canvas Overlays to Android live streams using Ant Media Server’s WebRTC SDK.

πŸ”§ Getting Started

There are two sample activities available in the companion GitHub repo:

DeepARActivity.java β€” for AR effects

CustomCanvasActivity.java β€” for custom overlays

πŸ“Œ To get started:

  1. Clone the sample:
git clone https://github.com/USAMAWIZARD/AntMedia-DeepAR-And-Overlay
Enter fullscreen mode Exit fullscreen mode
  1. Build and run on your Android device.

  2. Start streaming with dynamic effects or branded overlays!

πŸͺ„ Section 1: DeepAR Activity β€” Augmented Reality for Live Streaming

What is DeepAR?

DeepAR is an AR SDK for real-time face tracking, filters, and visual effects. When integrated with the Ant Media Server SDK, you can stream AR-enhanced video with ultra-low latency to your viewers.

*How It Works
*

  • The camera captures the video feed.
  • Frames pass through the DeepAR SDK.
  • DeepAR applies selected AR effects.

Processed frames are sent via WebRTC to the Ant Media Server and streamed live to viewers.

Example effects include:

  • Viking helmets
  • Neon devil horns
  • Playful AR elements

*Code Snippet β€” Initialize DeepAR
*

deepAR = new DeepAR(this);
deepAR.setLicenseKey("your-license-key");
deepAR.initialize(this, this);

initializeEffects();
setupCamera();
setupStreamingAndPreview();
Enter fullscreen mode Exit fullscreen mode

*WebRTC Client Setup
*

webRTCClient = IWebRTCClient.builder()
    .setServerUrl("wss://test.antmedia.io/LiveApp/websocket")
    .setActivity(this)
    .setVideoSource(IWebRTCClient.StreamSource.CUSTOM)
    .setWebRTCListener(createWebRTCListener())
    .setInitiateBeforeStream(true)
    .build();
Enter fullscreen mode Exit fullscreen mode

*Camera Frame Processing
*

imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(this), image -> {
    try {
        feedDeepAR(image);
    } finally {
        image.close();
    }
});
Enter fullscreen mode Exit fullscreen mode

You can also cycle through effects with simple UI controls.

*🎨 Section 2: Custom Canvas Activity β€” Branded Overlays
*

While AR effects are fun, sometimes streams need branding elements, such as:

  • Logos
  • Watermarks
  • Text captions

That’s where Custom Canvas Overlays come in.

*Built-in Overlay Types
*

  1. Image Overlay
    Use your own logo or branding graphic, positioned anywhere on the screen.

  2. Text Overlay
    Show custom text like titles or hashtags, with adjustable font size and color.

  • How It Works
  • CameraX captures frames.
  • An OpenGL ES renderer composites overlays.
  • Final frames are streamed via WebRTC. *Sample Overlay Setup *
imageProxyRenderer = new ImageProxyRenderer(webRTCClient, this, surfaceView, new CanvasListener() {
    @Override
    public void onSurfaceInitialized() {
        // Image overlay
        logoOverlay = new Overlay(getApplicationContext(), R.drawable.test, 0.8f, 0.8f);
        logoOverlay.setSize(0.2f);

        // Text overlay
        textOverlay = new Overlay(getApplicationContext(), "Hello", 64, Color.RED, 0f, -0.3f);
        textOverlay.setSize(0.12f);
    }
});
Enter fullscreen mode Exit fullscreen mode

*πŸš€ Why Ant Media Server?
*

Using WebRTC with Ant Media Server gives you:

βœ” Ultra-low latency streaming
βœ” Scalable streaming to thousands of viewers
βœ” Adaptive bitrate support
βœ” Cross-platform playback on any device or browser

*🏁 Wrap Up
*

Whether you want fun AR effects or professional overlays, the Ant Media Android SDK gives you powerful tools to elevate your Android live streaming.

*πŸ‘‰ Clone the project and start experimenting!
*

Would you like a formatted Markdown version with images and GitHub links ready for DEV.to (so it looks even better when published)? Just let me know!
πŸ‘‰ Check the original tutorial here: https://antmedia.io/deepar-and-custom-overlay-with-ant-media-android-sdk/

Top comments (0)