GithubHelp home page GithubHelp logo

webcam's Introduction

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

webcam's People

Contributors

aamcrae avatar at-wat avatar bazile-clyde avatar bpstark avatar colin-davis avatar djadala avatar edaniels avatar f-fl0 avatar fabian-z avatar rsjethani avatar seanavery avatar suapapa avatar thomasf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webcam's Issues

v4l2.go / waitForFrame panics on "large" fds.

waitForFrame panics on "large" fd value.

panic: runtime error: index out of range [19] with length 16

goroutine 410912 [running]:
golang.org/x/sys/unix.(*FdSet).Set(...)
        /home/dezi/go/src/golang.org/x/sys/unix/fdset.go:12
github.com/blackjack/webcam.waitForFrame(0x4e2, 0x5)
        /home/dezi/go/src/github.com/blackjack/webcam/v4l2.go:563 +0x165
github.com/blackjack/webcam.(*Webcam).WaitForFrame(0xc0157a4c90?, 0x4f9ebf?)
        /home/dezi/go/src/github.com/blackjack/webcam/webcam.go:289 +0x1c

Referring to unix manpage of select, this can only handle fds beeing less than some limit.
This leads to unpredictable panics.

The solution is to replace "select" with "poll":

func waitForFrame(fd uintptr, timeout uint32) (count int, err error) {

	for {
		//fds := &unix.FdSet{}
		//fds.Set(int(fd))

		//var oneSecInNsec int64 = 1e9
		//timeoutNsec := int64(timeout) * oneSecInNsec
		//nativeTimeVal := unix.NsecToTimeval(timeoutNsec)
		//tv := &nativeTimeVal

		//count, err = unix.Select(int(fd+1), fds, nil, nil, tv)
		
		pollFds := []unix.PollFd{{Fd: int32(fd), Events: unix.POLLIN}}
		count, err = unix.Poll(pollFds, int(timeout*1000))

		if count < 0 && err == unix.EINTR {
			continue
		}
		return
	}
}

I have tested this, and it works.
If desired, I can provide a pull request.

Regards, dezi

Request to become a maintainer or alternatively fork this library

Hi @blackjack, with work that @viamrobotics is doing with cameras, we've been working a lot with this library in conjunction with https://github.com/pion/mediadevices and https://github.com/edaniels/gostream which are both extensively used by https://github.com/viamrobotics/rdk/ . We currently have a good amount of resources for making contributions and maintaining these libraries. Ideally, we want to increase the pace of development on this library to match the pace of the work on our product. To me, the best scenario looks like being able to commit to this repository directly. Based on what you want though, we're also open to maintaining a fork (with a go module name change) and contributing our work back. The latter would be slower but we're open to both options!

As for myself, I'm an active contributor to the Viam Robotics and Pion organizations. Given maintenance privileges, I would do my best to contribute to this repository both personally and on behalf of my employment at Viam.

Thank you for the great work this project has provided us so far Oleksandr.

Request to cut a new release to include fd leak fix

Ran into an issue recently with file descriptors piling up on Raspberry PI devices which include v4l2 files that do not satisfy the capabilities check. This issue has already been fixed in the master branch -- thanks @bpstark!

@edaniels Since this is a somewhat critical issue, I am wondering if we could cut a new release to include this fix.

Webcam should prevent double close

In https://github.com/blackjack/webcam/blob/master/webcam.go#L276, a user may accidentally (due to a bug) call Close more than once. This is particularly dangerous since we're holding to a raw file descriptor number. This could play out as:

  1. First close (normal, expected)
  2. Some other code opens a file and gets that now unused file descriptor number
  3. Second close (bug, unexpected) and now the other code has its file descriptor unexpectedly modified

Bad interaction with SDL RenderPresent?

I'm experiencing a rather strange problem related to v4l2 frame reading: whenever ReadFrame() is called (or, more, precisely, the buffer enqueuing/dequeuing ioctls), SDL screen updates stop or happen at random, large intervals. I don't know if the problem is in V4L2, SDL, the GL stack, X11, drm, or my code. I still didn't try to reimplement the example in C to bypass the Go packages, but it doesn't seem that Go is causing this.

