diff --git a/camera.go b/camera.go index 383b7ed..82ffe02 100644 --- a/camera.go +++ b/camera.go @@ -8,7 +8,6 @@ import ( "os/signal" "regexp" "runtime" - "strconv" "strings" "syscall" ) @@ -73,9 +72,9 @@ func NewCamera(stream int) (*Camera, error) { var device string switch runtime.GOOS { case "linux": - device = "/dev/video" + strconv.Itoa(stream) + device = fmt.Sprintf("/dev/video%d", stream) case "darwin": - device = strconv.Itoa(stream) + device = fmt.Sprintf(`"%d"`, stream) case "windows": // If OS is windows, we need to parse the listed devices to find which corresponds to the // given "stream" index. @@ -83,10 +82,10 @@ func NewCamera(stream int) (*Camera, error) { if err != nil { return nil, err } - if stream >= len(devices) { + if stream < 0 || stream >= len(devices) { return nil, fmt.Errorf("could not find device with index: %d", stream) } - device = "video=" + devices[stream] + device = fmt.Sprintf("video=%s", devices[stream]) default: return nil, fmt.Errorf("unsupported OS: %s", runtime.GOOS) } diff --git a/videowriter.go b/videowriter.go index 404fbff..cca0954 100644 --- a/videowriter.go +++ b/videowriter.go @@ -102,7 +102,7 @@ func NewVideoWriter(filename string, width, height int, options *Options) (*Vide return nil, err } - writer := VideoWriter{filename: filename} + writer := &VideoWriter{filename: filename} if options == nil { options = &Options{} @@ -180,7 +180,7 @@ func NewVideoWriter(filename string, width, height int, options *Options) (*Vide } } - return &writer, nil + return writer, nil } // Once the user calls Write() for the first time on a VideoWriter struct,