-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
DirectShow: VideoCapture returns blank frames for OBS Virtual Camera on Windows #19746
Description
System information (version)
- OpenCV => 4.5.1.48 (opencv-python)
- Operating System / Platform => Windows 10 64 Bit
Detailed description
OBS installs a DirectShow virtual camera which works fine in Zoom etc. but not in OpenCV via VideoCapture, all frames are either zeros or a bit of garbage at the top of the frame. I also checked it against the CommandCam tool which is a simple C++ frame grabber written in a single straight-forward file. No problems there as well. This is what commandcam.exe /details shows:
2. OBS Virtual Camera
Pin: Video Output, 6 caps
Cap 0: FORMAT_VideoInfo, NV12, 12 bits, 1920x1080 @ 30 fps
Cap 1: FORMAT_VideoInfo, I420, 12 bits, 1920x1080 @ 30 fps
Cap 2: FORMAT_VideoInfo, YUY2, 16 bits, 1920x1080 @ 30 fps
Cap 3: FORMAT_VideoInfo, NV12, 12 bits, 1280x720 @ 20 fps
Cap 4: FORMAT_VideoInfo, I420, 12 bits, 1280x720 @ 20 fps
Cap 5: FORMAT_VideoInfo, YUY2, 16 bits, 1280x720 @ 20 fps
I tried all pixel formats and resolutions (with the tool) and it worked for all combinations.
Steps to reproduce
First, install OBS. The virtual camera always streams a dummy picture.
Then, grab a frame with OpenCV.
def decode_fourcc(fourcc):
return chr((fourcc & 0xff)) + chr((fourcc & 0xff00) >> 8) + chr((fourcc & 0xff0000) >> 16) + chr((fourcc & 0xff000000) >> 24)
vc = cv2.VideoCapture(2, cv2.CAP_DSHOW)
assert vc.isOpened()
fourcc = decode_fourcc(int(vc.get(cv2.CAP_PROP_FOURCC)))
print(f'fourcc: {fourcc}') # fourcc: }ë6ä --> with my real webcam this is YUY2
for _ in range(1000):
ret, frame_captured = vc.read()
assert ret
print(frame_captured.min(), frame_captured.max())
# 0 0I should also mention that I set the environment variable OPENCV_DSHOW_SAVEGRAPH_FILENAME=graph.grf and GraphEdit cannot open the file. It can open the file when I capture something from my real webcam device however. So somehow the filter graph must be broken.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found solution - I updated to latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc