/* * NatCorder * Copyright (c) 2020 Yusuf Olokoba. */ namespace NatSuite.Recorders { using System; using System.Threading.Tasks; using Internal; /// /// MP4 video recorder. /// public sealed class MP4Recorder : IMediaRecorder { #region --Client API-- /// /// Video size. /// public (int width, int height) frameSize => recorder.frameSize; /// /// Create an MP4 recorder. /// /// Video width. /// Video height. /// Video frame rate. /// Audio sample rate. Pass 0 for no audio. /// Audio channel count. Pass 0 for no audio. /// Video bitrate in bits per second. /// Keyframe interval in seconds. public MP4Recorder (int width, int height, float frameRate, int sampleRate = 0, int channelCount = 0, int bitrate = (int)(960 * 540 * 11.4f), int keyframeInterval = 3) => this.recorder = new NativeRecorder((callback, context) => Bridge.CreateMP4Recorder(width, height, frameRate, bitrate, keyframeInterval, sampleRate, channelCount, Utility.GetPath(@".mp4"), callback, context)); public MP4Recorder(string path,int width, int height, float frameRate,int sampleRate = 0, int channelCount = 0, int bitrate = (int)(960 * 540 * 11.4f), int keyframeInterval = 3) => this.recorder = new NativeRecorder((callback, context) => Bridge.CreateMP4Recorder(width, height, frameRate, bitrate, keyframeInterval, sampleRate, channelCount, path, callback, context)); /// /// Commit a video pixel buffer for encoding. /// The pixel buffer MUST have an RGBA8888 pixel layout. /// /// Pixel buffer containing video frame to commit. /// Frame timestamp in nanoseconds. public void CommitFrame (T[] pixelBuffer, long timestamp) where T : struct => recorder.CommitFrame(pixelBuffer, timestamp); /// /// Commit a video pixel buffer for encoding. /// The pixel buffer MUST have an RGBA8888 pixel layout. /// /// Pixel buffer in native memory to commit. /// Frame timestamp in nanoseconds. public void CommitFrame (IntPtr nativeBuffer, long timestamp) => recorder.CommitFrame(nativeBuffer, timestamp); /// /// Commit an audio sample buffer for encoding. /// /// Linear PCM audio sample buffer, interleaved by channel. /// Sample buffer timestamp in nanoseconds. public void CommitSamples (float[] sampleBuffer, long timestamp) => recorder.CommitSamples(sampleBuffer, timestamp); /// /// Finish writing and return the path to the recorded media file. /// public Task FinishWriting () => recorder.FinishWriting(); #endregion private readonly IMediaRecorder recorder; } }