Perhaps you could try the following example to see if you have any idea on what's happening? This code should show a smooth color change in the SDL window, but fails to do so if cam.ReadFrame() is uncommented. The frame counter shows that ReadFrame() is not blocking, it's just the window image that's not being properly updated.

package main

import (
    "fmt"
    "github.com/blackjack/webcam"
    "github.com/veandco/go-sdl2/sdl"
    "os"    
)

func main() {
    window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED,
        sdl.WINDOWPOS_UNDEFINED, 640, 480, sdl.WINDOW_SHOWN)
    if err != nil {
        fmt.Printf("can't create window: %s\n", err)
        os.Exit(1)
    }
    defer window.Destroy()

    renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
    if err != nil {
        fmt.Printf("can't create renderer: %s\n", err)
        os.Exit(1)
    }
    defer renderer.Destroy()

    texture, err := renderer.CreateTexture(sdl.PIXELFORMAT_YUY2, sdl.TEXTUREACCESS_STREAMING, 640, 480)
    if err != nil {
        fmt.Printf("can't create texture: %s", err)
        os.Exit(1)
    }
    defer texture.Destroy()

    x := uint8(0)

    cam, err := webcam.Open("/dev/video0")
    if err != nil {
        fmt.Printf("can't open webcam: %s", err)
        os.Exit(1)
    }
    _, _, _, err = cam.SetImageFormat(0x56595559, 640, 480)
    if err != nil {
        fmt.Printf("can't set image format: %s", err)
        os.Exit(1)
    }
    cam.StartStreaming()

    for {
        cam.WaitForFrame(1)
        cam.ReadFrame()
        renderer.SetDrawColor(x, x, x, 255)
        x++
        renderer.Clear()
        renderer.Present()
        fmt.Printf("%03d\r", x)
    }
}

sys/mman.h no such file or directory

iv tried downloading blackjack/webcam and the go compiler is not agreeing with it, gcc is installed, other repositories download. whats up?
capture
had to message you in an issue, no other contact that i can see

WaitForFrame times out on RPi (with LifeCam and RPi internal camera)

On RPi3 with Ubuntu/arm64 with a Microsoft Studio webcam always times out on cam.WaitForFrame(..) call when using YUYV 4:2:2 and 1920x1080 while 640x480 works just fine. However MJPEG works fine at 1920x1080. No other errors just a timeout. Potential there is a buffer issue somewhere since the amount of data with YUY will be much higher?

However MJPEG also fails. A different RPi with Raspbian and an internal RPi Cam getting the following trace:

DeviceConfig: /dev/video0, Motion-JPEG,
Available formats:
Planar YVU 4:2:0, 32-bit BGRA/X 8-8-8-8, H.264, UYVY 4:2:2, Y/CbCr 4:2:0, VYUY 4:2:2, YUYV 4:2:2, 24-bit RGB 8-8-8, JFIF JPEG, Motion-JPEG, YVYU 4:2:2, Y/CrCb 4:2:0, Planar YUV 4:2:0, 24-bit BGR 8-8-8,
Supported frame sizes for format: Motion-JPEG
[32-3280;2]x[32-2464;2],
Request: Motion-JPEG [32-3280;2]x[32-2464;2]
Result: Motion-JPEG 3280x2464
Wait frame..
Webcam wait frame, retrying: Timeout occured
Wait frame..
Webcam wait frame, retrying: Timeout occured
Wait frame..

The timeout is at 10sec but I have tried minutes and it never yields data same when trying YUYV Is this normal? What could the issue be?

Also a Logitech Brio has the same issue, timeout on WaitForFrame.

Question ! who can help me

I use pion mediadevices packege form my app
failed to find the best driver that fits the constraint
why don't get the best driver ,What's wrong
who can help me

my video is
[root@RV1126_RV1109:/userdata/kvm]# v4l2-ctl --list-devices
rkisp-statistics (platform: rkisp):
/dev/video9
/dev/video10
/dev/video11

rkispp_input_params (platform: rkispp):
/dev/video17
/dev/video18

rkisp_mainpath (platform:ffb50000.rkisp):
/dev/video0
/dev/video1
/dev/video2
/dev/video3
/dev/video4
/dev/video5
/dev/video6
/dev/video7
/dev/video8

