thinkski / go-v4l2

A pure Go implementation of Video4Linux2 stream capture with a zero-copy channel interface.
MIT License
23 stars 5 forks source link
v4l2 video4linux2-stream-capture

go-v4l2

A pure Go implementation of Video4Linux2 stream capture with a simple channel based interface:

Quickstart

See examples/record.go for a more detailed example.

device, err := v4l2.Open("/dev/video0")

device.SetPixelFormat(1280, 720, v4l2.V4L2_PIX_FMT_H264)

device.SetBitrate(1000000)

device.Start()

for {
    select {
    case sample := <-device.C:
        // Each read is a H.264 NAL unit
        fmt.Printf("Read %d byte sample\n", len(sample.Data))
        sample.Release()
    }
}

Build example:

GOARCH=arm GOOS=linux go build examples/record.go