-
-
Save leetesla/0eb4316af7eff19cbbcb62dab3ee9521 to your computer and use it in GitHub Desktop.
An example illustrating recording video and microphone audio in Unity with NatCorder API and NatDevice API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class VideoRecorder { | |
| MP4Recorder recorder; // Recorder that will record an MP4 | |
| CameraInput cameraInput; // Recorder input for recording video from a game camera | |
| AudioDevice audioDevice; // Microphone for recording user audio | |
| void StartRecording () { | |
| // Get a microphone | |
| var query = new MediaDeviceQuery(MediaDeviceCriteria.AudioDevice); | |
| audioDevice = query.current as AudioDevice; | |
| // Create recorder | |
| var clock = new RealtimeClock(); | |
| recorder = new MP4Recorder(1280, 720, 30, audioDevice.sampleRate, audioDevice.channelCount); | |
| // Stream media samples | |
| cameraInput = new CameraInput(recorder, clock, Camera.main); | |
| audioDevice.StartRunning(audioBuffer => recorder.CommitSamples(audioBuffer.sampleBuffer.ToArray(), clock.timestamp)); | |
| } | |
| async void StopRecording () { | |
| // Stop streaming media to the recorder | |
| cameraInput.Dispose(); | |
| audioDevice.StopRunning(); | |
| // Finish writing video | |
| var recordingPath = await recorder.FinishWriting(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment