OnvifLib 1.1.1

dotnet add package OnvifLib --version 1.1.1
                    
NuGet\Install-Package OnvifLib -Version 1.1.1
                    
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="OnvifLib" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OnvifLib" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="OnvifLib" />
                    
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 OnvifLib --version 1.1.1
                    
#r "nuget: OnvifLib, 1.1.1"
                    
#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 OnvifLib@1.1.1
                    
#: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=OnvifLib&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=OnvifLib&version=1.1.1
                    
Install as a Cake Tool

OnvifLib

NuGet Downloads License: MIT

OnvifLib is a modern and lightweight .NET library for interacting with ONVIF-compliant IP cameras. It provides a simple interface to discover devices, control PTZ, retrieve media streams, and handle events over the ONVIF protocol.

๐Ÿ“‚ Source code: github.com/treealarm/OnvifLib โ€” issues and pull requests welcome.


๐Ÿš€ Features

  • ๐Ÿ” Device discovery and information
  • ๐ŸŽฅ Media profile and RTSP URI retrieval
  • ๐Ÿ•น๏ธ PTZ (Pan-Tilt-Zoom) camera control
  • ๐Ÿ“ก Event handling (PullPoint or Subscription)
  • ๐Ÿง  Analytics (ver20): analytics modules and rules, metadata configuration (Profile M)
  • ๐ŸŽž๏ธ Profile G: the camera's own recordings โ€” search, replay and recording jobs
  • ๐Ÿ”Œ Device I/O: relay outputs and digital inputs
  • ๐Ÿ” WS-Security (UsernameToken) support
  • โœ… Targets .NET 10

๐Ÿ“ฆ Installation

dotnet add package OnvifLib

โšก Quick start

using OnvifLib;

// Create returns immediately and discovers the camera's services in the background.
var camera = Camera.Create("192.168.1.64", 80, "admin", "secret");
await camera.InitTask;

// A null service list means unreachable or unauthorized โ€” Create itself never throws.
if (await camera.GetServicesAsync() is null)
    throw new InvalidOperationException("could not reach the camera");

var info = await camera.GetDeviceInformationAsync();
Console.WriteLine($"{info.Manufacturer} {info.Model}, firmware {info.FirmwareVersion}");

// Every Get*Service() returns null when the camera does not offer that service.
if (await camera.GetMediaService() is { } media)
{
    foreach (var profile in media.GetProfiles())
    {
        var uri = await media.GetStreamUri(profile.Token);
        Console.WriteLine($"{profile.Name} {profile.Width}x{profile.Height} {profile.Encoding} โ†’ {uri}");
    }

    // Snapshot bytes, or null (the failure is logged rather than thrown).
    if (await media.GetImage() is { } image)
        await File.WriteAllBytesAsync("snapshot.jpg", image.Data);
}

if (await camera.GetPtzService() is { } ptz)
{
    var profile = (await camera.GetProfiles())!.First();
    await ptz.ContinuousMoveAsync(profile.Token, panTiltX: 0.5f, panTiltY: 0f);
    await Task.Delay(500);
    await ptz.StopAsync(profile.Token);
}

Stream URIs come back exactly as the camera reported them, which is usually without credentials โ€” a player needs user:password spliced in, percent-encoded.

To find cameras rather than address one directly:

var result = await WsDiscovery.ProbeAsync(TimeSpan.FromSeconds(4), CancellationToken.None);

// ScanOk distinguishes "scanned, found nothing" from "could not scan at all".
if (!result.ScanOk)
    Console.WriteLine("no interface could join the multicast group โ€” check the firewall");

foreach (var device in result.Devices)
    Console.WriteLine($"{device.Name} at {device.Ip}:{device.Port}");

๐Ÿงช Samples

Two runnable applications live in samples/, both referencing the library directly:

OnvifLib.Probe A console harness that walks the whole public API against a camera and prints OK/FAIL/SKIP per call, with a summary and an exit code. Read-only by default; --allow-writes adds writes that undo themselves. Good as a smoke test and as a way to find out what a camera actually supports.
OnvifLib.Gui A cross-platform Avalonia test bench (Windows and Linux) with a tab per service: discovery, device, media and snapshots, PTZ, imaging, events, analytics, Profile G and device I/O, plus a log pane that can capture the full SOAP exchange.
dotnet run --project samples/OnvifLib.Probe -- --discovery
dotnet run --project samples/OnvifLib.Gui

In VS Code, press F5 and pick a configuration โ€” the GUI, its self-test, or the probe with prompts for the address and credentials. In Visual Studio, set either sample as the startup project and pick a launch profile.

Note: do not enable trimming or NativeAOT in a consuming application. System.ServiceModel.* builds its channels, serializers and generated proxies by reflection with no trim annotations, so a trimmed build launches and then fails on the first SOAP call.

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 93 8/11/2026
1.0.10 81 8/11/2026
1.0.9 87 8/11/2026
1.0.7 119 6/22/2026
1.0.6 106 6/5/2026
1.0.5 99 6/5/2026
1.0.4 294 10/1/2025
1.0.3 210 9/8/2025
1.0.2 227 7/3/2025
1.0.1 366 6/11/2025

Targets .NET 10. Previous releases targeted .NET 8; consumers on .NET 8 or 9 must stay on 1.0.10. Analytics modules and rules now expose structured parameters as OnvifElementItem (name plus raw XML) instead of a bare XML list, so a Modify can round-trip them without renaming the parameter. Adds two runnable samples: a console probe that exercises the whole public API against a camera, and a cross-platform Avalonia test bench.