rkispp_input_image (platform:ffb60000.rkispp):
/dev/video12
/dev/video13
/dev/video14
/dev/video15
/dev/video16
[root@RV1126_RV1109:/userdata/kvm]# v4l2-ctl -d /dev/video0 --all
Driver Info:
Driver name : rkisp_v4
Card type : rkisp_mainpath
Bus info : platform:ffb50000.rkisp
Driver version : 4.19.111
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name : rkisp
Model : rkisp
Serial :
Bus info :
Media version : 4.19.111
Hardware revision: 0x00000000 (0)
Driver version : 4.19.111
Interface Info:
ID : 0x03000012
Type : V4L Video
Entity Info:
ID : 0x00000011 (17)
Name : rkisp_mainpath
Function : V4L2 I/O
Pad 0x01000014 : 0: Sink
Link 0x02000015: from remote pad 0x1000004 of entity 'rkisp-isp-subdev': Data
Priority: 2
Format Video Capture Multiplanar:
Width/Height : 1920/1080
Pixel Format : 'YUYV' (YUYV 4:2:2)
Field : None
Number of planes : 1
Flags :
Colorspace : Default
Transfer Function : Default
YCbCr/HSV Encoding: Default
Quantization : Full Range
Plane 0 :
Bytes per Line : 3840
Size Image : 4147200
Crop: Left 0, Top 0, Width 1920, Height 1080
Selection: crop, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection: crop, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:

Image Processing Controls

             link_frequency 0x009f0901 (intmenu): min=0 max=1 default=0 value=0
                 pixel_rate 0x009f0902 (int64)  : min=0 max=2147483647 step=1 default=300000000 value=300000000 flags=read-only

Digital Video Controls

              power_present 0x00a00964 (bitmask): max=0x00000001 default=0x00000000 value=0x00000000 flags=read-only

