<h5 dir="auto">System information (version)</h5>

<p dir="auto"><a href="https://github.com/opencv/opencv/files/5196784/OpenCV1.zip">OpenCV1.zip</a></p>
<p dir="auto">Hello,</p>
<p dir="auto">I make an example program with opencv on my main computer (windows 10 x64) with opencv4.4.0, visual c++ 2019 and it work fine on the main computer. I have compiled sources files as explain on the opencv site.</p>
<p dir="auto">When i try to run it on a windows 7 x64 computer after importing all the dll (core440, videoio,  ....) , i got the error :<br>
...opencv-4.4.0\modules\videoio\src\cap_msmf.cpp (682) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(unsupported media type)</p>
<p dir="auto">I am serarching all other the web for few hours now but found nothing helping me... Does someone here have a solution ?</p>
<p dir="auto">Thanks !</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &quot;opencv2/imgcodecs.hpp&quot;
#include &quot;opencv2/highgui.hpp&quot;
#include &quot;opencv2/imgproc.hpp&quot;
#include &lt;string&gt;
#include &lt;opencv2/core.hpp&gt;
#include &lt;opencv2/videoio.hpp&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	double Fiducial_Diameter = 0.5;
	Mat src;


	if (argc &lt; 3) {
		cerr &lt;&lt; &quot;ERROR! Argument missing\n&quot;;
		return -1;
	}
	string num  = argv[1];
	string diam = argv[2];

	VideoCapture cap;
	int deviceID = stoi(num);				// 0 = open default camera
	int apiID = cv::CAP_ANY;				// 0 = autodetect default API


		
	// open selected camera using selected API
	cap.open(deviceID, apiID);
	// check if we succeeded
	if (!cap.isOpened()) {
		cerr &lt;&lt; &quot;ERROR! Unable to open camera\n&quot;;
		return -1;
	}
	//--- GRAB AND WRITE LOOP
	cout &lt;&lt; &quot;Start grabbing&quot; &lt;&lt; endl
		&lt;&lt; &quot;Press any key to terminate&quot; &lt;&lt; endl;
	for (;;)
	{
		// wait for a new frame from camera and store it into 'frame'
		cap.read(src);
		// check if we succeeded
		if (src.empty()) {
			cerr &lt;&lt; &quot;ERROR! blank frame grabbed\n&quot;;
			break;
		}
		// show live and wait for a key with timeout long enough to show images
	// Get center of the image
		Point CenterOfImage = Point(src.size().width / 2, src.size().height / 2);
		circle(src, CenterOfImage, stoi(diam), Scalar(0, 255, 000), 1, LINE_AA);
		

		imshow(&quot;Live&quot;, src);
		if (waitKey(5) &gt;= 0)
			break;
	}
	return EXIT_SUCCESS;
}"><pre class="notranslate"><code class="notranslate">#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include &lt;string&gt;
#include &lt;opencv2/core.hpp&gt;
#include &lt;opencv2/videoio.hpp&gt;
#include &lt;iostream&gt;
#include &lt;stdio.h&gt;

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
	double Fiducial_Diameter = 0.5;
	Mat src;


	if (argc &lt; 3) {
		cerr &lt;&lt; "ERROR! Argument missing\n";
		return -1;
	}
	string num  = argv[1];
	string diam = argv[2];

	VideoCapture cap;
	int deviceID = stoi(num);				// 0 = open default camera
	int apiID = cv::CAP_ANY;				// 0 = autodetect default API


		
	// open selected camera using selected API
	cap.open(deviceID, apiID);
	// check if we succeeded
	if (!cap.isOpened()) {
		cerr &lt;&lt; "ERROR! Unable to open camera\n";
		return -1;
	}
	//--- GRAB AND WRITE LOOP
	cout &lt;&lt; "Start grabbing" &lt;&lt; endl
		&lt;&lt; "Press any key to terminate" &lt;&lt; endl;
	for (;;)
	{
		// wait for a new frame from camera and store it into 'frame'
		cap.read(src);
		// check if we succeeded
		if (src.empty()) {
			cerr &lt;&lt; "ERROR! blank frame grabbed\n";
			break;
		}
		// show live and wait for a key with timeout long enough to show images
	// Get center of the image
		Point CenterOfImage = Point(src.size().width / 2, src.size().height / 2);
		circle(src, CenterOfImage, stoi(diam), Scalar(0, 255, 000), 1, LINE_AA);
		

		imshow("Live", src);
		if (waitKey(5) &gt;= 0)
			break;
	}
	return EXIT_SUCCESS;
}
</code></pre></div>
<p dir="auto">Win 7, CMake 3.18.1, VS 2015 community, opencv <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/opencv/opencv/commit/422f802ec96feecbc9db2f60879e8fe364cf8a92/hovercard" href="https://github.com/opencv/opencv/commit/422f802ec96feecbc9db2f60879e8fe364cf8a92"><tt>422f802</tt></a> with Qt 5.15 and eigen.</p>
<p dir="auto">Reading a frame from <code class="notranslate">VideoCapture</code> thrown exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\videoio_registr
y.cpp (191) cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistr
y VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990)
; INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (370) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (175) cv::impl::DynamicLib::libraryLoad load c:\Lib\opencv\build_x64\bin\ope
ncv_videoio_gstreamer440_64d.dll =&gt; FAILED
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (175) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer440_64d
.dll =&gt; FAILED
[ WARN:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\cap_msmf.cpp (6
77) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30)
 MFVideoFormat_RGB24(codec not found)

