Skip to content

Commit 4b5fdc6

Browse files
committed
Merge pull request opencv#17406 from mshabunin:fix-msmf-audio-handling
2 parents fef6192 + 2d11edd commit 4b5fdc6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

modules/videoio/src/cap_msmf.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,12 +487,14 @@ class FormatStorage
487487
}
488488
}
489489
}
490-
std::pair<MediaID, MediaType> findBest(const MediaType& newType)
490+
std::pair<MediaID, MediaType> findBestVideoFormat(const MediaType& newType)
491491
{
492492
std::pair<MediaID, MediaType> best;
493493
std::map<MediaID, MediaType>::const_iterator i = formats.begin();
494494
for (; i != formats.end(); ++i)
495495
{
496+
if (i->second.majorType != MFMediaType_Video)
497+
continue;
496498
if (newType.isEmpty()) // file input - choose first returned media type
497499
{
498500
best = *i;
@@ -770,7 +772,12 @@ bool CvCapture_MSMF::configureOutput(MediaType newType, cv::uint32_t outFormat)
770772
{
771773
FormatStorage formats;
772774
formats.read(videoFileSource.Get());
773-
std::pair<FormatStorage::MediaID, MediaType> bestMatch = formats.findBest(newType);
775+
std::pair<FormatStorage::MediaID, MediaType> bestMatch = formats.findBestVideoFormat(newType);
776+
if (bestMatch.second.isEmpty())
777+
{
778+
CV_LOG_DEBUG(NULL, "Can not find video stream with requested parameters");
779+
return false;
780+
}
774781
dwStreamIndex = bestMatch.first.stream;
775782
nativeFormat = bestMatch.second;
776783
MediaType newFormat = nativeFormat;

0 commit comments

Comments
 (0)