Tanoda
MP4Recorder.cs
Go to the documentation of this file.
1/*
2* NatCorder
3* Copyright (c) 2020 Yusuf Olokoba.
4*/
5
6using System;
7using System.Threading.Tasks;
9
10namespace NatSuite.Recorders
11{
15 public sealed class MP4Recorder : IMediaRecorder
16 {
17 #region --Client API--
18
22 public (int width, int height) frameSize => recorder.frameSize;
23
34 public MP4Recorder(int width, int height, float frameRate, int sampleRate = 0, int channelCount = 0,
35 int bitrate = (int) (960 * 540 * 11.4f), int keyframeInterval = 3)
36 {
37 recorder = new NativeRecorder((callback, context) => Bridge.CreateMP4Recorder(width, height, frameRate,
38 bitrate, keyframeInterval, sampleRate, channelCount, Internal.Utility.GetPath(@".mp4"), callback,
39 context));
40 }
41
42 public MP4Recorder(int width, int height, float frameRate, string filename, int sampleRate = 0,
43 int channelCount = 0, int bitrate = (int) (960 * 540 * 11.4f), int keyframeInterval = 3)
44 {
45 recorder = new NativeRecorder((callback, context) => Bridge.CreateMP4Recorder(width, height, frameRate,
46 bitrate, keyframeInterval, sampleRate, channelCount, filename + ".mp4", callback, context));
47 }
48
55 public void CommitFrame<T>(T[] pixelBuffer, long timestamp) where T : struct
56 {
57 recorder.CommitFrame(pixelBuffer, timestamp);
58 }
59
66 public void CommitFrame(IntPtr nativeBuffer, long timestamp)
67 {
68 recorder.CommitFrame(nativeBuffer, timestamp);
69 }
70
76 public void CommitSamples(float[] sampleBuffer, long timestamp)
77 {
78 recorder.CommitSamples(sampleBuffer, timestamp);
79 }
80
84 public Task<string> FinishWriting()
85 {
86 return recorder.FinishWriting();
87 }
88
89 #endregion
90
91 private readonly IMediaRecorder recorder;
92 }
93}
void CommitFrame< T >(T[] pixelBuffer, long timestamp)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
Definition: MP4Recorder.cs:55
Task< string > FinishWriting()
Finish writing and return the path to the recorded media file.
Definition: MP4Recorder.cs:84
void CommitFrame(IntPtr nativeBuffer, long timestamp)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
Definition: MP4Recorder.cs:66
void CommitSamples(float[] sampleBuffer, long timestamp)
Commit an audio sample buffer for encoding.
Definition: MP4Recorder.cs:76
MP4Recorder(int width, int height, float frameRate, string filename, int sampleRate=0, int channelCount=0, int bitrate=(int)(960 *540 *11.4f), int keyframeInterval=3)
Definition: MP4Recorder.cs:42
A recorder capable of recording video frames, and optionally audio frames, to a media output....
Task< string > FinishWriting()
Finish writing and return the path to the recorded media file.
void CommitFrame(IntPtr nativeBuffer, long timestamp)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
void CommitSamples(float[] sampleBuffer, long timestamp)
Commit an audio sample buffer for encoding.