vcamera

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package vcamera creates and streams video to virtual V4L2 capture devices on Linux.

It uses V4L2Loopback to create virtual camera drivers and GStreamer to display test video streams. You can install both using our V4L2Loopback setup script. This script also needs to run `sudo modprobe v4l2loopback`. Since feeding the root password to that command at runtime would be impractical, it's recommended that you allow the current user to run that command without requiring a password. The script above will display a prompt asking if you want this behavior. Select "yes".

Usage:

// create a builder object
config := vcamera.Builder()

// create 1-to-N cameras
config = config.NewCamera(1, "Low-res Camera", vcamera.Resolution{Width: 640, Height: 480})
config = config.NewCamera(2, "Hi-res Camera", vcamera.Resolution{Width: 1280, Height: 720})
...

// start streaming
config, err := Stream()
if err != nil {
	// handle error
}

// shutdown streams
config.Shutdown()

Because this class allows for method chaining the above could be accomplished like so

config, err := vcamera.Builder().
	NewCamera(1, "Low-res Camera", vcamera.Resolution{Width: 640, Height: 480}).
	NewCamera(2, "Hi-res Camera", vcamera.Resolution{Width: 1280, Height: 720}).
	Stream()

// DO NOT forget to stop streaming to avoid leaking resources.
defer config.Shutdown()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is a builder object used to create virtual cameras.

func Builder

func Builder(logger logging.Logger) *Config

Builder creates a new vcamera.Config builder object.

func (*Config) NewCamera

func (c *Config) NewCamera(id int, label string, res Resolution) *Config

NewCamera lazily creates a new camera. No cameras are actually created until Stream is called.

func (*Config) Shutdown

func (c *Config) Shutdown() error

Shutdown stops streaming to and removes all virtual cameras.

func (*Config) Stream

func (c *Config) Stream() (*Config, error)

Stream starts streaming videos to all virtual cameras.

This function blocks until all virtual cameras successfully start streaming, or an error occurs. Shutdown will stop all streams started by this method.

type Resolution

type Resolution struct {
	Width  int
	Height int
}

Resolution stores the Width and Height in pixels for a camera resolution.

Directories

Path Synopsis
This package creates two virtual cameras and streams test video to them until the program halts (with ctrl-c for example).
This package creates two virtual cameras and streams test video to them until the program halts (with ctrl-c for example).

Jump to

Keyboard shortcuts

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