Repository: opencv
Issue: cv2.CAP_ANY (MSMF) not support high resolution webcam
Labels: bug,category: videoio(camera),platform: win32

### System Information

OpenCV python version: 4.9.0
Operating System / Platform: Windows 10 pro
Python version: 3.11



### Detailed description

I'm not able to use MSMF with high resolution

Logs:
```
[DEBUG:0@0.030] global videoio_registry.cpp:218 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.038] global videoio_registry.cpp:242 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.046] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ WARN:0@0.054] global cap.cpp:270 cv::VideoCapture::open VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0@0.057] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0@0.061] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\thaip\AppData\Roaming\Python\Python311\site-packages\cv2\opencv_videoio_gstreamer490_64.dll => FAILED
[ INFO:0@0.069] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer490_64.dll => FAILED
[ WARN:0@0.072] global cap.cpp:332 cv::VideoCapture::open VIDEOIO(GSTREAMER): backend is not available (plugin is missing, or can't be loaded due dependencies or it is not compatible)
[ WARN:0@0.078] global cap.cpp:270 cv::VideoCapture::open VIDEOIO(MSMF): trying capture cameraNum=0 ...
[ INFO:0@0.228] global cap_msmf.cpp:1031 CvCapture_MSMF::configureHW MSMF: Using D3D11 video acceleration on GPU device: NVIDIA GeForce RTX 2080 Ti
[DEBUG:0@0.330] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) NV12
[DEBUG:0@0.334] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) MFVideoFormat_RGB32
[ WARN:0@6.797] global cap.cpp:282 cv::VideoCapture::open VIDEOIO(MSMF): created, isOpened=1
[DEBUG:0@6.800] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 10) NV12
[DEBUG:0@6.803] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 10) MFVideoFormat_RGB32
[DEBUG:0@12.903] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (3840x2160 @ 1) YUY2
[DEBUG:0@12.907] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (3840x2160 @ 1) MFVideoFormat_RGB32
[DEBUG:0@18.908] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[DEBUG:0@18.912] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[DEBUG:0@24.891] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
[ WARN:0@34.900] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Error: Failed to capture frame
[DEBUG:0@34.904] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@34.907] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.909] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@34.912] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.915] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@34.917] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.919] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@34.923] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
4000x3000
[DEBUG:0@34.925] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
[ WARN:0@44.937] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Error: Failed to capture frame
[DEBUG:0@44.941] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@44.944] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.946] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@44.949] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.952] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@44.955] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.957] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@44.960] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
4000x3000
[DEBUG:0@44.962] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
```

### Steps to reproduce

When i try to use max resolution of my webcam:
```
cap = cv2.VideoCapture(0, cv2.CAP_ANY)

cap.set(cv2.CAP_PROP_FPS, 10)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 4656)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 3496) 
```

Logs:
```
[DEBUG:0@0.030] global videoio_registry.cpp:218 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.038] global videoio_registry.cpp:242 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.046] global videoio_registry.cpp:244 cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930); OBSENSOR(920)
[ WARN:0@0.054] global cap.cpp:270 cv::VideoCapture::open VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0@0.057] global backend_plugin.cpp:383 cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0@0.061] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load C:\Users\thaip\AppData\Roaming\Python\Python311\site-packages\cv2\opencv_videoio_gstreamer490_64.dll => FAILED
[ INFO:0@0.069] global plugin_loader.impl.hpp:67 cv::plugin::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer490_64.dll => FAILED
[ WARN:0@0.072] global cap.cpp:332 cv::VideoCapture::open VIDEOIO(GSTREAMER): backend is not available (plugin is missing, or can't be loaded due dependencies or it is not compatible)
[ WARN:0@0.078] global cap.cpp:270 cv::VideoCapture::open VIDEOIO(MSMF): trying capture cameraNum=0 ...
[ INFO:0@0.228] global cap_msmf.cpp:1031 CvCapture_MSMF::configureHW MSMF: Using D3D11 video acceleration on GPU device: NVIDIA GeForce RTX 2080 Ti
[DEBUG:0@0.330] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) NV12
[DEBUG:0@0.334] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 30) MFVideoFormat_RGB32
[ WARN:0@6.797] global cap.cpp:282 cv::VideoCapture::open VIDEOIO(MSMF): created, isOpened=1
[DEBUG:0@6.800] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 10) NV12
[DEBUG:0@6.803] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (640x480 @ 10) MFVideoFormat_RGB32
[DEBUG:0@12.903] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (3840x2160 @ 1) YUY2
[DEBUG:0@12.907] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (3840x2160 @ 1) MFVideoFormat_RGB32
[DEBUG:0@18.908] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[DEBUG:0@18.912] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[DEBUG:0@24.891] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
[ WARN:0@34.900] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Error: Failed to capture frame
[DEBUG:0@34.904] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@34.907] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.909] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@34.912] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.915] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@34.917] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@34.919] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@34.923] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
4000x3000
[DEBUG:0@34.925] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
[ WARN:0@44.937] global cap_msmf.cpp:1768 CvCapture_MSMF::grabFrame videoio(MSMF): can't grab frame. Error: -2147483638
Error: Failed to capture frame
[DEBUG:0@44.941] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@44.944] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.946] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@44.949] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.952] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) NV12
[ WARN:0@44.955] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
[DEBUG:0@44.957] global cap_msmf.cpp:914 CvCapture_MSMF::initStream Init stream 0 with MediaType (4000x3000 @ 10) MFVideoFormat_RGB32
[ WARN:0@44.960] global cap_msmf.cpp:928 CvCapture_MSMF::initStream Failed to select stream 0
4000x3000
[DEBUG:0@44.962] global cap_msmf.cpp:533 `anonymous-namespace'::SourceReaderCB::Wait videoio(MSMF): waiting for frame...
```

If i use normal DSHOW (Which not support GPU), it's work perfectly
```
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
```

When i try to use lower resolution of my webcam, it work normally with GPU usage
```
cap = cv2.VideoCapture(0, cv2.CAP_ANY)

cap.set(cv2.CAP_PROP_FPS, 30)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2048)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1536) 
```

My webcam support:
```
# 4656x3496 MJPEG@10fps  YUY2 1fps      4208x3120MJPEG@10fps  YUY2 1fps
# 4160x3120 MJPEG@10fps  YUY2 1fps      4000x3000MJPEG@10fps  YUY2 1fps
# 3840x2160 MJPEG@10fps  YUY2 1fps      3264x2448MJPEG@10fps  YUY2 1fps
# 2592x1944 MJPEG@10fps  YUY2 1fps      2320x1744MJPEG@30fps  YUY2 1fps 
# 2048x1536 MJPEG@30fps  YUY2 1fps      1920x1080MJPEG@30fps  YUY2 5fps 
# 1600x1200 MJPEG@30fps  YUY2 5fps      1280x960MJPEG@10fps  YUY2 10fps 
# 1280x720 MJPEG@30fps  YUY2 10fps      1024x768MJPEG@10fps  YUY2 10fps 
# 800x600 MJPEG@30fps  YUY2 15fps       640x480MJPEG@30fps  YUY2 30fps 
```

### Issue submission checklist

- [X] I report the issue, it's not a question
- [X] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- [ ] I updated to the latest OpenCV version and the issue is still there
- [ ] There is reproducer code and related data files (videos, images, onnx, etc)