7using System.Collections.Generic;
9using System.Runtime.InteropServices;
10using System.Threading.Tasks;
23 #region --Client API--
28 public (
int width,
int height)
frameSize => (framebuffer.width, framebuffer.height);
38 framebuffer =
new Texture2D(imageWidth, imageHeight, TextureFormat.RGBA32,
false,
false);
39 writeTasks =
new List<Task>();
41 recordingPath =
Internal.Utility.GetPath(
string.Empty);
42 Directory.CreateDirectory(recordingPath);
51 public void CommitFrame<T>(T[] pixelBuffer,
long timestamp =
default) where T :
struct
53 var handle = GCHandle.Alloc(pixelBuffer, GCHandleType.Pinned);
54 CommitFrame(handle.AddrOfPinnedObject(), timestamp);
64 public void CommitFrame(IntPtr nativeBuffer,
long timestamp =
default)
67 framebuffer.LoadRawTextureData(nativeBuffer, framebuffer.width * framebuffer.height * 4);
68 var frameData = framebuffer.EncodeToJPG();
70 var frameIndex = ++frameCount;
71 writeTasks.Add(Task.Run(() =>
72 File.WriteAllBytes(Path.Combine(recordingPath, $
"{frameIndex}.jpg"), frameData)));
78 public void CommitSamples(
float[] sampleBuffer =
default,
long timestamp =
default)
87 Object.Destroy(framebuffer);
88 return Task.WhenAll(writeTasks).ContinueWith(_ => recordingPath);
94 #region --Operations--
96 private readonly Texture2D framebuffer;
97 private readonly
string recordingPath;
98 private readonly List<Task> writeTasks;
99 private int frameCount;
using Leap.Unity.Interaction. Internal
JPG image sequence recorder. This recorder is currently supported on macOS and Windows....
JPGRecorder(int imageWidth, int imageHeight)
Create a JPG recorder.
Task< string > FinishWriting()
Finish writing and return the path to the recorded media file.
void CommitSamples(float[] sampleBuffer=default, long timestamp=default)
This recorder does not support committing audio samples.
void CommitFrame< T >(T[] pixelBuffer, long timestamp=default)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
void CommitFrame(IntPtr nativeBuffer, long timestamp=default)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.