-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example using cgo; example device fmt; updating webcam example
- Loading branch information
1 parent
aab6d9c
commit eab8daf
Showing
5 changed files
with
543 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"strings" | ||
|
||
"github.com/vladimirvivien/go4vl/v4l2" | ||
) | ||
|
||
func main() { | ||
devName := "/dev/video0" | ||
width := 640 | ||
height := 480 | ||
format := "yuyv" | ||
|
||
flag.StringVar(&devName, "d", devName, "device name (path)") | ||
flag.IntVar(&width, "w", width, "capture width") | ||
flag.IntVar(&height, "h", height, "capture height") | ||
flag.StringVar(&format, "f", format, "pixel format") | ||
flag.Parse() | ||
|
||
device, err := v4l2.Open(devName) | ||
if err != nil { | ||
log.Fatalf("failed to open device: %s", err) | ||
} | ||
defer device.Close() | ||
|
||
currFmt, err := device.GetPixFormat() | ||
if err != nil { | ||
log.Fatalf("unable to get format: %s", err) | ||
} | ||
log.Printf("Current format: %s", currFmt) | ||
|
||
fmtEnc := v4l2.PixelFmtYUYV | ||
switch strings.ToLower(format) { | ||
case "mjpeg": | ||
fmtEnc = v4l2.PixelFmtMJPEG | ||
case "h264", "h.264": | ||
fmtEnc = v4l2.PixelFmtH264 | ||
case "yuyv": | ||
fmtEnc = v4l2.PixelFmtYUYV | ||
} | ||
|
||
if err := device.SetPixFormat(v4l2.PixFormat{ | ||
Width: uint32(width), | ||
Height: uint32(height), | ||
PixelFormat: fmtEnc, | ||
Field: v4l2.FieldNone, | ||
}); err != nil { | ||
log.Fatalf("failed to set format: %s", err) | ||
} | ||
|
||
currFmt, err = device.GetPixFormat() | ||
if err != nil { | ||
log.Fatalf("unable to get format: %s", err) | ||
} | ||
log.Printf("Updated format: %s", currFmt) | ||
} |
Oops, something went wrong.