MCPcopy Index your code
hub / github.com/blackjack/webcam

github.com/blackjack/webcam @v0.6.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.1 ↗ · + Follow
99 symbols 210 edges 8 files 42 documented · 42% 2 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-webcam

Build Status GoDoc

This is a go library for working with webcams and other video capturing devices. It depends entirely on V4L2 framework, thus will compile and work only on Linux machine.

Installation

$ go get github.com/blackjack/webcam

Usage

import "github.com/blackjack/webcam"
// ...
cam, err := webcam.Open("/dev/video0") // Open webcam
if err != nil { panic(err.Error()) }
defer cam.Close()
// ...
// Setup webcam image format and frame size here (see examples or documentation)
// ...
err = cam.StartStreaming()
if err != nil { panic(err.Error()) }
for {
  err = cam.WaitForFrame(timeout)

  switch err.(type) {
  case nil:
  case *webcam.Timeout:
    fmt.Fprint(os.Stderr, err.Error())
    continue
  default:
    panic(err.Error())
  }

  frame, err := cam.ReadFrame()
  if len(frame) != 0 {
   // Process frame
  } else if err != nil {
    panic(err.Error())
  }
}

For more detailed example see examples folder The number of frame buffers used may be set as:

// If already streaming, stop streaming.
if streaming_on {
  cam.StopStreaming()
}
err = cam.SetBufferCount(64)

Roadmap

The library is still under development so API changes can happen. Currently library supports streaming using only MMAP method, which should be sufficient for most of devices available on the market. Other streaming methods can be added in future (please create issue if you need this).

Also currently image format is defined by 4-byte code received from V4L2, which is good in terms of compatibility with different versions of Linux kernel, but not very handy if you want to do some image manipulations. Plans are to aligh V4L2 image format codes with Image package from Go library.

License

See LICENSE file

Core symbols most depended-on inside this repo

Ioctl
called by 20
ioctl/ioctl.go
IoRW
called by 14
ioctl/ioctl.go
Error
called by 12
errors.go
String
called by 5
formats.go
GetString
called by 5
formats.go
Close
called by 4
webcam.go
CToGoString
called by 4
v4l2.go
ioc
called by 4
ioctl/ioctl.go

Shape

Function 39
Method 31
Struct 24
TypeAlias 5

Languages

Go100%

Modules by API surface

v4l2.go44 symbols
webcam.go27 symbols
examples/http_mjpeg_streamer/webcam.go8 symbols
ioctl/ioctl.go6 symbols
examples/stdout_streamer/stdout_streamer.go6 symbols
formats.go5 symbols
errors.go2 symbols
examples/getcontrols/getcontrols.go1 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add webcam \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page