Media Devices
Record More than Just the Screen
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.
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:
Then we can start streaming the camera preview:
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.
We can now commit a bunch of frames from the camera preview into our recording.
And once we are done recording camera preview frames, we can stop recording.
Recording the Microphone
If you plan to record user audio through the microphone, you will want to use NatDevice. Unity's Microphone
API is known to often produce glitchy audio.
We created our NatMic API because we couldn't get around Unity's glitchy microphone audio. NatMic was later merged with NatCam to create NatDevice.
NatDevice on the other hand will stream audio sample buffers directly from the microphone to your code in .NET. To start, get a microphone:
Then when you start recording, stream audio samples from the NatDevice AudioDevice
to the recorder:
When finishing recording, stop the audio device before stopping the recording:
And that's it!
Last updated