client-sdk-swift icon indicating copy to clipboard operation
client-sdk-swift copied to clipboard

Custom Video Source using AVFoundation

Open andreasteich opened this issue 1 year ago • 8 comments

I'm looking for a way to add a custom video source like providing the video frames by AVCapturesession with a custom captureOutput implementation. Is that possible using LiveKit?

andreasteich avatar Oct 17 '24 21:10 andreasteich

I want to implement the custom CameraCapturer too.

But looks like it was using RTCCameraVideoCapturer from webrtc and also cannot extends VideoCapturer outside the module.

ming-chu avatar Oct 18 '24 00:10 ming-chu

From my point of view, it would be enough to know how to feed the frames to webrtc manually. So I could retrieve the frames via captureOutput and hand them over to WebRTC videoCapturer?

andreasteich avatar Oct 19 '24 09:10 andreasteich

@andreasteich then I think maybe you want something like this LocalVideoTrack.createBufferTrack().

ming-chu avatar Oct 19 '24 14:10 ming-chu

Okay thank you very much! Do you have some more informarion about that? Can't find documentation for that...

andreasteich avatar Oct 19 '24 22:10 andreasteich

Hi @andreasteich ,

here is the doc about LocalVideoTrack.createBufferTrack()

here is the doc about BufferCapturer

Here is some sudo code for your reference:

let bufferTrack = LocalVideoTrack.createBufferTrack()
let capturer = bufferTrack.capturer as? BufferCapturer
// var yourBuffer: CMSampleBuffer?
capturer?.capture(yourBuffer)

ming-chu avatar Oct 21 '24 17:10 ming-chu

You're amazing thank you very much!

So if I understand it correctly, when I'm receiving CMSampleBuffers inside captureOutput of AVCaptureSession, I can pass those buffers on to the capturer.capture(...) with proper configuration provided for BufferCapturer and LocalVideoTrack on setup?

Can you confirm @ming-chu ?

andreasteich avatar Oct 21 '24 18:10 andreasteich

You're amazing thank you very much!

So if I understand it correctly, when I'm receiving CMSampleBuffers inside captureOutput of AVCaptureSession, I can pass those buffers on to the capturer.capture(...) with proper configuration provided for BufferCapturer and LocalVideoTrack on setup?

Can you confirm @ming-chu ?

I think so, but honestly I didn't tested it out. I would like to hear from you about the results 😃

ming-chu avatar Oct 21 '24 21:10 ming-chu

So I keep this issue until implementation done. Thank you very much!

andreasteich avatar Oct 22 '24 08:10 andreasteich

Hey @andreasteich did you manage to implement customCapturer? I’m also working on something similar, and if you could share any code or guidance for publishing a buffer

Negi-Rohit avatar Nov 07 '24 11:11 Negi-Rohit

@Negi-Rohit yes, was able to do so by following @ming-chu instructions. Just Create the BufferTrack and pass it some CMSampleBuffer or CVPixelBuffer objects.

Works incredibly well!

andreasteich avatar Nov 11 '24 12:11 andreasteich

@Negi-Rohit yes, was able to do so by following @ming-chu instructions. Just Create the BufferTrack and pass it some CMSampleBuffer or CVPixelBuffer objects.

Works incredibly well!

@ming-chu and @andreasteich Thank you very much

Negi-Rohit avatar Nov 11 '24 16:11 Negi-Rohit

Thanks @ming-chu with this I can send my buffer

PiyushSaneparaTPC avatar Feb 10 '25 07:02 PiyushSaneparaTPC