From 2d11edd1031b8651cbedef40937ed58972eb05a9 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 27 May 2020 17:52:17 +0300 Subject: [PATCH] videoio/MSMF: fixed audio stream handling --- modules/videoio/src/cap_msmf.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/videoio/src/cap_msmf.cpp b/modules/videoio/src/cap_msmf.cpp index 119873b..15b1d2a 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; -- 2.7.4