I am trying to follow through the DirectShow examples on the windows dev center to make my own application that can capture screen and audio to video. https://msdn.microsoft.com/en-us/library/windows/desktop/dd318627(v=vs.85).aspx
When I run through the RenderStream
method fails and the HRESULT_CODE
is 16387.
Here is my code. I've read lots of examples and can't quite get my head around it all. I'd love to get something really basic working so I can expand it on my own.
I realize it won't be best practice etc. I am very rusty with C++ and new to DirectShow so please don't be too critical and feel free to explain like I'm a bit simple!
Here is the code I have:
void AudioVideoBuilder::AVBuilder::MakeVideo()
{
IGraphBuilder *pGraph = NULL;
ICaptureGraphBuilder2 *pBuild = NULL;
// Create the Filter Graph Manager.
HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);
if (SUCCEEDED(hr))
{
// Create the Capture Graph Builder.
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL,
CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2,
(void **)&pBuild);
if (SUCCEEDED(hr))
{
pBuild->SetFiltergraph(pGraph);
}
};
IBaseFilter *pCap = 0;
if (SUCCEEDED(hr))
{
// Create the Capture Graph Builder.
hr = CoCreateInstance(CLSID_CaptureGraphBuilder2,
NULL,
CLSCTX_INPROC_SERVER,
IID_ICaptureGraphBuilder2,
(void**)&pBuild);
IBaseFilter *pMux;
if (SUCCEEDED(hr))
{
hr = pBuild->SetOutputFileName(
&MEDIASUBTYPE_Avi, // Specifies AVI for the target file.
L"C:\\Example.avi", // File name.
&pMux, // Receives a pointer to the mux.
NULL); // (Optional) Receives a pointer to the file sink.
if (SUCCEEDED(hr))
{
hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE, // Pin category.
&MEDIATYPE_Audio, // Media type.
pCap, // Capture filter.
NULL, // Intermediate filter (optional).
pMux); // Mux or file sink filter.
if (SUCCEEDED(hr))
{
hr = pBuild->RenderStream(
&PIN_CATEGORY_CAPTURE, // Pin category.
&MEDIATYPE_Video, // Media type.
pCap, // Capture filter.
NULL, // Intermediate filter (optional).
pMux); // Mux or file sink filter.
// Release the mux filter.
pMux->Release();
IConfigAviMux *pConfigMux = NULL;
hr = pMux->QueryInterface(IID_IConfigAviMux, (void**)&pConfigMux);
if (SUCCEEDED(hr))
{
pConfigMux->SetMasterStream(0);
pConfigMux->Release();
}
IConfigInterleaving *pInterleave = NULL;
hr = pMux->QueryInterface(IID_IConfigInterleaving, (void**)&pInterleave);
if (SUCCEEDED(hr))
{
pInterleave->put_Mode(INTERLEAVE_CAPTURE);
pInterleave->Release();
}
}
else
{
DWORD error = HRESULT_CODE(hr);
}
}
else
{
DWORD error = HRESULT_CODE(hr);
}
}
}
else
{
DWORD error = HRESULT_CODE(hr);
}
}