MediaToolkitNet.Interop 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MediaToolkitNet.Interop --version 0.1.0
                    
NuGet\Install-Package MediaToolkitNet.Interop -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MediaToolkitNet.Interop" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MediaToolkitNet.Interop" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MediaToolkitNet.Interop" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MediaToolkitNet.Interop --version 0.1.0
                    
#r "nuget: MediaToolkitNet.Interop, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MediaToolkitNet.Interop@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MediaToolkitNet.Interop&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MediaToolkitNet.Interop&version=0.1.0
                    
Install as a Cake Tool

MediaToolkit.NET

Low-level wrappers over the native media stacks for .NET 10, plus one cross-platform API on top of them: device enumeration, camera and microphone capture, audio playback, decoding and recording.

Interop goes through [LibraryImport] and unmanaged function pointers. COM on Windows is called directly through vtable slots, without [ComImport] or the built-in COM marshaller, so the assemblies stay AOT- and trim-safe.

Install

dotnet add package MediaToolkitNet

MediaToolkitNet pulls in every backend and selects one at runtime. Take a single backend instead when you do not want the rest:

Package Contents
MediaToolkitNet Facade: backend registry and per-platform selection
MediaToolkitNet.Core Abstractions only; no native code, no dependencies
MediaToolkitNet.Interop Native loading, UTF-8 marshalling, COM vtable access
MediaToolkitNet.FFmpeg FFmpeg 7.x: demux, decode, encode, mux
MediaToolkitNet.Mpv libmpv client API
MediaToolkitNet.Windows Media Foundation, WASAPI, DirectShow
MediaToolkitNet.Linux V4L2, ALSA, PulseAudio
MediaToolkitNet.MacOS AVFoundation, CoreAudio

Quick start

using MediaToolkitNet;
using MediaToolkitNet.Core.Capture;
using MediaToolkitNet.Core.Frames;

// Whichever backend this machine actually has.
using var capture = MediaToolkitNetBackends.CreateVideoCapture(VideoCaptureSettings.Default);

capture.FrameCaptured += (in VideoFrame frame) =>
{
    // The frame is borrowed: it is valid only inside this handler.
    // Copy the data out if you need to keep it.
    ReadOnlySpan<byte> luma = frame.GetPlane(0);
};

capture.Start();

List what a machine can do:

foreach (var backend in MediaToolkitNetBackends.Registered)
{
    Console.WriteLine($"{backend.Name}: {backend.IsAvailable}, {backend.Capabilities}");
}

foreach (var device in MediaToolkitNetBackends.EnumerateDevices())
{
    Console.WriteLine($"{device.Kind} {device.Name}");
}

What each backend provides

Capability Windows Linux macOS FFmpeg mpv
Device enumeration MF + WASAPI + DShow ALSA + V4L2 CoreAudio + AVF avdevice —
Video capture IMFSourceReader V4L2 mmap AVCaptureSession — —
Audio capture WASAPI (+ loopback) ALSA / PulseAudio AudioQueue — —
Audio render WASAPI ALSA / PulseAudio AudioQueue — —
Playback — — AVPlayer decode to frames full
Recording to file IMFSinkWriter — — encode + mux —

A dash means the backend does not take that role: FFmpeg owns no audio output, mpv never hands frames back, and on Linux and macOS writing files is the FFmpeg backend's job.

Requirements

  • .NET 10, and a 64-bit process: every mapped struct layout assumes a 64-bit pointer.
  • No native binary ships in any package. The platform backends only call libraries that are already part of the operating system, but:
    • MediaToolkitNet.FFmpeg needs FFmpeg 7.x at runtime (avutil 59 / avcodec 61 / avformat 61);
    • MediaToolkitNet.Mpv needs libmpv at runtime.

A backend whose libraries are missing reports IsAvailable == false instead of throwing, so probing is always safe.

Status

This is an early release. On Windows, device enumeration, camera capture, WASAPI audio capture and audio recording to AAC/MP4 have been exercised against real hardware. The Linux, macOS, FFmpeg and mpv backends compile but have not been run yet, and the public API may still change. See the release notes for the full picture before depending on it.

