diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamPixelFormat.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamPixelFormat.java index fe72cf65..dd6bf68f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamPixelFormat.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamPixelFormat.java @@ -6,8 +6,7 @@ public enum WebcamPixelFormat { //Only V4L2 formats defined in linux/videodev2.h are required here, declared in order of priority for supported formats PIX_FMT_RGB24("RGB3", true), PIX_FMT_YUYV("YUYV", true), - PIX_FMT_MJPG("MJPG", true), - PIX_FMT_NV12("NV12", false); + PIX_FMT_MJPG("MJPG", true); private final String name; private final boolean supported; @@ -25,6 +24,14 @@ public enum WebcamPixelFormat { return supported; } + public int getFourCC() { + char a = name.charAt(0); + char b = name.charAt(1); + char c = name.charAt(2); + char d = name.charAt(3); + return ((int) a) | ((int) b << 8) | ((int) c << 16) | ((int) d << 24); + } + public String toString() { return name; } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java index 6e076a5f..39760e08 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/WebcamService.java @@ -182,8 +182,13 @@ public class WebcamService extends ScheduledService { } } + //On Linux, formats not defined in WebcamPixelFormat are unsupported so ask for RGB3 + if(OsType.getCurrent() == OsType.UNIX && WebcamPixelFormat.fromFourCC(format.getFormatInfo().fourcc) == null) { + format.getFormatInfo().fourcc = WebcamPixelFormat.PIX_FMT_RGB24.getFourCC(); + } + if(log.isDebugEnabled()) { - log.debug("Opening capture stream on " + device + " with format " + format.getFormatInfo().width + "x" + format.getFormatInfo().height + " (" + WebcamPixelFormat.fourCCToString(format.getFormatInfo().fourcc) + ")"); + log.debug("Opening capture stream on " + device + " with format " + format.getFormatInfo().width + "x" + format.getFormatInfo().height + " (" + WebcamPixelFormat.fourCCToString(format.getFormatInfo().fourcc) + ")"); } opening.set(true);