log a debug message if a capture backend is generally available but isn't capabable of a capture mode#22700
Conversation
modules/videoio/src/cap.cpp
Outdated
|
|
||
| if(!foundFilenameBackend && cv::videoio_registry::hasBackend(static_cast<VideoCaptureAPIs>(apiPreference))) | ||
| { | ||
| CV_CAPTURE_LOG_DEBUG(NULL, |
There was a problem hiding this comment.
I believe CV_LOG_WARNING could be used in this case directly (without preconditions).
modules/videoio/src/cap.cpp
Outdated
| //Check if the backend generally is available but can't be used to capture by filename | ||
| bool foundFilenameBackend = false; | ||
| for (size_t i = 0; i < backends.size(); i++) | ||
| { | ||
| if((foundFilenameBackend = (apiPreference == backends[i].id))) | ||
| break; | ||
| } |
There was a problem hiding this comment.
Instead of scanning in multiple places we could add internal call:
const VideoBackendInfo& cv::videoio_registry::getBackendInfo(VideoCaptureAPIs api)
(similar to cv::videoio_registry::getBackendName() but non-public).
And then use VideoBackendInfo::mode field directly.
There was a problem hiding this comment.
Sounds like a plan
There was a problem hiding this comment.
I am not sure what internal in that case means. cv::videoio_registry::internal?
There was a problem hiding this comment.
"internal" means that it should not be a part of OpenCV public API.
- declaration should go to
src/videoio_registry.hpp - definition/implementation
src/videoio_registry.cpp
You could add ::internal nested namespace as your wish.
| namespace videoio_registry { namespace internal { | ||
| const VideoBackendInfo& getBackendInfo(VideoCaptureAPIs api) | ||
| { |
There was a problem hiding this comment.
Please avoid indentation in namespaces
| if (api == CAP_ANY) | ||
| CV_Error(Error::StsError, "Wrong backend ID: CAP_ANY"); |
There was a problem hiding this comment.
CV_Assert(api != CAP_ANY); is preferable (this check is an internal assumption)
| } | ||
|
|
||
| CV_Error(Error::StsError, "Unknown backend ID"); | ||
| return builtin_backends[0]; // unreachable but necessary to silence warnings |
There was a problem hiding this comment.
silence warnings
Which build configuration provides warning?
builtin_backends[0]
This array may be empty. So even a zero/first element is invalid.
There was a problem hiding this comment.
silence warnings
Which build configuration provides warning?
I can't tell you exactly because it was the CI that was failing with a warning because of returning a temporary. Changing the code to this suppressed the warning.
builtin_backends[0]This array may be empty. So even a zero/first element is invalid.
Of course, but it's (supposed) to be unreachable. How would you like me to handle that case?
| if (api == CAP_ANY) | ||
| CV_Error(Error::StsError, "Wrong backend ID: CAP_ANY"); | ||
|
|
||
| const int N = sizeof(builtin_backends)/sizeof(builtin_backends[0]); |
There was a problem hiding this comment.
builtin_backends
Not correct.
We should use VideoBackendRegistry::enabledBackends instead.
We need to add getter for this "protected" field:
const std::vector<VideoBackendInfo>& getEnabledBackends() const
{
return enabledBackends;
}
| return info; | ||
| } | ||
|
|
||
| CV_Error(Error::StsError, "Unknown backend ID"); |
There was a problem hiding this comment.
This exception changes existed behavior of .open() method of VideoCapture for non-existed/disabled backends.
Perhaps we need to return pointer (const VideoBackendInfo*) and check for NULL in caller.
There was a problem hiding this comment.
Should I implement it like that?
There was a problem hiding this comment.
This is internal API, so it could be adopted later if you have better solution.
Anyway implementation should not raise exception through CV_Error() (as high-level API of VideoCapture doesn't do that in case of failure of opening process).
Changing that behavior would break a lot of existed user code. This is a compatibility question.
|
@opencv-alalek Could do you have updates? |
|
@asmorkalov There is nothing to add from my side. No idea which updates are expected here. |
The open question is if it should be implemented like that. |
…sn't capabable of a capture mode.
8a71dda to
a2be9e9
Compare
|
@kallaballa I simplified your solution a bit and squashed commits. It works as expected now: |
|
thx! |
|
I'm receiving this warning when attempting to capture from a UDP stream using FFMPEG as a backend in a Docker container: I think this warning could do with a bit of an evaluation as it took an awful lot of digging to get to here to figure out what was going on, and I'm still not entirely sure why my VideoCapture is failing - as it works outside the container and fails inside. This warning implies that FFMPEG is installed correctly and OpenCV is too, unless I'm completely mistaken. |
Hi! |
The pertaining issue: #22699
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.