[root@RV1126_RV1109:/usr/bin]# v4l2-ctl -d /dev/video14 --all
Driver Info:
Driver name : rkispp_v0
Card type : rkispp_scale0
Bus info : platform:ffb60000.rkispp
Driver version : 4.19.111
Capabilities : 0x84201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04201000
Video Capture Multiplanar
Streaming
Extended Pix Format
Media Driver Info:
Driver name : rkispp
Model : rkispp
Serial :
Bus info :
Media version : 4.19.111
Hardware revision: 0x00000000 (0)
Driver version : 4.19.111
Interface Info:
ID : 0x0300000a
Type : V4L Video
Entity Info:
ID : 0x00000009 (9)
Name : rkispp_scale0
Function : V4L2 I/O
Pad 0x0100000c : 0: Sink
Link 0x0200002c: from remote pad 0x1000020 of entity 'rkispp-subdev': Data, Enabled
Priority: 2
Format Video Capture Multiplanar:
Width/Height : 1920/1080
Pixel Format : 'NV12' (Y/CbCr 4:2:0)
Field : None
Number of planes : 1
Flags :
Colorspace : Default
Transfer Function : Default
YCbCr/HSV Encoding: Default
Quantization : Full Range
Plane 0 :
Bytes per Line : 1920
Size Image : 3110400
[root@RV1126_RV1109:/usr/bin]# v4l2-ctl -d /dev/video14 --set-fmt-video=width=1920,height=1080,pixelformat=NV12 --stream-mmap=3 --stream-to=/tmp/bg12.bin --stream-count=1 --stream-poll
<
get image data is OK!
[root@RV1126_RV1109:/usr/bin]#
the app log as follow:
func init() {
discovered := make(map[string]struct{})
discover(discovered, "/dev/v4l/by-path/")
discover(discovered, "/dev/video")
//discover(discovered, "/dev/media*")
}
//register camer
func discover(discovered map[string]struct{}, pattern string) {

/dev/v4l/by-path/platform-ffb50000.rkisp-video-index0 platform-ffb50000.rkisp-video-index0 ../../video0
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index0 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index0;video0 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index1 platform-ffb50000.rkisp-video-index1 ../../video1
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index1 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index1;video1 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index10 platform-ffb50000.rkisp-video-index10 ../../video10
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index10 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index10;video10 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index11 platform-ffb50000.rkisp-video-index11 ../../video11
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index11 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index11;video11 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index2 platform-ffb50000.rkisp-video-index2 ../../video2
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index2 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index2;video2 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index3 platform-ffb50000.rkisp-video-index3 ../../video3
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index3 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index3;video3 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index4 platform-ffb50000.rkisp-video-index4 ../../video4
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index4 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index4;video4 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index5 platform-ffb50000.rkisp-video-index5 ../../video5
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index5 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index5;video5 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index6 platform-ffb50000.rkisp-video-index6 ../../video6
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index6 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index6;video6 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index7 platform-ffb50000.rkisp-video-index7 ../../video7
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index7 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index7;video7 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index8 platform-ffb50000.rkisp-video-index8 ../../video8
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index8 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index8;video8 camera 0/dev/v4l/by-path/platform-ffb50000.rkisp-video-index9 platform-ffb50000.rkisp-video-index9 ../../video9
Register cam: &{/dev/v4l/by-path/platform-ffb50000.rkisp-video-index9 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb50000.rkisp-video-index9;video9 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index0 platform-ffb60000.rkispp-video-index0 ../../video12
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index0 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index0;video12 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index1 platform-ffb60000.rkispp-video-index1 ../../video13
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index1 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index1;video13 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index2 platform-ffb60000.rkispp-video-index2 ../../video14
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index2 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index2;video14 camera 0.1/dev/v4l/by-path/platform-ffb60000.rkispp-video-index3 platform-ffb60000.rkispp-video-index3 ../../video15
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index3 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index3;video15 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index4 platform-ffb60000.rkispp-video-index4 ../../video16
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index4 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index4;video16 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index5 platform-ffb60000.rkispp-video-index5 ../../video17
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index5 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index5;video17 camera 0/dev/v4l/by-path/platform-ffb60000.rkispp-video-index6 platform-ffb60000.rkispp-video-index6 ../../video18
Register cam: &{/dev/v4l/by-path/platform-ffb60000.rkispp-video-index6 map[540422490:Z16 825382478:NV21 842093913:I420 842094158:NV12 1196444237:MJPEG 1448695129:YUY2 1498831189:UYVY] map[I420:842093913 MJPEG:1196444237 NV12:842094158 NV21:825382478 UYVY:1498831189 YUY2:1448695129 Z16:540422490] false {0 0} } platform-ffb60000.rkispp-video-index6;video18 camera 0/dev/video0 video0 readlink /dev/video0: invalid argument
/dev/video1 video1 readlink /dev/video1: invalid argument
/dev/video10 video10 readlink /dev/video10: invalid argument
/dev/video11 video11 readlink /dev/video11: invalid argument
/dev/video12 video12 readlink /dev/video12: invalid argument
/dev/video13 video13 readlink /dev/video13: invalid argument
/dev/video14 video14 readlink /dev/video14: invalid argument
/dev/video15 video15 readlink /dev/video15: invalid argument
/dev/video16 video16 readlink /dev/video16: invalid argument
/dev/video17 video17 readlink /dev/video17: invalid argument
/dev/video18 video18 readlink /dev/video18: invalid argument
/dev/video2 video2 readlink /dev/video2: invalid argument
/dev/video3 video3 readlink /dev/video3: invalid argument
/dev/video4 video4 readlink /dev/video4: invalid argument
/dev/video5 video5 readlink /dev/video5: invalid argument
/dev/video6 video6 readlink /dev/video6: invalid argument
/dev/video7 video7 readlink /dev/video7: invalid argument
/dev/video8 video8 readlink /dev/video8: invalid argument
/dev/video9 video9 readlink /dev/video9: invalid argument

s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
	//s, err := mediadevices.GetDisplayMedia(mediadevices.MediaStreamConstraints{
	Video: func(c *mediadevices.MediaTrackConstraints) {
		c.FrameFormat = prop.FrameFormat(frame.FormatNV12)
		c.Width = prop.Int(1920)
		c.Height = prop.Int(1080)
	},
	Audio: func(c *mediadevices.MediaTrackConstraints) {
	},
	Codec: codecSelector,
})

