MixedReality-WebRTC icon indicating copy to clipboard operation
MixedReality-WebRTC copied to clipboard

Save local video frames to images

Open astaikos316 opened this issue 5 years ago • 7 comments

I am trying to figure out if there is a way to grab individual frames from the local video source in order to save them as images for further inspection and processing. Is there a method available to do such a thing? I thought there was but having trouble finding the documentation reference.

astaikos316 avatar Apr 21 '20 22:04 astaikos316

Ping @astaikos316 - is that what you were looking for? Can we close this issue? :)

djee-ms avatar Apr 27 '20 13:04 djee-ms

@djee-ms I haven't been able to set the frame saved off to a texture and render the image. I only get a blank image. Is there any example of how to do this in unity?

astaikos316 avatar Apr 27 '20 14:04 astaikos316

MediaPlayer.cs is getting the frame via the IVideoSource interface to display them to a texture (see here). It registers a callback with:

videoSrc.RegisterCallback(I420AVideoFrameReady);

then uses the VideoBridge helper class to enqueue those frames when the callback is invoked, and dequeue them in its Update() method to upload them into a Unity Texture2D object. This requires some custom shader, because the frames are encoded in YUV format, and Unity needs to display in ARGB format. An alternative is to use the ARGB callbacks, but it is better to use a custom shader because the conversion YUV -> ARGB is much faster via a shader than using CPU (which is what happen when you use the ARGB callbacks).

djee-ms avatar Apr 27 '20 14:04 djee-ms

@djee-ms Right now I am working with the last release version and not using master, because my project has been working for quite a while to get to a stable position. Is there a way to do this with the release version in a similar fashion? There are notable differences between the two and I am trying to see how to best approach this.

astaikos316 avatar Apr 28 '20 23:04 astaikos316

@astaikos316 Hi! I have a same question with you. I want to take a photo in hololens, then send the photo to computer using WebRTC. The hololens and compter have video chat using WebRTC. My question is that I don't know how to take a photo in unity which hololens and compter have video stream. How to take a photo in hololens? Can you have a good idea. Looking your forward!

zhuisa avatar Jun 11 '21 12:06 zhuisa

@astaikos316 Hi! I have a same question with you. I want to take a photo in hololens, then send the photo to computer using WebRTC. The hololens and compter have video chat using WebRTC. My question is that I don't know how to take a photo in unity which hololens and compter have video stream. How to take a photo in hololens? Can you have a good idea. Looking your forward!

Maybe you can create a RenderTexture and use Graphics.Blit() to get the render result. And you can covert RenderTexture to Texture2D. It`s good work for me.

Xiink avatar Oct 22 '21 06:10 Xiink