github.com/blackjack/webcam@v0.0.0-20230509180125-87693b3f29dc/README.md (about) 1 # go-webcam 2 3 [](https://travis-ci.org/blackjack/webcam) [](https://godoc.org/github.com/blackjack/webcam) 4 5 This is a **go** library for working with webcams and other video capturing devices. 6 It depends entirely on [V4L2](http://linuxtv.org/downloads/v4l-dvb-apis/) framework, thus will compile and work only on **Linux** machine. 7 8 ## Installation 9 10 ```console 11 $ go get github.com/blackjack/webcam 12 ``` 13 14 ## Usage 15 16 ```go 17 import "github.com/blackjack/webcam" 18 // ... 19 cam, err := webcam.Open("/dev/video0") // Open webcam 20 if err != nil { panic(err.Error()) } 21 defer cam.Close() 22 // ... 23 // Setup webcam image format and frame size here (see examples or documentation) 24 // ... 25 err = cam.StartStreaming() 26 if err != nil { panic(err.Error()) } 27 for { 28 err = cam.WaitForFrame(timeout) 29 30 switch err.(type) { 31 case nil: 32 case *webcam.Timeout: 33 fmt.Fprint(os.Stderr, err.Error()) 34 continue 35 default: 36 panic(err.Error()) 37 } 38 39 frame, err := cam.ReadFrame() 40 if len(frame) != 0 { 41 // Process frame 42 } else if err != nil { 43 panic(err.Error()) 44 } 45 } 46 ``` 47 For more detailed example see [examples folder](https://github.com/blackjack/webcam/tree/master/examples) 48 The number of frame buffers used may be set as: 49 ```go 50 // If already streaming, stop streaming. 51 if streaming_on { 52 cam.StopStreaming() 53 } 54 err = cam.SetBufferCount(64) 55 ``` 56 57 ## Roadmap 58 59 The library is still under development so API changes can happen. Currently library supports streaming 60 using only MMAP method, which should be sufficient for most of devices available on the market. 61 Other streaming methods can be added in future (please create issue if you need this). 62 63 Also currently image format is defined by 4-byte code received from V4L2, which is good in terms of 64 compatibility with different versions of Linux kernel, but not very handy if you want to do some image manipulations. 65 Plans are to aligh V4L2 image format codes with [Image](https://golang.org/pkg/image/) package from Go library. 66 67 ## License 68 69 See LICENSE file