Cap backend: MSMF"><pre class="notranslate"><code class="notranslate">[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\videoio_registr
y.cpp (191) cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistr
y VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990)
; INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (370) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (175) cv::impl::DynamicLib::libraryLoad load c:\Lib\opencv\build_x64\bin\ope
ncv_videoio_gstreamer440_64d.dll =&gt; FAILED
[ INFO:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\backend_plugin.
cpp (175) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer440_64d
.dll =&gt; FAILED
[ WARN:0] global C:\Lib\opencv\source\opencv\modules\videoio\src\cap_msmf.cpp (6
77) CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30)
 MFVideoFormat_RGB24(codec not found)

Cap backend: MSMF
</code></pre></div>
<p dir="auto">Test code:</p>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#include &lt;opencv2/imgcodecs.hpp&gt;
#include &lt;opencv2/videoio.hpp&gt;
#include &lt;opencv2//highgui.hpp&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	VideoCapture cap;
	Mat frame;
	bool bIsOpen = cap.open(0);
	cout &lt;&lt; &quot;\nCap backend: &quot; &lt;&lt; cap.getBackendName() &lt;&lt; endl;
	if (!bIsOpen) {
		cout &lt;&lt; &quot;Can't open camera!&quot; &lt;&lt; endl;
		return -1;
	}
	while (waitKey() != 27) {
		try {
			cap &gt;&gt; frame; //  &lt;- exception here
		}
		catch (Exception &amp;e) {
			cout &lt;&lt; e.err;
		}
		if (frame.empty()) {
			cout &lt;&lt; &quot;Empty frame captured!&quot; &lt;&lt; endl;
			return -1;
		}
		imshow(&quot;cap&quot;, frame);
	}

	return 0;
}
"><pre class="notranslate"><code class="notranslate">#include &lt;opencv2/imgcodecs.hpp&gt;
#include &lt;opencv2/videoio.hpp&gt;
#include &lt;opencv2//highgui.hpp&gt;
#include &lt;fstream&gt;
#include &lt;iostream&gt;

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
	VideoCapture cap;
	Mat frame;
	bool bIsOpen = cap.open(0);
	cout &lt;&lt; "\nCap backend: " &lt;&lt; cap.getBackendName() &lt;&lt; endl;
	if (!bIsOpen) {
		cout &lt;&lt; "Can't open camera!" &lt;&lt; endl;
		return -1;
	}
	while (waitKey() != 27) {
		try {
			cap &gt;&gt; frame; //  &lt;- exception here
		}
		catch (Exception &amp;e) {
			cout &lt;&lt; e.err;
		}
		if (frame.empty()) {
			cout &lt;&lt; "Empty frame captured!" &lt;&lt; endl;
			return -1;
		}
		imshow("cap", frame);
	}

	return 0;
}

</code></pre></div>
</details>
<p dir="auto">In debug it is seen that error occurs here:<br>
</p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/opencv/opencv/blob/dbab8d8c3897040f134af7195e130dbfcdc2c065/modules/core/src/copy.cpp#L298">opencv/modules/core/src/copy.cpp</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 298
      in
      <a data-pjax="true" class="commit-tease-sha" href="/opencv/opencv/commit/dbab8d8c3897040f134af7195e130dbfcdc2c065">dbab8d8</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L298" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="298"></td>
          <td id="LC298" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-c1">CV_IPP_RUN_FAST</span>(<span class="pl-c1">CV_INSTRUMENT_FUN_IPP</span>(ippiCopy_8u_C1R_L, sptr, (<span class="pl-k">int</span>)src.<span class="pl-smi">step</span>, dptr, (<span class="pl-k">int</span>)dst.<span class="pl-smi">step</span>, <span class="pl-c1">ippiSizeL</span>(sz.<span class="pl-smi">width</span>, sz.<span class="pl-smi">height</span>)) &gt;= <span class="pl-c1">0</span>) </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto">Reproduced on several different PC with different cameras.</p>
<p dir="auto">Last known OpenCV ver. where this code work is 4.12.</p>