I am trying to build a Unity application that sends a video feed from a USB camera plugged into an Android phone through an Agora.io video call. I am using this Unity asset:
https://assetstore.unity.com/packages/tools/integration/usb-camera-for-unity-android-151744
The asset has a method called GetFrame() that I am using to get each frame and send through Agora.io as a byte[] array. I need to convert the Texture2D returned by GetFrame() into a byte[] before sending it. The problem is that Unity's Texture2D.GetRawTextureData() method is returning an empty byte array. The Texture2D is not null and the texture appears fine when output to a panel in the scene. Is there another way of doing this? What could I be doing wrong?
while (!usbStopped)
{
tempTexture2D = usbCamera.GetFrame(0);
byte[] bytes = tempTexture2D.GetRawTextureData();
if (bytes.Length == 0)
throw new Exception("Frame bytes empty!");
yield return StartCoroutine(PushFrame(bytes, 640, 480, () => bytes = null);
}
The Exception is always getting hit. Any help much appreciated.