diff --git a/common-mod/build.gradle b/common-mod/build.gradle index 1b79147..0157f7d 100644 --- a/common-mod/build.gradle +++ b/common-mod/build.gradle @@ -13,6 +13,8 @@ repositories { } } +compileJava.dependsOn(':common:shadowJar') + dependencies { implementation("org.openpnp:opencv:${opencv_version}") diff --git a/common-mod/src/main/java/ru/dimaskama/webcam/client/cap/CapturingDevice.java b/common-mod/src/main/java/ru/dimaskama/webcam/client/cap/CapturingDevice.java index 1969208..c83edb8 100644 --- a/common-mod/src/main/java/ru/dimaskama/webcam/client/cap/CapturingDevice.java +++ b/common-mod/src/main/java/ru/dimaskama/webcam/client/cap/CapturingDevice.java @@ -57,6 +57,7 @@ public void run() { int realWidth = 0, realHeight = 0; int lastFps = 0; int realFps = 0; + boolean formatChecked = false; VideoCapture cap = new VideoCapture(deviceNumber); Mat mat = new Mat(); @@ -72,6 +73,7 @@ public void run() { cap.set(CAP_PROP_FRAME_HEIGHT, resolution.height); realWidth = (int) Math.round(cap.get(CAP_PROP_FRAME_WIDTH)); realHeight = (int) Math.round(cap.get(CAP_PROP_FRAME_HEIGHT)); + formatChecked = false; } int fps = this.fps; if (lastFps != fps) { @@ -82,6 +84,17 @@ public void run() { if (!cap.read(mat)) { throw new DeviceException(Component.translatable("webcam.error.device_disconnected", deviceNumber)); } + + if (!formatChecked) { + formatChecked = true; + org.opencv.core.Scalar sum = org.opencv.core.Core.sumElems(mat); + // Some virtual cameras (OBSBOT) output NV12 which DSHOW can't convert to RGB, causing black frames. + // Detect this and force NV12 format explicitly. + if (mat.channels() == 3 && sum.val[0] == 0 && sum.val[1] == 0 && sum.val[2] == 0) { + cap.set(CAP_PROP_FOURCC, org.opencv.videoio.VideoWriter.fourcc('N', 'V', '1', '2')); + } + } + onFrame(realFps, realWidth, realHeight, mat); } } finally { diff --git a/paper/build.gradle b/paper/build.gradle index 5146b98..4eb8849 100644 --- a/paper/build.gradle +++ b/paper/build.gradle @@ -18,6 +18,8 @@ repositories { } } +compileJava.dependsOn(':common:shadowJar') + dependencies { implementation "io.netty:netty-handler:${netty_version}" implementation "io.netty:netty-buffer:${netty_version}"