Two Tiers. Zero CGO. Full V4L2 Control.
Start with the ergonomic device package for everyday capture and output, or drop straight to v4l2 when you need direct ioctl control.
Layered Architecture
go4vl separates everyday application ergonomics from low-level kernel ABI details. High-level callers open a *device.Device, negotiate pixel formats with functional options, and stream frames through Go iterators or pooled channels.
Beneath that layer, v4l2 talks directly to /dev/video*, /dev/media*, and /dev/v4l-subdev* through golang.org/x/sys/unix and architecture-specific UAPI bindings generated from Linux kernel headers.
Zero-Copy Streaming & Pooled Channels
Range directly over memory-mapped kernel buffers using Device.Frames(ctx) (iter.Seq2[*device.Frame, error]). Each iteration waits with v4l2.Poll, yields a slice backed directly by the kernel MMAP ring with zero copies, and automatically re-queues the buffer via VIDIOC_QBUF—even on break or early return.
When your pipeline fans frames across goroutines or multiplexes Go channels with select, use Device.GetFrames() backed by FramePool and call frame.Release() to recycle memory.
Multi-Planar Formats, Output & DMA-BUF
SoC image signal processors and hardware codecs store luma and chroma channels in separate, non-contiguous memory planes. go4vl handles both single-planar formats and multi-planar MPLANE streams uniformly via WithPixFormatMPlane, per-plane slices in frame.Planes, and WriteFramePlanes.
You can also drive video output devices with WriteFrame, share zero-copy DMA-BUF file descriptors with ExportBuffer and ExportBufferPlane, capture ISP metadata via MetaFormat, and negotiate HDMI EDID blocks.
Media Controller, Sub-devices & Hardware Codecs
Embedded cameras expose complex pipelines spanning /dev/media*, /dev/v4l-subdev*, and multiple video nodes. Query full graph topologies with GetMediaTopology, enable media links, negotiate sub-device pad formats and routing tables, and drive hardware codecs through M2MSession, v4l2.Poller, and MediaRequest FDs for H.264, HEVC, VP8, VP9, AV1, MPEG2, and FWHT.
Cross-Compile Anywhere Without CGO
Checked-in UAPI definitions (zconsts_linux.go and per-architecture ztypes_linux_*.go) eliminate C toolchains and kernel header dependencies at build time. Cross-compile static Linux binaries directly from Linux, macOS, or Windows.
linux/amd64
Workstations, servers, and x86_64 capture appliances.
linux/arm64
Raspberry Pi 4/5 (64-bit), Jetson, and edge compute nodes.
linux/arm
32-bit Raspberry Pi OS and embedded ARMv7 boards.
linux/riscv64
64-bit RISC-V Linux single-board systems.
# Cross-compile static Linux binaries with CGO_ENABLED=0
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ./examples/iter_capture
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build ./examples/iter_capture
CGO_ENABLED=0 GOOS=linux GOARCH=riscv64 go build ./examples/iter_capture