livekit / track-processors-js

Pre-built track processors for background images, blur, etc for use with the LiveKit JS Client SDK
https://livekit.io
Apache License 2.0
34 stars 15 forks source link

Real time change #25

Closed nums closed 8 months ago

nums commented 11 months ago

I don't see how we can change the background image of the BackgroundTransformer without creating a destory. The idea would be to be able to update the background image in real time without having to reset it all.

lukasIO commented 11 months ago

Hi! That's currently not possible, but would be a nice improvement! If that's something you would like to contribute, let me know.

nums commented 11 months ago

Hello,

Here: https://github.com/livekit/track-processors-js/pull/26

lukasIO commented 11 months ago

Thanks, how were you planning to call that update function?

nums commented 11 months ago

For example when you want to change the background image or to switch between blur to image background. The update is more quick than a complete destroy and re initialization of transformer

lukasIO commented 11 months ago

Sorry, should have clarified what I mean: Did you test these changes? I think the update function is currently not exposed from the VirtualBackground processor, which makes it impossible to use this API for users of the package.

nums commented 11 months ago

Sorry, I did not understand.

But yes, I made few tests and it is working great, below is an example of use. (after 5 secondes, the background switch from blur to background image)

let localVideoTrack = new LocalVideoTrack(videoTrack);
let backgroundTransformer = new BackgroundTransformer({
    blurRadius: 50
});
let pipeline = new ProcessorPipeline([backgroundTransformer], 'virtualbackground');        
await localVideoTrack.setProcessor(pipeline);         

setTimeout(() => {
  backgroundTransformer.update({
    imagePath: './samantha-gades-BlIhVfXbi9s-unsplash.jpg'
  });
}, 5000);
lukasIO commented 11 months ago

Got it, but the pipeline in your example is what's currently exposed to users, which does not expose this update method. Ideally we'd want to have a way for users to call that function directly in there, or, alternatively return the updateBackground method somehow additionally on the VirtualBackground processor pipeline

dnetteln commented 9 months ago

I would also be interested in any progress on this. Changing the background images without tearing down the whole transformer would be great!

lukasIO commented 8 months ago

https://github.com/livekit/track-processors-js/pull/32 implements this by allowing you to do

const virtualB = VirtualBackground(imagePath);

virtualB.updateTransformerOptions({ imagePath: newImagePath });