Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/friendly-forks-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": patch
---

Make selfie segmenter work better
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024-2025 LiveKit, Inc.
* Copyright 2024-2026 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -122,9 +122,7 @@ class VirtualBackgroundVideoProcessor(
val image = imageProxy.image

if (enabled && image != null) {
// Put 0 for rotation degrees
// We'll rotate it together with the original video frame in the shader.
val inputImage = InputImage.fromMediaImage(image, 0)
val inputImage = InputImage.fromMediaImage(image, imageProxy.imageInfo.rotationDegrees)
latch.acquire()
val task = segmenter.process(inputImage)
task.addOnSuccessListener { mask ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit, Inc.
* Copyright 2025-2026 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,13 +29,14 @@ uniform sampler2D background;
uniform samplerExternalOES frame;
uniform sampler2D mask;
out vec4 fragColor;
in vec2 vMaskCoords;

void main() {

vec4 frameTex = texture(frame, texCoords);
vec4 bgTex = texture(background, texCoords);

float maskVal = texture(mask, texCoords).r;
float maskVal = texture(mask, vMaskCoords).r;

// Compute screen-space gradient to detect edge sharpness
float grad = length(vec2(dFdx(maskVal), dFdy(maskVal)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 LiveKit, Inc.
* Copyright 2025-2026 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,12 +18,14 @@ package io.livekit.android.track.processing.video.shader

internal const val DEFAULT_VERTEX_SHADER_SOURCE = """#version 300 es
out vec2 texCoords;
out vec2 vMaskCoords;
in vec4 in_pos;
in vec4 in_tc;
uniform mat4 tex_mat;
void main() {
gl_Position = in_pos;
texCoords = (tex_mat * in_tc).xy;
vMaskCoords = vec2(in_tc.x, 1.0 - in_tc.y);
}
"""

Expand Down