Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect parameters for MFCopyImage?
    primarykey
    data
    text
    <p>I'm trying to create an IMFSample from a CImage so that I that I can encode a video from a series of images using a SinkWriter. Microsoft has a sample of how to do this with a DWORD array (instead of a CIMage) here: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff819477(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ff819477(v=vs.85).aspx</a> . Doing this involves using <code>MFCopyImage()</code>, but I am getting an ACCESS VIOLATION when calling this function, so I may be passing in the wrong parameters. I am new to C++.</p> <p>Working from their sample, this is what I've got:</p> <pre><code>CImage *img = LoadImage(); IMFSample *pSample = NULL; IMFMediaBuffer *pBuffer = NULL; const LONG cbWidth = img-&gt;GetBPP() / 8 * img-&gt;GetWidth(); const DWORD cbBuffer = cbWidth * img-&gt;GetHeight(); BYTE *pData = NULL; HRESULT hr = MFCreateMemoryBuffer(cbBuffer, &amp;pBuffer); if (SUCCEEDED(hr)) { hr = pBuffer-&gt;Lock(&amp;pData, NULL, NULL); } if (SUCCEEDED(hr)) { hr = MFCopyImage( pData, cbWidth, (BYTE*)img-&gt;GetBits(), cbWidth, cbWidth, img-&gt;GetHeight() ); // ACCESS VIOLATION HERE! } if (pBuffer) { pBuffer-&gt;Unlock(); } </code></pre> <p>Anyone know why this gets me an ACCESS VIOLATION ? Am I passing in the right values, especially for the stride? Based on this documentation: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb970554(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/bb970554(v=vs.85).aspx</a> , it was not clear to me what exactly this parameter is supposed to be.</p> <p>Update Dec 11: Changed code sample with corrections provided by @cha and @roman-r. Still getting the same error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload