request rgb3 pixel format on linux where returned format is unsupported

This commit is contained in:
Craig Raw 2025-06-02 16:28:44 +02:00
parent 31ce3ce68a
commit 8885e48ed9
2 changed files with 15 additions and 3 deletions

View file

@ -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;
}

View file

@ -182,8 +182,13 @@ public class WebcamService extends ScheduledService<Image> {
}
}
//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);