GStreamer for Go, without cgo (purego)
  • Go 99%
  • Makefile 1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Patrice Ferlet 74aedf1487
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci: escape GO_VERSION for Woodpecker
2026-12-02 14:48:45 +01:00
docs Move module path to metal3d.org/purego/gst 2026-12-02 14:24:45 +01:00
.gitignore gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
.gitlab-ci.yml gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
.woodpecker.yml ci: escape GO_VERSION for Woodpecker 2026-12-02 14:48:45 +01:00
appsink.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
bus.go Bind the primitives a player needs 2026-12-01 21:38:48 +01:00
eos_test.go Send the end-of-stream event 2026-12-01 17:13:04 +01:00
gerror.go gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
go.mod Move module path to metal3d.org/purego/gst 2026-12-02 14:24:45 +01:00
go.sum gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
gst.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
gst_test.go gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
library.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
LICENSE gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
loader_unix.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
loader_windows.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
Makefile gst-purego: cgo-free GStreamer binding 2026-11-21 23:18:06 +01:00
pipeline.go Bind the primitives a player needs 2026-12-01 21:38:48 +01:00
property.go Load GStreamer by its platform name 2026-12-01 22:33:38 +01:00
property_test.go Bind the primitives a player needs 2026-12-01 21:38:48 +01:00
query.go Bind the primitives a player needs 2026-12-01 21:38:48 +01:00
query_test.go Make the seek test independent of the stream speed 2026-12-01 22:39:35 +01:00
README.md Move module path to metal3d.org/purego/gst 2026-12-02 14:24:45 +01:00
state_test.go Report the state change on the right bit 2026-12-01 17:26:22 +01:00

gst-purego

A cgo-free binding for GStreamer, loaded at run time with purego, in the same spirit as gtk4-purego.

The binding is deliberately small: it covers building a pipeline from its description, driving its state, reading its bus, moving the cursor, reading properties, and pulling decoded samples from an appsink — not every GStreamer API. docs/DESIGN.md lists the functions that are in scope and the decisions behind them.

gst.Init()
pipeline, err := gst.ParseLaunch("pipewiresrc ! audioconvert ! opusenc ! oggmux ! filesink location=note.ogg")
if err != nil {
    return err
}
defer pipeline.Close()

if err := pipeline.SetState(gst.StatePlaying); err != nil {
    return err
}
defer pipeline.SetState(gst.StateNull)

Rules

  • No cgo. CGO_ENABLED=0 is pinned by the Makefile; the library is opened with purego.Dlopen and its symbols are resolved lazily.
  • A missing library is not a crash. gst.Available() reports whether GStreamer could be loaded; a caller that only plays media keeps working without it.
  • One C function, one Go function. No clever wrapper layers: the generated and hand-written names mirror the C ones, like the GTK binding does.
  • Nothing here knows about GTK. The pipeline is a string built by the caller; this package returns errors, it does not open dialogs.
  • No build tag, no plugin. GStreamer plugins are loaded by GStreamer itself; the binding never guesses which ones are installed.

Platforms

The libraries are opened at run time, so the same Go binary works wherever GStreamer is installed. The shared objects do not have the same name everywhere, and the loader tries them in this order:

system library where
Linux libgstreamer-1.0.so.0 the distribution path
macOS libgstreamer-1.0.0.dylib DYLD_* paths, then /opt/homebrew/lib, /usr/local/lib, /Library/Frameworks/GStreamer.framework/Versions/1.0/lib
Windows gstreamer-1.0-0.dll the executable directory and PATH

libgstapp (the appsink) and libgobject (the properties) follow the same pattern: libgstapp-1.0.so.0 / libgstapp-1.0.0.dylib / gstapp-1.0-0.dll, and libgobject-2.0.so.0 / libgobject-2.0.0.dylib / gobject-2.0-0.dll.

  • Windows: install the MSVC runtime package and add C:\gstreamer\1.0\msvc_x86_64\bin to PATH. GStreamer finds its plugins relative to gstreamer-1.0-0.dll, so the installation layout must be kept.
  • macOS: brew install gstreamer is enough; the official .pkg installs a framework, which is also found. With a Homebrew prefix of your own, set DYLD_FALLBACK_LIBRARY_PATH to its lib directory.
  • Linux: only the runtime package is needed. The -devel package brings the unversioned .so symlink, which is a fallback, not a requirement.

Build and test

make check          # build, vet, lint, tests
make test           # tests only: they skip when libgstreamer is absent

The tests need gstreamer1 and a couple of plugins (gst-plugins-base, gst-plugins-good, gst-plugins-bad for opusenc):

sudo dnf install gstreamer1 gstreamer1-plugins-base gstreamer1-plugins-good \
                 gstreamer1-plugins-bad-free

gtk4-purego is the GTK4 binding this project is modelled on. The two divide the work: gtk4-purego owns the window and its widgets, gst-purego runs the pipeline, and neither imports the other. An application that needs both depends on both and keeps the rendering between them — for example by pulling samples from an appsink.

Licence

MIT, like the GTK binding.