NatCorder seamlessly integrates with our cross-platform media device API for Unity Engine, NatDevice. NatDevice provides a lightweight API for accessing and using hardware cameras and microphones. It has the same cross-platform support as NatCorder, and has the same minimum requirements.
GitHub - natmlx/NatDevice: High performance, cross-platform camera and microphone streaming for Unity Engine. Register at https://hub.natml.ai
NatDevice on GitHub.
Recording the Camera
Unity's API for using the hardware camera, WebCamTexture, has several limitations that prevent it from being used in a production environment.
First and foremost, the camera preview is not corrected for orientation on mobile platforms. This means that when the camera is started and displayed, it will be rotated wrongly. Correcting this orientation for display is a non-trivial process. But correcting the orientation for recording is orders of magnitude more difficult, as you will have to manually rotate each pixel buffer in memory. NatDevice handles all these gory details automatically.
Beyond the above point, NatDevice provides an expansive API for camera control. NatDevice allows for controlling the camera exposure, focus, flash, zoom, torch, white balance mode, and so on.
The typical NatDevice camera workflow is to first find a camera device to stream the camera preview from:
// Get a camera device
var query =newMediaDeviceQuery(MediaDeviceCriteria.CameraDevice);
var device = query.current asCameraDevice;
Then we can start streaming the camera preview:
// Set the preview resolution to full HD
// Then start streaming the preview
var textureOutput =newTextureOutput();
var previewTexture =await textureOutput;
Back on the NatCorder side, we will first create a recorder. Since we are recording the camera preview, we need to make sure that the frame size of the recorder is set to that of the preview texture.
// Create a recorder
var recorder =newMP4Recorder(previewTexture.width, previewTexture.height,30);
We can now commit a bunch of frames from the camera preview into our recording.