Documentation
¶
Overview ¶
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
Index ¶
- Constants
- Variables
- func CToGoString(c []byte) string
- type FdSet
- type FrameSize
- type PixelFormat
- type Timeout
- type Webcam
- func (w *Webcam) Close() error
- func (w *Webcam) GetSupportedFormats() map[PixelFormat]string
- func (w *Webcam) GetSupportedFrameSizes(f PixelFormat) []FrameSize
- func (w *Webcam) ReadFrame() ([]byte, error)
- func (w *Webcam) SetImageFormat(f PixelFormat, width, height uint32) (PixelFormat, uint32, uint32, error)
- func (w *Webcam) StartStreaming() error
- func (w *Webcam) WaitForFrame(timeout uint32) error
Constants ¶
const ( V4L2_CAP_VIDEO_CAPTURE uint32 = 0x00000001 V4L2_CAP_STREAMING uint32 = 0x04000000 V4L2_BUF_TYPE_VIDEO_CAPTURE uint32 = 1 V4L2_MEMORY_MMAP uint32 = 1 V4L2_FIELD_ANY uint32 = 0 )
const ( V4L2_FRMSIZE_TYPE_DISCRETE uint32 = 1 V4L2_FRMSIZE_TYPE_CONTINUOUS uint32 = 2 V4L2_FRMSIZE_TYPE_STEPWISE uint32 = 3 )
const ( FD_BITS = uintptr(unsafe.Sizeof(0) * 8) FD_SETSIZE = 1024 )
Variables ¶
var ( VIDIOC_QUERYCAP = ioctl.IoR(uintptr('V'), 0, unsafe.Sizeof(v4l2_capability{})) VIDIOC_ENUM_FMT = ioctl.IoRW(uintptr('V'), 2, unsafe.Sizeof(v4l2_fmtdesc{})) VIDIOC_S_FMT = ioctl.IoRW(uintptr('V'), 5, unsafe.Sizeof(v4l2_format{})) VIDIOC_REQBUFS = ioctl.IoRW(uintptr('V'), 8, unsafe.Sizeof(v4l2_requestbuffers{})) VIDIOC_QUERYBUF = ioctl.IoRW(uintptr('V'), 9, unsafe.Sizeof(v4l2_buffer{})) VIDIOC_QBUF = ioctl.IoRW(uintptr('V'), 15, unsafe.Sizeof(v4l2_buffer{})) VIDIOC_DQBUF = ioctl.IoRW(uintptr('V'), 17, unsafe.Sizeof(v4l2_buffer{})) //sizeof int32 VIDIOC_STREAMON = ioctl.IoW(uintptr('V'), 18, 4) VIDIOC_ENUM_FRAMESIZES = ioctl.IoRW(uintptr('V'), 74, unsafe.Sizeof(v4l2_frmsizeenum{})) )
Functions ¶
func CToGoString ¶
Types ¶
type FrameSize ¶
type FrameSize struct { MinWidth uint32 MaxWidth uint32 StepWidth uint32 MinHeight uint32 MaxHeight uint32 StepHeight uint32 }
Struct that describes frame size supported by a webcam For fixed sizes min and max values will be the same and step value will be equal to '0'
type PixelFormat ¶
type PixelFormat uint32
Represents image format code used by V4L2 subsystem. Number of formats can be different in various Linux kernel versions See /usr/include/linux/videodev2.h for full list of supported image formats
type Webcam ¶
type Webcam struct {
// contains filtered or unexported fields
}
Webcam object
func Open ¶
Open a webcam with a given path Checks if device is a v4l2 device and if it is capable to stream video
func (*Webcam) GetSupportedFormats ¶
func (w *Webcam) GetSupportedFormats() map[PixelFormat]string
Returns image formats supported by the device alongside with their text description Not that this function is somewhat experimental. Frames are not ordered in any meaning, also duplicates can occur so it's up to developer to clean it up. See http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-enum-framesizes.html for more information
func (*Webcam) GetSupportedFrameSizes ¶
func (w *Webcam) GetSupportedFrameSizes(f PixelFormat) []FrameSize
Returns supported frame sizes for a given image format
func (*Webcam) ReadFrame ¶
Read a single frame from the webcam If frame cannot be read at the moment function will return empty slice
func (*Webcam) SetImageFormat ¶
func (w *Webcam) SetImageFormat(f PixelFormat, width, height uint32) (PixelFormat, uint32, uint32, error)
Sets desired image format and frame size Note, that device driver can change that values. Resulting values are returned by a function alongside with an error if any
func (*Webcam) WaitForFrame ¶
Wait until frame could be read