onvif-go

Talk to any ONVIF camera from Go.

Find cameras on the network, read their streams, move them, and test against virtual ones when no hardware is around.

$ go get github.com/0x524a/onvif-go

One client for every vendor.

Context on every call, safe to share across goroutines, and an endpoint can be a full URL, host:port or just an IP. Call Initialize once and the client finds the media, PTZ and imaging services itself.

client, err := onvif.NewClient(
    "192.168.1.100",
    onvif.WithCredentials("admin", "password"),
    onvif.WithTimeout(30*time.Second),
)
if err := client.Initialize(ctx); err != nil { /* ... */ }

profiles, _ := client.GetProfiles(ctx)
uri, _ := client.GetStreamURI(ctx, profiles[0].Token)
fmt.Println(uri.URI) // rtsp://192.168.1.100:554/...

No camera on your desk? Run one.

The server package is a virtual multi-lens camera with Device, Media, PTZ and Imaging services. Add the WS-Discovery responder and your own client, VMS or CI job finds it like real hardware.

Give it a stable name and it keeps the same endpoint ID after every restart.

main.go
cfg := server.DefaultConfig()
cfg.EndpointSeed = "lobby-camera" // same ID on every start
ready := make(chan struct{})
cfg.Ready = ready

srv, _ := server.New(cfg)
go srv.Start(ctx)
<-ready

resp := discovery.NewResponder(&discovery.ResponderConfig{})
resp.Register(srv.DiscoveryDevice())
go resp.Start(ctx) // answers Probes, sends Hello and Bye

What it covers.

Typed requests and responses for the ONVIF services cameras actually ship, with WS-Security digest authentication on every call.

Device98 APIsInformation, capabilities, network, users, certificates, Wi-Fi, storage, logs, firmware
Media14+ APIsProfiles, RTSP and HTTP stream URIs, snapshots, encoder settings
PTZ13 APIsContinuous, absolute and relative moves, presets, home position, status
Imaging7 APIsBrightness, contrast, exposure, focus, white balance, wide dynamic range
Discoveryclient + responderFind devices on a chosen network interface, or announce your own
Events, Device I/OincludedPull-point subscriptions, relays, digital inputs

Command-line tools included.

Prebuilt binaries are attached to every release.

onvif-cliInteractive menu or one-shot flags for scripts and CI: -op info, -op stream, -op discover.
onvif-serverStart virtual cameras from the shell, with any number of profiles.
onvif-diagnosticsTest a real camera and capture its raw SOAP, then turn the capture into a regression test.
onvif-quickDiscover, connect and try PTZ in a few keystrokes.

Tested against real cameras.

AxisHikvisionDahuaBoschHanwha

Responses captured from these vendors' devices are replayed in the test suite, so a fix for one camera does not break another. Supports ONVIF Profile S, T and G. Needs Go 1.25 or newer.