1

I have multiple cameras in my Windows 11 system and I am wondering how to get all avaiable resolutions for them. I am not intending to make a video capture, but I am willing to just get these properties.

Also, I don't care which API to use, be it DirectShow or MMF (Microsoft Media Foundation). I haven't used any of these before either.

I have found multiple resources doing that in C# (as in here), but similar suggested answers for C++ are hard to understand - some code is given, but what libraries and 'includes' used is not given (as in here)

I have also checked DirectShow samples in hope something would be there, but I didn't find anything.

So, I checked MMF as well (1, 2, 3) and docs, but all posts seem pretty outdated and no full code is given showing how to use certain functions alongside proper 'includes', as trying the code gives me unresolved symbols.

So I am kind of stuck at the moment, I can't find a solution to this.

I would appreciate any help.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Bobbie
  • 163
  • 1
  • 11

1 Answers1

2

Also, I don't care which API to use, be it DirectShow or MMF (Microsoft Media Foundation). I haven't used any of these before either.

You generally do care because the data might be different.

With Media Foundation, see How to Set the Video Capture Format

Call IMFMediaTypeHandler::GetMediaTypeCount to get the number of supported formats.

You might also want to have a look at Tanta: Windows Media Foundation Sample Projects and sample code there.

With DirectShow, see Webcamera supported video formats in addition to links you found; you will have to sort out includes and libraries through, among SDK samples AMCap does some one this and can be built from source without additional external libraries, from original code or from this fork adopted to most recent VS.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thank you! It seems I have come closer to a solution, however I still have some unresolved symbols. Here is what I achieved so far: https://pastebin.com/PnwzXmg2 I used the links you've sent and Microsoft Docs. The unresolved symbols are here: https://pastebin.com/v5uGRHac Perhaps you could point out on an include that I have forgotten? Thanks! – Bobbie Jan 14 '22 at 15:36
  • 1
    `#pragma comment(lib, "mfuuid")`, like [here](https://stackoverflow.com/q/26336450/868014) – Roman R. Jan 14 '22 at 15:54
  • That worked, thank you! I am now able to launch the code. Howver, for some reason: `hr = ppDevices[0]->ActivateObject(IID_PPV_ARGS(&pSource));` returns `FAILED`. Is there any particular reason why that can happen? – Bobbie Jan 14 '22 at 16:28
  • 1
    "`FAILED`" means that there is some negative value compard to zero inside this macro. You need to figure out whta it is exactly, check it out at https://www.magnumdb.com/ and then figure out the identifier matching the value. This will explain the reason. – Roman R. Jan 14 '22 at 16:32
  • This is amazing. The error code was `-2147221008` which corresponds to `CO_E_NOTINITIALIZED`. It should be fixed with calling CoInitialize(NULL) at the start of the program and calling CoUninitialize() at the end of the program. I didn't know about this website by the way, very useful. Thank you very much for your time and effort, Roman! I achieved what I wanted. – Bobbie Jan 14 '22 at 17:10