MIT licensed.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on MediaToolkitNet.Interop:

Package Downloads
MediaToolkitNet.FFmpeg

FFmpeg backend for MediaToolkit.NET: demuxing, decoding, encoding and muxing through libavformat, libavcodec, libavutil, libswscale and libswresample, plus probing, transcoding with subtitle conversion and burn-in, and a frame reader. Supports the FFmpeg 7.x, 8.x and 9.x ABI and validates the struct layout at startup. The FFmpeg shared libraries are not included and must be present at runtime.

MediaToolkitNet.Mpv

libmpv backend for MediaToolkit.NET: a self-rendering media player driven through the mpv client API, including property access, the event loop, filter chains and encoding mode. libmpv is not included and must be present at runtime.

MediaToolkitNet.MacOS

macOS backend for MediaToolkit.NET: AVFoundation capture and playback driven through the Objective-C runtime, and CoreAudio AudioQueue for PCM capture and render.

MediaToolkitNet.Windows

Windows backend for MediaToolkit.NET: camera capture and file recording through Media Foundation, audio capture, loopback and playback through WASAPI, and DirectShow device enumeration. COM is called through raw vtable slots, so no built-in COM marshalling is required.

MediaToolkitNet.Linux

Linux backend for MediaToolkit.NET: V4L2 video capture over memory mapped buffers, plus audio capture and playback through ALSA and the PulseAudio simple API. Works with PipeWire through its ALSA and PulseAudio compatibility layers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.1 183 9/26/2026
0.3.0 152 9/26/2026
0.2.0 172 9/19/2026
0.1.2 154 9/17/2026
0.1.1 148 9/17/2026
0.1.0 115 9/17/2026

MediaToolkit.NET 0.1.0 - first release.

The README on this page already covers what the library does, how to install it,
what each backend provides and what it needs at runtime. These notes cover only
what is specific to this release: how far it has actually been tested, and where
it does not work yet.

VERIFIED ON REAL HARDWARE (Windows 11)

- Device enumeration through Media Foundation, WASAPI and DirectShow, including
 default-endpoint flags.
- Video capture from a USB camera: 640x480 NV12 at 30 fps, sustaining about
 23 fps delivered to the frame handler.
- Audio capture through WASAPI at 48 kHz stereo float.
- Recording live audio to AAC/MP4 through IMFSinkWriter, producing a
 structurally complete MP4 (ftyp / mdat / moov, brand mp42), which confirms the
 writer was finalised rather than merely fed.

The Windows COM vtable slot tables were corrected twice during development by
running them, not by reading them: a wrong slot number compiles, raises no
exception, and silently calls the neighbouring method.

NOT EXERCISED YET - PLEASE READ BEFORE DEPENDING ON THIS

- The Linux and macOS backends have never been run. They compile and are guarded
 at runtime, but the V4L2 struct sizes and the Objective-C runtime layout have
 not been confirmed against real hardware.
- The FFmpeg and mpv backends have never been run, because those native
 libraries were not installed on the development machine. The FFmpeg ABI
 self-check refuses to proceed on a layout it cannot confirm, so a mismatch
 should produce a clear error rather than memory corruption, but that path is
 untested too.
- Media Foundation video recording is untested: the development machine has no
 video encoder MFT registered at all. MediaFoundationRecorder detects that case
 and reports it plainly. Audio recording on that path does work.

That is why this is 0.1.0. The public API may still change.

KNOWN LIMITATIONS

- Media Foundation video recording needs a video encoder MFT registered on the
 machine; editions such as Windows N without the Media Feature Pack have none.
- MacOSBackend cannot write files, because AVAssetWriter is not wrapped. Use the
 FFmpeg backend instead.
- FFmpegPlayer only decodes: no renderer and no audio output.
- Only the mpv client API is wrapped; the render API is not.
- DirectShow is wrapped for device enumeration only, with no filter graph.

Reports from Linux and macOS are especially welcome.

Full notes: https://github.com/yartat/MediaToolkit.NET/releases/tag/v0.1.0
Issues: https://github.com/yartat/MediaToolkit.NET/issues