diff --git a/modules/videoio/src/cap_msmf.cpp b/modules/videoio/src/cap_msmf.cpp index 119873beb0..15b1d2ade7 100644 --- a/modules/videoio/src/cap_msmf.cpp +++ b/modules/videoio/src/cap_msmf.cpp @@ -487,12 +487,14 @@ public: } } } - std::pair findBest(const MediaType& newType) + std::pair findBestVideoFormat(const MediaType& newType) { std::pair best; std::map::const_iterator i = formats.begin(); for (; i != formats.end(); ++i) { + if (i->second.majorType != MFMediaType_Video) + continue; if (newType.isEmpty()) // file input - choose first returned media type { best = *i; @@ -770,7 +772,12 @@ bool CvCapture_MSMF::configureOutput(MediaType newType, cv::uint32_t outFormat) { FormatStorage formats; formats.read(videoFileSource.Get()); - std::pair bestMatch = formats.findBest(newType); + std::pair bestMatch = formats.findBestVideoFormat(newType); + if (bestMatch.second.isEmpty()) + { + CV_LOG_DEBUG(NULL, "Can not find video stream with requested parameters"); + return false; + } dwStreamIndex = bestMatch.first.stream; nativeFormat = bestMatch.second; MediaType newFormat = nativeFormat;