NatCorder
Search…
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.
1
// These are the currently supported recorders
2
var gifRecorder = new GIFRecorder(...);
3
var mp4Recorder = new MP4Recorder(...);
4
var hevcRecorder = new HEVCRecorder(...);
5
var jpgRecorder = new JPGRecorder(...);
6
var wavRecorder = new WAVRecorder(...);
Copied!
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.
1
// Say I have a texture
2
var texture = new Texture2D(...) or new WebCamTexture(...);
3
// I can commit its pixel data for recording
4
recorder.CommitFrame(texture.GetPixels32(), ...);
Copied!
The CommitFrame method takes in any managed numeric array which can be interpreted as a pixel buffer.
1
// So you can commit a byte array
2
var byteBuffer = new byte[...];
3
recorder.CommitFrame(byteBuffer, ...);
4
// Or an int array
5
var intBuffer = new int[...];
6
recorder.CommitFrame(intBuffer, ...);
Copied!
The CommitFrame method also has an overload which takes in a pointer to a pixel buffer in native (unmanaged) memory:
1
void* pixelBuffer = ...; // you probably shouldn't use pointers in C#
2
recorder.CommitFrame((IntPtr)pixelBuffer, ...);
Copied!

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.
1
var sampleBuffer = new float[...];
2
recorder.CommitSamples(sampleBuffer, ...);
Copied!

Finishing a Recording Session

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