NatCorder
Search…
⌃K

Fundamentals

What You Should Know
NatCorder provides all recording functionality with implementations of a single interface: IMediaRecorder. At the highest level, NatCorder works by encoding video and audio frames on-demand. As a result, recording always follows three steps:

Starting a Recording Session

The first step is to start a recording session by creating a recorder.
// These are the currently supported recorders
var gifRecorder = new GIFRecorder(...);
var mp4Recorder = new MP4Recorder(...);
var hevcRecorder = new HEVCRecorder(...);
var jpgRecorder = new JPGRecorder(...);
var wavRecorder = new WAVRecorder(...);
var webmRecorder = new WEBMRecorder(...);
There is no defined limit on the number of simultaneous recording sessions, but the actual limit will vary by device.

Committing Frames

Once you have created a recorder, you will commit video and/or audio frames to the recorder.

Committing Video Frames

When committing video frames, the recorder always expects a pixel buffer with an RGBA8888 layout in memory. You will use the CommitFrame method to commit video frames.
// Say I have a texture
var texture = new Texture2D(...) or new WebCamTexture(...);
// I can commit its pixel data for recording
recorder.CommitFrame(texture.GetPixels32(), ...);
The CommitFrame method takes in any managed numeric array which can be interpreted as a pixel buffer.
// So you can commit a byte array
var byteBuffer = new byte[...];
recorder.CommitFrame(byteBuffer, ...);
// Or an int array
var intBuffer = new int[...];
recorder.CommitFrame(intBuffer, ...);

Committing Audio Frames

When committing audio frames, the recorder always expects a single precision floating point (float) linear PCM sample buffer, interleaved by channel. You will use the CommitSamples method to commit audio frames.
var sampleBuffer = new float[...];
recorder.CommitSamples(sampleBuffer, ...);

Finishing a Recording Session

Once you are done recording, simply call the FinishWriting method:
var path = await recorder.FinishWriting();
The recorder will finish its operations, cleanup any resources, then return a path to the recorded video.