NatCorder
Search…
HEVCRecorder
class NatSuite.Recorders.HEVCRecorder : IMediaRecorder
NatCorder includes the HEVCRecorder which records MP4 videos with the more recent H.265 HEVC codec. This codec provides better compression at the expense of computational cost.
The HEVCRecorder uses the H.265 HEVC codec for video and AAC for audio.
On Android, this recorder is not guaranteed to be supported on any given device.
On Windows, you must install the HEVC Video Extensions pack.

Creating the Recorder

1
/// <summary>
2
/// Create a HEVC recorder.
3
/// </summary>
4
/// <param name="width">Video width.</param>
5
/// <param name="height">Video height.</param>
6
/// <param name="framerate">Video framerate.</param>
7
/// <param name="sampleRate">Audio sample rate. Pass 0 for no audio.</param>
8
/// <param name="channelCount">Audio channel count. Pass 0 for no audio.</param>
9
/// <param name="videoBitRate">Video bit rate in bits per second.</param>
10
/// <param name="keyframeInterval">Keyframe interval in seconds.</param>
11
/// <param name="audioBitRate">Audio bit rate in bits per second.</param>
12
HEVCRecorder (
13
int width,
14
int height,
15
float framerate,
16
int sampleRate = 0,
17
int channelCount = 0,
18
int videoBitRate = 10_000_000,
19
int keyframeInterval = 2,
20
int audioBitRate = 64_000
21
);
Copied!
The HEVCRecorder can be created to record video with optional audio. To record video only, simply provide the video width, video height, and video framerate.
1
// Record video only at 720p60
2
var recorder = new HEVCRecorder(1280, 720, 60);
Copied!
To record video with audio, you will provide the audio format along with the video format. The audio format comprises of the sampleRate and channelCount.
1
// Record 1080p video with 48KHz stereo audio
2
var recorder = new HEVCRecorder(1920, 1080, 30, 48000, 2);
Copied!
You can additionally specify the output video bitrate (in bits per second) and keyframe interval (in seconds).
1
// Record 1080p60 video only with custom compression settings
2
var recorder = new MP4Recorder(
3
1920,
4
1080,
5
60,
6
bitrate: 12_000_000, // bits per second
7
keyframeInterval: 3 // seconds
8
);
Copied!
The videoBitRate and keyframeInterval parameters are important for controlling the output video file size.
On Windows, the HEVCRecorder will always output audio with a 192kbps bitrate.

Video Size

1
/// <summary>
2
/// Video size.
3
/// </summary>
4
(int width, int height) frameSize { get; }
Copied!
Refer to the Frame Size section of the IMediaRecorder interface for more information.
Some devices, especially Android devices, will fail to record when either the width or height is not divisible by two. In general, it is best to stick with a standard recording size like 1280x720 or 1920x1080.

Committing Video Frames

1
/// <summary>
2
/// Commit a video pixel buffer for encoding.
3
/// The pixel buffer MUST have an RGBA8888 pixel layout.
4
/// </summary>
5
/// <param name="pixelBuffer">Pixel buffer containing video frame to commit.</param>
6
/// <param name="timestamp">Pixel buffer timestamp in nanoseconds.</param>
7
void CommitFrame<T> (T[] pixelBuffer, long timestamp) where T : unmanaged;
Copied!
Refer to the Committing Video Frames section of the IMediaRecorder interface for more information.
The spacing between consecutive timestamp values determines the actual video frame rate. The value passed to the constructor is merely a hint to the encoder.
Committed timestamps must be strictly monotonic. Not meeting this condition will cause recording to fail.

Committing Audio Frames

1
/// <summary>
2
/// Commit an audio sample buffer for encoding.
3
/// </summary>
4
/// <param name="sampleBuffer">Linear PCM audio sample buffer, interleaved by channel.</param>
5
/// <param name="timestamp">Sample buffer timestamp in nanoseconds.</param>
6
void CommitSamples (float[] sampleBuffer, long timestamp);
Copied!
Refer to the Committing Audio Frames section of the IMediaRecorder interface for more information.

Finishing Recording

1
/// <summary>
2
/// Finish writing and return the path to the recorded media file.
3
/// </summary>
4
Task<string> FinishWriting ();
Copied!
Refer to the Finishing Recording section of the IMediaRecorder interface for more information.
Last modified 2mo ago