RTMP Streaming Directshow Filter

How to use the RTMP Streaming Directshow Filter



This article is intended to show you how to use the RTMP Streaming Directshow Filters in a simple application with default parameters.

Start by calling CoInitialize to initialize the COM library:     

HRESULT hr = CoInitialize(NULL);


Next, call CoCreateInstance to create the Filter Graph Manager.

hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph);


IBaseFilter *pVCap; // Video capture filter. Initialize pVCap and add it to the filter graph (not shown)
IBaseFilter *pACap; // Audio capture filter. Initialize pACap and add it to the filter graph (not shown)

call CoCreateInstance to create the RTMP Streaming Directshow Filter
 

CComPtr pRTMPFilter;
CComPtr pRTMPFilterConfig;
std::wstring strURL=L"rtmp://localhost:1935/live/myStream";
hr = CoCreateInstance(CLSID_ViscomsoftRTMPStreamingFilter, NULL, CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void **)&pRTMPFilter);
pRTMPFilter->QueryInterface(IID_IRTMPStreamingConfig, (void**)&pRTMPFilterConfig);
pRTMPFilterConfig->setRMTPUrl(strURL.c_str());
pRTMPFilterConfig->setVideoBitrate(1000000);
pRTMPFilterConfig->setAudioSamplesPerSecond(SamplingFrequency::Audio_48000);
pRTMPFilterConfig->setAudioBitrate(AudioBitrate::Bitrate_96Kbps);
pRTMPFilterConfig->setH264Profile(H264Profile::Main_Profile);
pRTMPFilterConfig->setVideoQuality(4);


Add RTMP Streaming Directshow Filter to the graph.

hr = pGraph->AddFilter(pRTMPFilter, L"RTMP Streaming Filter");


Connect Video Capture Filter to RTMP Streaming Directshow Filter, connectFilters() can be found in VC++ sample.
 

hr = dsHelper.connectFilters(pGraph, pVCap, pRTMPFilter);

  Connect Audio Capture Filter to RTMP Streaming Directshow Filter, connectFilters() can be found in VC++ sample.
 

hr = dsHelper.connectFilters(pGraph, pACap, pRTMPFilter);

Query the IMediaControl interface to control the streaming.
 

hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);

Run the graph.
 

hr = pControl->Run();

When you close your application, close the COM library.
 

CoUninitialize();