usbauto

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

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

Camera owns a single FFmpeg process that exposes the best stream and a preview stream.

func Open

func Open(ctx context.Context, deviceID string, opts ...Option) (*Camera, error)

Open probes the device, selects the best source mode automatically, and starts one split pipeline.

func (*Camera) Best

func (c *Camera) Best() *Stream

Best returns the best-quality stream for AI or archival consumers.

func (*Camera) Close

func (c *Camera) Close() error

Close stops the FFmpeg process and closes all stream channels.

func (*Camera) Device

func (c *Camera) Device() string

Device returns the resolved camera name when available.

func (*Camera) Done

func (c *Camera) Done() <-chan struct{}

Done closes when the FFmpeg process exits or the camera is closed.

func (*Camera) Preview

func (c *Camera) Preview() *Stream

Preview returns the scaled preview stream intended for browser playback.

func (*Camera) SourceMode

func (c *Camera) SourceMode() Mode

SourceMode returns the selected camera input mode.

type Mode

type Mode struct {
	Width     int     `json:"width"`
	Height    int     `json:"height"`
	FrameRate float64 `json:"frameRate"`
}

Mode is the selected source mode for the camera.

type Option

type Option func(*options)

Option customizes how usbauto selects and publishes streams.

func WithBitrates

func WithBitrates(bestKbps, previewKbps int) Option

WithBitrates sets optional encoder bitrates in Kbps for the best and preview branches.

func WithEncoder

func WithEncoder(name string, args ...string) Option

WithEncoder sets the FFmpeg H264 encoder for both branches.

func WithH264Profile

func WithH264Profile(profile string) Option

WithH264Profile sets the output H264 profile for both branches.

func WithInputArgs

func WithInputArgs(args ...string) Option

WithInputArgs appends extra arguments before FFmpeg's -i.

func WithInputCodec

func WithInputCodec(codec string) Option

WithInputCodec sets the preferred camera-side codec or pixel format before FFmpeg decodes it. Examples: "mjpeg", "h264", "yuyv422".

func WithInputFormat

func WithInputFormat(format string) Option

WithInputFormat overrides the inferred FFmpeg input format.

func WithLogger

func WithLogger(l gwebrtp.Logger) Option

WithLogger overrides the package logger.

func WithMaxResolution added in v1.2.1

func WithMaxResolution(w, h int) Option

WithMaxResolution limits the selected resolution to at most w x h.

func WithPreviewHeight

func WithPreviewHeight(height int) Option

WithPreviewHeight sets the scaled preview height. Aspect ratio is preserved automatically.

func WithStreamBuffer

func WithStreamBuffer(size int) Option

WithStreamBuffer changes the per-stream access-unit channel depth.

func WithTargetFPS

func WithTargetFPS(fps float64) Option

WithTargetFPS sets the preferred source FPS when choosing the best input mode.

type Stream

type Stream struct {
	Name        string
	Width       int
	Height      int
	FrameRate   float64
	AccessUnits <-chan gwebrtp.H264AccessUnit
	Keyframes   <-chan gwebrtp.H264AccessUnit
}

Stream is one branch of the USB camera pipeline.

Jump to

Keyboard shortcuts

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