v4l2

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package v4l2 streams a V4L2 capture node in pure Go (mmap buffers over golang.org/x/sys/unix ioctls), delivering each frame as an RGBA picture letterboxed to a requested aspect, and names the capture nodes a system has.

Index

Constants

View Source
const ExposureManual int32 = 1

ExposureManual is the ControlExposureAuto menu entry that hands the exposure to ControlExposureAbsolute (V4L2_EXPOSURE_MANUAL).

View Source
const MinWidth = 640

MinWidth is the least width asked of a camera, so a small picture still gets one worth scaling.

Variables

View Source
var ErrNoControl = errors.New("v4l2: no such control")

ErrNoControl is a control the device does not have, or has disabled.

Functions

func CaptureCard

func CaptureCard(path string) (string, bool)

CaptureCard is the card name of a node that captures video, else false.

Types

type Camera

type Camera struct {
	// contains filtered or unexported fields
}

Camera streams a V4L2 capture node, letterboxing each frame on its own goroutine.

func Open

func Open(device string, frame image.Point, maxFPS int) (*Camera, error)

Open starts streaming device (YUYV, else MJPEG, about frame's width, at least MinWidth), its pictures letterboxed to frame's aspect, converting at most maxFPS of them a second.

func (*Camera) Close

func (c *Camera) Close()

Close stops the stream and releases the device.

func (*Camera) Err

func (c *Camera) Err() error

Err is why Frames closed.

func (*Camera) Format

func (c *Camera) Format() string

Format names the negotiated stream: size and pixel format.

func (*Camera) Frames

func (c *Camera) Frames() <-chan *image.RGBA

Frames delivers the newest pictures; it closes when the camera stops, Err then saying why.

func (*Camera) Recycle

func (c *Camera) Recycle(img *image.RGBA)

Recycle hands a picture from Frames back for the next frame.

type ControlID

type ControlID uint32

ControlID names a V4L2 control.

const (
	ControlGain             ControlID = 0x00980913
	ControlExposureAuto     ControlID = 0x009a0901
	ControlExposureAbsolute ControlID = 0x009a0902
)

The controls an exposure measurement reads and sets (V4L2_CID_*).

func (ControlID) String

func (id ControlID) String() string

String is the control's V4L2 name, or its number for one this package does not name.

type ControlRange

type ControlRange struct {
	Min, Max, Step, Default int32
}

ControlRange is what a control accepts and starts at.

func (ControlRange) Clamp

func (r ControlRange) Clamp(v int32) int32

Clamp is v limited to the range.

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter reads the brightness of a capture node's frames at the lowest resolution it offers, and its controls. Nothing it captures outlives the call that measured it.

func OpenMeter

func OpenMeter(device string) (*Meter, error)

OpenMeter opens device without streaming, so its controls can be read with the camera off.

func (*Meter) Close

func (m *Meter) Close() error

Close stops the stream and releases the buffers and the device.

func (*Meter) Control

func (m *Meter) Control(id ControlID) (int32, error)

Control reads the current value of control id.

func (*Meter) Format

func (m *Meter) Format() string

Format names the negotiated stream: size and pixel format.

func (*Meter) MeanLuma

func (m *Meter) MeanLuma(timeout time.Duration) (float64, error)

MeanLuma waits up to timeout for the next frame and returns its mean luma, 0-255.

func (*Meter) QueryControl

func (m *Meter) QueryControl(id ControlID) (ControlRange, error)

QueryControl reads the range of control id; a control the device lacks is ErrNoControl.

func (*Meter) SetControl

func (m *Meter) SetControl(id ControlID, value int32) error

SetControl sets control id to value.

func (*Meter) Start

func (m *Meter) Start() error

Start streams the smallest YUYV frame the device offers, else the smallest MJPEG one. A camera another process streams fails with unix.EBUSY in the chain.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL