Skip to content

Instantly share code, notes, and snippets.

Avatar

Yusuf Olokoba olokobayusuf

View GitHub Profile
@olokobayusuf
olokobayusuf / Galaxy.txt
Created Jun 2, 2020
Testing the supported resolutions of Unity's WebCamTexture.
View Galaxy.txt
Camera2: Hardware level: 1
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 4032 x 3024 [2.5824869781268642]
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 4032 x 2268 [2.2948049056750834]
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 3984 x 2988 [2.558534596033433]
06-02 10:49:07.625 21849 21865 I Unity : Camera2: FrameSize 3264 x 2448 [2.1598687907924505]
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 3264 x 1836 [1.8721867183406695]
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 3024 x 3024 [2.2948049056750834]
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2976 x 2976 [2.2628042229822007]
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2880 x 2160 [1.9095425048844386]
06-02 10:49:07.626 21849 21865 I Unity : Camera2: FrameSize 2592 x 1944 [1.698821473568786]
@olokobayusuf
olokobayusuf / CameraTextureInput.cs
Last active May 8, 2020
A recorder input that blits the camera view instead of re-rendering it. It performs letterboxing for aspect ratio mismatches.
View CameraTextureInput.cs
/*
* NatCorder
* Copyright (c) 2020 Yusuf Olokoba.
*/
namespace NatSuite.Recorders.Inputs {
using UnityEngine;
using UnityEngine.Rendering;
@olokobayusuf
olokobayusuf / StreamCamera.cs
Created Feb 15, 2020
Streaming the camera preview from a camera device in NatDevice.
View StreamCamera.cs
async void StartPreview () {
// Start the camera preview
ICameraDevice device = ...;
Texture2D previewTexture = await device.StartRunning();
// Display the preview texture on a UI panel
rawImage.texture = previewTexture;
}
@olokobayusuf
olokobayusuf / ICameraDevice.cs
Created Feb 15, 2020
The fundamental camera device interface in NatDevice, which all camera devices implement.
View ICameraDevice.cs
/// <summary>
/// Camera device which provides pixel buffers.
/// </summary>
public interface ICameraDevice : IMediaDevice {
/// <summary>
/// Is the camera front facing?
/// </summary>
bool frontFacing { get; }
@olokobayusuf
olokobayusuf / RecordAudio.cs
Last active Feb 15, 2020
Streaming audio sample buffers from an audio device in NatDevice.
View RecordAudio.cs
void StartRecording () {
// Start recording audio from the microphone
IAudioDevice device = ...;
device.StartRunning(OnSampleBuffer);
}
void OnSampleBuffer (float[] sampleBuffer, long timestamp) {
// `sampleBuffer` is linear PCM, interleaved by channel
}
@olokobayusuf
olokobayusuf / IMediaDevice.cs
Created Feb 15, 2020
The fundamental interface in NatDevice, which all media devices implement.
View IMediaDevice.cs
/// <summary>
/// Media device which provides media buffers.
/// </summary>
public interface IMediaDevice : IEquatable<IMediaDevice> {
/// <summary>
/// Device unique ID.
/// </summary>
string uniqueID { get; }
@olokobayusuf
olokobayusuf / IAudioDevice.cs
Last active Feb 15, 2020
The fundamental audio device interface in NatDevice, which all audio devices implement.
View IAudioDevice.cs
/// <summary>
/// Audio device which provides sample buffers.
/// </summary>
public interface IAudioDevice : IMediaDevice {
/// <summary>
/// Audio sample rate.
/// </summary>
int sampleRate { get; }
@olokobayusuf
olokobayusuf / TranscodeDemo.cs
Created Jun 20, 2019
An example illustrating transcoding a video in Unity using NatExtractor and NatCorder.
View TranscodeDemo.cs
using UnityEngine;
using NatCorder;
using NatExtractor;
public class TranscodeDemo : MonoBehaviour {
public string videoPath; // Path to video to be transcoded
void Start () {
// Create a frame extractor
@olokobayusuf
olokobayusuf / AudioStream.cs
Last active Dec 16, 2019
An implementation of a NatMic audio device that produces audio data from a backing AudioSource or AudioListener.
View AudioStream.cs
/*
* NatMic
* Copyright (c) 2019 Yusuf Olokoba
*/
namespace NatMic.Recorders {
using UnityEngine;
using System;
using System.Runtime.CompilerServices;
View MixAudio.cs
// Get a hardware microphone
var microphoneDevice = AudioDevice.GetDevices()[0];
// Create a virtual device from an AudioSource component in game
var gameDevice = new VirtualDevice(audioSource);
// Create a mixer device that mixes audio from both devices
var audioDevice = new MixerDevice(microphoneDevice, gameDevice);
// Use the audio device like any other NatMic device
...