selectVideo {{ {1920 (ideal) 1080 (ideal) NV12 (ideal)} { }} { {0 0 0 } {0 0 0 0 false false false}}} {[0x14b0a60] []}
Query &{0x17640c0 0x17640c0}
Query &{0x1737cc0 0x1737cc0}
Query &{0x1737e40 0x1737e40}
Query &{0x1737f00 0x1737f00}
Query &{0x1737d80 0x1737d80}
Query &{0x1737e80 0x1737e80}
Query &{0x1737f40 0x1737f40}
Query &{0x1737b80 0x1737b80}
Query &{0x1737c80 0x1737c80}
Query &{0x1737d00 0x1737d00}
Query &{0x1737c40 0x1737c40}
Query &{0x1737dc0 0x1737dc0}
Query &{0x1764080 0x1764080}
Query &{0x1737b00 0x1737b00}
Query &{0x1737b40 0x1737b40}
Query &{0x1737bc0 0x1737bc0}
Query &{0x1737ec0 0x1737ec0}
Query &{0x1737f80 0x1737f80}
Query &{0x1737c00 0x1737c00}
Query &{0x1737d40 0x1737d40}
Query &{0x1737e00 0x1737e00}
Queryresults [0x16955f0 0x1695710 0x16957a0 0x1695680 0x1695740 0x16957d0 0x1695500 0x16955c0 0x1695620 0x1695590 0x16956b0 0x16954a0 0x16954d0 0x1695530 0x1695770 0x1695800 0x1695560 0x1695650 0x16956e0]
queryDriverProperties drivers [0x16955f0 0x1695710 0x16957a0 0x1695680 0x1695740 0x16957d0 0x1695500 0x16955c0 0x1695620 0x1695590 0x16956b0 0x16954a0 0x16954d0 0x1695530 0x1695770 0x1695800 0x1695560 0x1695650 0x16956e0]
drivers &{0x1737cc0 0x1737cc0}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index5
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 119 114 51 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737cc0 0x1737cc0}
&{0x1737cc0 0x1737cc0} []
drivers &{0x1737e40 0x1737e40}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index1
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 109 95 98 121 112 97 115 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 54 48 48 48 48 46 114 107 105 115 112 112 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737e40 0x1737e40}
&{0x1737e40 0x1737e40} []
drivers &{0x1737f00 0x1737f00}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index4
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 115 99 97 108 101 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 54 48 48 48 48 46 114 107 105 115 112 112 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737f00 0x1737f00}
&{0x1737f00 0x1737f00} []
drivers &{0x1737d80 0x1737d80}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index8
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 114 100 50 95 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216697856 69214208 [0 0 0]}
&{0x1737d80 0x1737d80} open error Not a video capture device
drivers &{0x1737e80 0x1737e80}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index2
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 115 99 97 108 101 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 54 48 48 48 48 46 114 107 105 115 112 112 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737e80 0x1737e80}
&{0x1737e80 0x1737e80} []
drivers &{0x1737f40 0x1737f40}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index5
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 105 110 112 117 116 95 112 97 114 97 109 115 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 32 114 107 105 115 112 112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 267119 2350907392 203423744 [0 0 0]}
&{0x1737f40 0x1737f40} open error Not a video capture device
drivers &{0x1737b80 0x1737b80}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index10
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 45 105 110 112 117 116 45 112 97 114 97 109 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 32 114 107 105 115 112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 267119 2350907392 203423744 [0 0 0]}
&{0x1737b80 0x1737b80} open error Not a video capture device
drivers &{0x1737c80 0x1737c80}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index4
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 119 114 50 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737c80 0x1737c80}
&{0x1737c80 0x1737c80} []
drivers &{0x1737d00 0x1737d00}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index6
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 114 100 48 95 109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216697856 69214208 [0 0 0]}
&{0x1737d00 0x1737d00} open error Not a video capture device
drivers &{0x1737c40 0x1737c40}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index3
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 119 114 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737c40 0x1737c40}
&{0x1737c40 0x1737c40} []
drivers &{0x1737dc0 0x1737dc0}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index9
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 45 115 116 97 116 105 115 116 105 99 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 32 114 107 105 115 112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 267119 2225078272 77594624 [0 0 0]}
&{0x1737dc0 0x1737dc0} open error Not a video capture device
drivers &{0x1737b00 0x1737b00}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index0
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 109 97 105 110 112 97 116 104 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737b00 0x1737b00}
&{0x1737b00 0x1737b00} []
drivers &{0x1737b40 0x1737b40}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index1
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 115 101 108 102 112 97 116 104 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737b40 0x1737b40}
&{0x1737b40 0x1737b40} []
drivers &{0x1737bc0 0x1737bc0}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index11
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 45 109 105 112 105 45 108 117 109 97 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 32 114 107 105 115 112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 267119 2225078272 77594624 [0 0 0]}
&{0x1737bc0 0x1737bc0} open error Not a video capture device
drivers &{0x1737ec0 0x1737ec0}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index3
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 115 99 97 108 101 49 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 54 48 48 48 48 46 114 107 105 115 112 112 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737ec0 0x1737ec0}
&{0x1737ec0 0x1737ec0} []
drivers &{0x1737f80 0x1737f80}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index6
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 45 115 116 97 116 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 32 114 107 105 115 112 112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 267119 2225078272 77594624 [0 0 0]}
&{0x1737f80 0x1737f80} open error Not a video capture device
drivers &{0x1737c00 0x1737c00}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index2
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 119 114 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216693760 69210112 [0 0 0]}
opened success &{0x1737c00 0x1737c00}
&{0x1737c00 0x1737c00} []
drivers &{0x1737d40 0x1737d40}
webcam /dev/v4l/by-path/platform-ffb50000.rkisp-video-index7
caps &{[114 107 105 115 112 95 118 52 0 0 0 0 0 0 0 0] [114 107 105 115 112 95 114 97 119 114 100 49 95 108 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 53 48 48 48 48 46 114 107 105 115 112 0 0 0 0 0 0 0 0 0] 267119 2216697856 69214208 [0 0 0]}
&{0x1737d40 0x1737d40} open error Not a video capture device
drivers &{0x1737e00 0x1737e00}
webcam /dev/v4l/by-path/platform-ffb60000.rkispp-video-index0
caps &{[114 107 105 115 112 112 95 118 48 0 0 0 0 0 0 0] [114 107 105 115 112 112 95 105 110 112 117 116 95 105 109 97 103 101 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [112 108 97 116 102 111 114 109 58 102 102 98 54 48 48 48 48 46 114 107 105 115 112 112 0 0 0 0 0 0 0 0] 267119 2216697856 69214208 [0 0 0]}
&{0x1737e00 0x1737e00} open error Not a video capture device
m map[0x16954a0:[] 0x16954d0:[] 0x1695560:[] 0x1695590:[] 0x16955c0:[] 0x16955f0:[] 0x1695710:[] 0x1695740:[] 0x1695770:[] 0x16957a0:[]]
selectBestDriver filter 0x89747c driverProperties map[0x16954a0:[] 0x16954d0:[] 0x1695560:[] 0x1695590:[] 0x16955c0:[] 0x16955f0:[] 0x1695710:[] 0x1695740:[] 0x1695770:[] 0x16957a0:[]]
priority 0 props []
priority 0 props []
priority 0 props []
priority 0 props []
priority 0 props []
priority 0.10000000149011612 props []
priority 0 props []
priority 0 props []
priority 0 props []
priority 0 props []
selectBestDriver err 0x89735c failed to find the best driver that fits the constraints
selectVideo err failed to find the best driver that fits the constraints

failed to find the best driver that fits the constraint

why don't get the best driver ,What's wrong

Add patch

Please add patch, I add some ioctls functions, get/set controls

Bad interaction with SDL RenderPresent?

I'm experiencing a rather strange problem related to v4l2 frame reading: whenever ReadFrame() is called (or, more, precisely, the buffer enqueuing/dequeuing ioctls), SDL screen updates stop or happen at random, large intervals. Exact behavior seems to be different on different machines. I don't know if the problem is in V4L2, SDL, the GL stack, X11, drm, or my code. I still didn't try to reimplement the example in C to bypass the Go packages, but it doesn't seem that Go is causing this.

Perhaps you could try the following example to see if you have any idea on what's happening here? This code should show a smooth color change in the SDL window, but fails to do so if cam.ReadFrame() is uncommented. The frame counter shows that ReadFrame() is not blocking, it's just the window image that's not being properly updated.

package main

import (
    "fmt"
    "github.com/blackjack/webcam"
    "github.com/veandco/go-sdl2/sdl"
    "os"
)

func main() {
    window, err := sdl.CreateWindow("test", sdl.WINDOWPOS_UNDEFINED,
        sdl.WINDOWPOS_UNDEFINED, 640, 480, sdl.WINDOW_SHOWN)
    if err != nil {
        fmt.Printf("can't create window: %s\n", err)
        os.Exit(1)
    }
    defer window.Destroy()

    renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
    if err != nil {
        fmt.Printf("can't create renderer: %s\n", err)
        os.Exit(1)
    }
    defer renderer.Destroy()

    texture, err := renderer.CreateTexture(sdl.PIXELFORMAT_YUY2, sdl.TEXTUREACCESS_STREAMING, 640, 480)
    if err != nil {
        fmt.Printf("can't create texture: %s", err)
        os.Exit(1)
    }
    defer texture.Destroy()

    x := uint8(0)

    cam, err := webcam.Open("/dev/video0")
    if err != nil {
        fmt.Printf("can't open webcam: %s", err)
        os.Exit(1)
    }
    _, _, _, err = cam.SetImageFormat(0x56595559, 640, 480)
    if err != nil {
        fmt.Printf("can't set image format: %s", err)
        os.Exit(1)
    }
    cam.StartStreaming()

    for {
        cam.WaitForFrame(1)
        cam.ReadFrame()
        renderer.SetDrawColor(x, x, x, 255)
        x++
        renderer.Clear()
        renderer.Present()
        fmt.Printf("%03d\r", x)
    }
}

Device or resource busy

Error:

panic : device or resource busy

When:

Any time the service tries to write to the camera (ioctl.Ioctl executions)

Example:

If I use the stdout_streamer.go the camera opens properly and is supported (I've successfully used an older version of this library also). Read events works fine such as cam.GetSupportedFormats() and cam.GetSupportedFrameSizes(format) but as soon as the first write event occurs cam.SetImageFormat(format, uint32(size.MaxWidth), uint32(size.MaxHeight)) the system panics with "device or resource busy".

Thoughts:

I've had no luck tracking down the source of this issue. My old build of this library still runs fine so I'm certain that my setup is correct. I'm guessing that something with os.OpenFile(path, unix.O_RDWR|unix.O_NONBLOCK, 0666) is blocking and only allowing read access.

PS: I am cross compiling from a windows machine (previously I was cross compiling from a mac). I will test today if this is the source of the issue.

Thanks

output to mp4

do we have an example to encode the file to a mp4 container? For example using ffmpeg.

Suggestion for example

What do you think about example that control backlight based on webcam as light sensor ?

USING IT FOR RPI CAMERA?

how can i use it for the rpi camera?
when i tried to run it on my raspberry pi it gave me error :
10:13 Unable to open webcam no such file or directory
Can you suggest a way?

Frames are "invalid JPEG format: uninitialized Huffman table"

Hi, I'm reading the frames in Motion-JPEG format, to add an overlay. But doing the following...

import (
    "bytes"
    "image"
)

/*...*/

    frame, _ := cam.ReadFrame()
    r := bytes.NewReader(frame)
    frameImage, _, err := image.Decode(r)
    if err != nil {
        return err
    }

...yields error invalid JPEG format: uninitialized Huffman table.

Thanks in advance,
Phil

Invalid argument on capture

Hello,

I'm very interested by your package but nothing works for me...

Here is a sample code:

package main

import (
	"log"
	"strings"

	"github.com/blackjack/webcam"
)

func main() {
	cam, err := webcam.Open("/dev/video0")
	if err != nil {
		panic(err.Error())
	}
	defer cam.Close()

	// Set the camera's resolution
	formats := cam.GetSupportedFormats()
	var format webcam.PixelFormat
	var width, height uint32

	for pf, f := range formats {
		f = strings.ToLower(f)
		log.Println("possible format", f)
		if strings.Contains(f, "jpeg") {
			format = pf
		}
	}
	sizes := cam.GetSupportedFrameSizes(format)
	for _, size := range sizes {
		log.Println("possible size:", size)
		if size.MaxWidth == 0 || size.MaxHeight == 0 {
			continue
		}
		width = size.MaxWidth
		height = size.MaxHeight
	}
	log.Println("Set resolution to: ", width, height, "and pixel format to: ", formats[format], format)

	cam.SetImageFormat(format, width, height)
	cam.SetFramerate(10)
	cam.SetBufferCount(1)

	err = cam.WaitForFrame(10)
	if err != nil {
		panic(err.Error())
	}
	frame, _, err := cam.GetFrame()
	if err != nil {
		log.Println(err.Error())
	} else {
		log.Println(len(frame))
	}
}

Whatever I try:

2022/05/18 14:00:43 possible format yuyv 4:2:2
2022/05/18 14:00:43 possible format motion-jpeg
2022/05/18 14:00:43 possible size: {1280 1280 0 720 720 0}
2022/05/18 14:00:43 possible size: {160 160 0 120 120 0}
2022/05/18 14:00:43 possible size: {176 176 0 144 144 0}
2022/05/18 14:00:43 possible size: {320 320 0 240 240 0}
2022/05/18 14:00:43 possible size: {352 352 0 288 288 0}
2022/05/18 14:00:43 possible size: {640 640 0 480 480 0}
2022/05/18 14:00:43 Set resolution to:  640 480 and pixel format to:  Motion-JPEG 1196444237
2022/05/18 14:00:43 invalid argument

Note that the error is raised on the GetFrame() call. I also try to not wait for the frame and to use ReadFrame but I've always got this error.

Can you tell me what I'm doing wrong ?

UYVY format support

Hello,
I want to modify the http_mjpeg_streamer so it can support also the UYVY format.
How can I change the following code to do that:

switch format {
case V4L2_PIX_FMT_YUYV:
	yuyv := image.NewYCbCr(image.Rect(0, 0, int(w), int(h)), image.YCbCrSubsampleRatio422)
	for i := range yuyv.Cb {
		ii := i * 4
		yuyv.Y[i*2] = frame[ii]
		yuyv.Y[i*2+1] = frame[ii+2]
		yuyv.Cb[i] = frame[ii+1]
		yuyv.Cr[i] = frame[ii+3]
	}
	img = yuyv

Thank you,

question error device or resource busy

os linux all read operation work write return error
fun SetImageFormat

err = ioctl.Ioctl(fd, VIDIOC_S_FMT, uintptr(unsafe.Pointer(format)))
return error

Requesting YUV 4:2:2 (YUYV) 1920x1080
2015/11/28 08:58:15 ====> [128 7 0 0 56 4 0 0 89 85 89 86 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
2015/11/28 08:58:15 SetImageFormat return error device or resource busy

add support for V4L2_PIX_FMT_MJPEG

These video-capture cards support mjpeg out-of-the-box, it would be pretty nice to support that format too.

Also the http_mjpeg_streamer/webcam example should also support it, as it no longer needs to compress the image at all, it can just send the data directly from the camera do the http response.

For reference, these are the supported formats, as displayed by the example:

Available formats:
YUYV 4:2:2
Motion-JPEG
Supported frame sizes for format YUYV 4:2:2
640x480
720x480
720x576
800x600
1024x768
1280x720
1360x768
1280x960
1280x1024
1600x1200
1920x1080

I've also have more information about these cards at https://github.com/rgl/usb-hdmi-video-capture (including v4l2-ctl --device /dev/video0 --list-formats-ext --all at https://github.com/rgl/usb-hdmi-video-capture/blob/master/v4l-output.txt).

Always getting a timeout from http_mjpeg_streamer

I successfully downloaded the package with go get github.com/blackjack/webcam and then I built the http_mjpeg_streamer example program with go install github.com/blackjack/webcam/examples/http_mjpeg_streamer.

When I invoke the sample program in single-image mode and then try to connect with a web browser or with wget nothing is received from the program, and http_mjpeg_streamer reports a timeout:

$ golang/bin/http_mjpeg_streamer  -m
Available formats:
YUYV 4:2:2
Motion-JPEG
Supported frame sizes for format YUYV 4:2:2
160x120
176x144
320x240
352x288
640x480
800x600
1280x960
1280x1024
1600x1200
Requesting YUYV 4:2:2 1600x1200
Resulting image format: YUYV 4:2:2 1600x1200
2018/08/09 21:26:30 connect from [2001:a61:5f2:900:f56e:b993:9bef:3d35]:64670 /
2018/08/09 21:26:37 Timeout occured

This is on a Raspberry Pi with Raspbian. I can successfully grab images from /dev/video0 device with the fswbcam program.

What am I doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.