Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid argument on capture #51

Open
metal3d opened this issue May 18, 2022 · 0 comments
Open

Invalid argument on capture #51

metal3d opened this issue May 18, 2022 · 0 comments

Comments

@metal3d
Copy link

metal3d commented May 18, 2022

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant