asticode/go-astiav
Golang ffmpeg and libav C bindings
go-astiav lets Go programs use FFmpeg (a powerful open-source tool for processing audio, video, and images) without writing C code. It does this by bridging Go to FFmpeg's C library, but reshapes the lower-level API into a style Go developers naturally expect.
What it does
- Provides thousands of FFmpeg features (decoding, encoding, filtering, scaling, etc.) behind Go functions. Instead of mucking with C pointers and memory rules, Go code reads and writes data in a familiar way.
- Focuses on being idiomatic: errors follow Go's standard
if err != nilpattern, constants and flags are typed, and methods are grouped into structs rather than being loose C functions. - Ships example programs that mirror FFmpeg's official examples, covering topics like demuxing (splitting media containers into streams), decoding video/audio, filtering, scaling, transcoding, and even hardware acceleration.
- Is fully tested (the README lists this as a completed goal).
Compatibility
- Only works with FFmpeg version
n9.0, not older or newer releases. - Breaking changes to its own API will happen without the usual
v2Go module version bump; a separate changelog tracks them.
Memory management pattern
The README explains a key pattern: when reading media frames or packets, you allocate one object once, reuse it in a loop, then explicitly free it. Example:
pkt := astiav.AllocPacket()– allocate a packet once.defer pkt.Free()– make sure it gets freed when done.- Inside the loop, call
formatContext.ReadFrame(pkt)to fill the reused packet, thendefer pkt.Unref()to clean the data that was injected before moving on.
This gives developers control over memory usage while keeping the code explicit about when resources are released.
Installation
- You must build FFmpeg from source with specific settings. The project shows a Dockerfile example for doing that, then points you to set environment variables (
CGO_CFLAGS,CGO_LDFLAGS,PKG_CONFIG_PATH) so Go's build tools can find FFmpeg's libraries. - On Windows, you need MSYS2/Mingw64's GCC toolchain, along with packages like
pkg-config,make, andnasm; the README provides step-by-step commands.
Why this project exists
The author previously maintained goav, a popular fork of an older Go-FFmpeg binding, but found it had too many unresolved problems. Rather than keep patching it, they wrote go-astiav from scratch to fix those issues with a cleaner, more Go-idiomatic design.
In short: go-astiav is a purpose-built bridge that brings FFmpeg’s rich media-processing power into Go code, with a modern Go API, tested examples, and a clear (though stricter) compatibility story around FFmpeg n9.0.
Related
- Project
- Project
- Project
- Project