- Home /
Efficient way to Capture Webcam image stream?
We plan to save a buffer of images that stream from the camera on mobile devices, and then convert those images to a video for later playback. The issue is saving images is extremely tasking. I'm currently using this simple code to capture images:
IEnumerator CaptureTextureAsPNG()
{
while (true)
{
yield return new WaitForEndOfFrame();
Texture2D textureFromCamera = new Texture2D(320, 180);// new Texture2D(cam.width, cam.height);
textureFromCamera.SetPixels(cam.GetPixels());
textureFromCamera.Apply();
byte[] bytes = textureFromCamera.EncodeToJPG(); //textureFromCamera.EncodeToPNG();
string filePath = Application.persistentDataPath + "/ScreenSave/" + imageCount + ".jpg";//".png";
Debug.Log(filePath);
if (imageCount > 199)
imageCount = 0;
imageCount++;
File.WriteAllBytes(filePath, bytes);
}
}
I read up on the experimental AsyncGPUReadback, which would probably work, but it looks like its dx11/12 only and we need to do this on mobile ios and android. Has anyone ran into this problem before?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154626im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to access a Webcam Moniker 0 Answers
Access to WebCam denied - UWP unity app,Access denied to WebCam in UWP project 1 Answer
WebCamTexture IOS crashing? 1 Answer