### Initialize Audio Input Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the audio input device with specified sample rate, channel count, and bits per sample. Recording starts immediately after initialization. ```cs waveIn.Initialize(sampleRate, channelCount, bitsPerSample); ``` -------------------------------- ### Initialize Device Capture Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the device capture object with a selected Media Foundation device. Remember to dispose of the object when done. ```cs using(var device = new DeviceCapture()) { ... } ``` -------------------------------- ### Select Screen for Capture Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the screen capture for a specific screen, typically the first one found. ```cs screenCapture.Initialize(screens.First()); // select the screen (here we take the first one) ``` -------------------------------- ### Enumerate Screens for Capture Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Enumerates available screens for screen capture. This is the first step before initializing screen capture. ```cs var screens = ScreenCapture.Enumerate(); ``` -------------------------------- ### Initialize Screen Capture Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the screen capture object with a selected screen. Ensure to dispose of the object after use. ```cs using (var screenCapture = new ScreenCapture()) { ... } ``` -------------------------------- ### Select Device for Capture Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the device capture for a specific device, typically the first one enumerated. ```cs device.Initialize(devices.First()); // select the device (here we take the first one) ``` -------------------------------- ### Read Device Capture Sample Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Reads a sample from the device capture into the provided buffer. Indicates success with a boolean return value. ```cs if (device.ReadSample(buffer, out var timestamp)) { // captured image is in the buffer } ``` -------------------------------- ### Enumerate Media Foundation Devices Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Enumerates available Media Foundation devices, such as webcams, for device capture. This is the initial step before device capture. ```cs var devices = DeviceCapture.Enumerate(); ``` -------------------------------- ### Initialize WaveOut Object for Audio Playback Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes the WaveOut object for audio output with specified sample rate, channel count, and bits per sample. ```cs using(var waveOut = new WaveOut()) { waveOut.Initialize(sampleRate, channelCount, bitsPerSample); ... } ``` -------------------------------- ### Initialize Video Encoder Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes a video encoder (e.g., H265Encoder). Ensure to dispose of the encoder after use. ```csharp using (var videoEncoder = new H265Encoder(width, height, timescale, defaultSampleDuration)) { videoEncoder.Initialize(); ... } ``` -------------------------------- ### Read Screen Capture Sample Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Reads a sample from the screen capture into the provided buffer. Returns true if a sample was successfully read. ```cs if (screenCapture.ReadSample(buffer, out var timestamp)) { // captured screen is in the buffer } ``` -------------------------------- ### Initialize Video Decoder Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes a video decoder (e.g., AV1Decoder). Ensure to dispose of the decoder after use. ```csharp using (var videoDecoder = new AV1Decoder(width, height, timescale, defaultSampleDuration)) { videoDecoder.Initialize(); ... } ``` -------------------------------- ### Create WaveIn Object Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a WaveIn object for audio input using the waveIn API. This object should be disposed after use. ```cs using(var waveIn = new WaveIn()) { ... } ``` -------------------------------- ### Initialize Audio Decoder Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes an audio decoder (e.g., OpusDecoder). Ensure to dispose of the decoder after use. ```csharp using (var audioDecoder = new OpusDecoder(960, channelCount, samplingRate, bitsPerSample)) { audioDecoder.Initialize(); ... } ``` -------------------------------- ### Create Screen Capture Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array buffer to hold the captured screen data. The size is determined by the screen capture output size. ```cs var buffer = new byte[screenCapture.OutputSize]; ``` -------------------------------- ### Enqueue Audio Sample for Playback Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Enqueues a byte array containing PCM audio data for playback. The length of the sample is also provided. ```cs byte[] pcmSample = ... waveOut.Enqueue(pcmSample, (uint)pcmSample.Length); ``` -------------------------------- ### Create Video Encoder Output Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array to hold the encoded video access unit (NALU/OBU). The size is determined by the encoder's OutputSize property. ```csharp var au = new byte[videoEncoder.OutputSize]; ``` -------------------------------- ### Create Device Capture Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array buffer to store captured image data from a device. The buffer size is based on the device's output size. ```cs var buffer = new byte[device.OutputSize]; ``` -------------------------------- ### Create Video Decoder Output Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array to hold the decoded video frame. The size is determined by the decoder's OutputSize property. ```csharp var nv12Buffer = new byte[videoDecoder.OutputSize]; ``` -------------------------------- ### Process Audio Input and Output Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Passes encoded audio frames to the decoder and retrieves decoded PCM audio. This loop continues as long as the decoder has output. ```csharp IEnumerable audioFrames = ...; // get a list of frames from your audio source foreach (var audioFrame in audioFrames) { if (audioDecoder.ProcessInput(audioFrame, 0)) { while (audioDecoder.ProcessOutput(ref pcmBuffer, out _)) { // pcmBuffer holds the decoded audio ... } } } ``` -------------------------------- ### Subscribe to FrameReceived Callback Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Subscribes to the FrameReceived event to process incoming audio data. The event provides the audio data in PCM format. ```cs waveIn.FrameReceived += (sender, e) => { byte[] pcmData = e.Data; ... } ``` -------------------------------- ### Create Audio Decoder Output Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array to hold the decoded audio (PCM) frame. The size is determined by the decoder's OutputSize property. ```csharp var pcmBuffer = new byte[audioDecoder.OutputSize]; ``` -------------------------------- ### Initialize Audio Encoder Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Initializes an audio encoder (e.g., AACEncoder). Ensure to dispose of the encoder after use. The UserData is crucial for AAC encoding. ```csharp using (var audioEncoder = new AACEncoder(channelCount, samplingRate, AACDecoder.CreateUserData(aacTrack.AudioSpecificConfig.ToBytes()), channelConfiguration)) { audioEncoder.Initialize(); // audioDecoder.UserData holds the AAC user data ... } ``` -------------------------------- ### Process Video Input and Output Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Passes encoded video units (NALU/OBU) to the decoder and retrieves decoded frames. This loop continues as long as the decoder has output. ```csharp IEnumerable units = ...; // get a list of NALU/OBU from your video source foreach (var unit in units) { if (videoDecoder.ProcessInput(unit, 0)) { while (videoDecoder.ProcessOutput(ref nv12Buffer, out _)) { // nv12Buffer holds the decoded nv12 frame ... } } } ``` -------------------------------- ### Create Audio Encoder Output Buffer Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Creates a byte array to hold the encoded audio (AAC) frame. The size is determined by the encoder's OutputSize property. ```csharp var aacBuffer = new byte[audioEncoder.OutputSize]; ``` -------------------------------- ### Process Audio Encoding Input and Output Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Passes PCM audio frames to the encoder and retrieves encoded AAC audio frames. This loop continues as long as the encoder has output. ```csharp IEnumerable pcmFrames = ...; // get a list of frames from your audio source foreach (var pcmFrame in pcmFrames) { if (audioEncoder.ProcessInput(pcmFrame, 0)) { while (audioEncoder.ProcessOutput(ref aacBuffer, out _)) { // aacBuffer holds the encoded AAC audio ... } } } ``` -------------------------------- ### Process Video Encoding Input and Output Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Passes NV12 frames to the encoder and retrieves encoded access units. It then parses these units into individual NALU/OBU. ```csharp if (videoEncoder.ProcessInput(nv12Buffer, timestamp)) { while (videoEncoder.ProcessOutput(ref au, out var length)) { // au buffer holds the encoded access unit var parsedAU = AnnexBUtils.ParseNalu(au, length); foreach (var unit in parsedAU) { // here you can access the individual NALU/OBU } } } ``` -------------------------------- ### Convert NV12 to RGB Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Converts a decoded NV12 video frame to RGB24 format for display. Ensure to dispose of the ColorConverter after use. ```csharp using(var nv12Decoder = new ColorConverter(PInvoke.MFVideoFormat_NV12, PInvoke.MFVideoFormat_RGB24, width, height)) { nv12Decoder.Initialize(); byte[] rgbBuffer = new byte[nv12Decoder.OutputSize]; if(nv12Decoder.ProcessInput(nv12Buffer, 0)) { if (nv12Decoder.ProcessOutput(ref rgbBuffer, out _)) { // rgbBuffer holds the decoded RGB frame ... } } } ``` -------------------------------- ### Convert RGB to NV12 Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Converts an RGB24 video frame to NV12 format for encoding. Ensure to dispose of the ColorConverter after use. ```csharp using(var nv12Encoder = new ColorConverter(PInvoke.MFVideoFormat_RGB24, PInvoke.MFVideoFormat_NV12, width, height)) { nv12Encoder.Initialize(); byte[] nv12Buffer = new byte[nv12Encoder.OutputSize]; if(nv12Encoder.ProcessInput(rgbBuffer, 0)) { if (nv12Encoder.ProcessOutput(ref nv12Buffer, out _)) { // nv12Buffer holds the encoded nv12 frame ... } } } ``` -------------------------------- ### Stop Audio Recording Source: https://github.com/jimm98y/sharpmediafoundationinterop/blob/main/README.md Stops the audio recording by closing or disposing of the WaveIn object. ```cs waveIn.Close(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.