This article is intended to show you how to use the Direct MP4 Encoder 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);
Add the following header file. #include <InitGuid.h> #include "directmp4encoderuids.h"
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 Direct MP4 Encoder Directshow Filter
CComPtr mMP4EncoderFilter; hr = CoCreateInstance(CLSID_ViscomsoftDirectMP4Encoder, NULL, CLSCTX_INPROC_SERVER,IID_IBaseFilter,(void **)&mMP4EncoderFilter);
Add Direct MP4 Encoder Directshow Filter to the graph and set the MP4 file name.
hr = pGraph->AddFilter(mMP4EncoderFilter, L"Direct MP4 Encoder Filter"); CComQIPtr<IFileSinkFilter> pSink(mMP4EncoderFilter); if(!pSink) { return hr; } pSink->SetFileName(L"c:\\temp\\myfile.mp4", NULL);
Setup the Direct MP4 Encoder parameter.
CComQIPtr<IMP4Manager, &IID_IDirectMP4EncoderConfig> pProfile(mMP4EncoderFilter); pProfile->SetH264Preset(L"superfast"); pProfile->SetMp4VideoBitrate(m_iMp4Videobitrate); pProfile->SetMp4AspectRatio(m_bMp4AspectRatio); pProfile->SetMp4AudioBitrate(m_iMp4Audiobitrate); pProfile->SetMp4AudioSampleRate(m_iMp4AudioSamplerate); pProfile->SetMp4AudioChannel(m_iMp4Audiochannel); pProfile->SetMp4FrameRate(m_iMp4FrameRate); pProfile->SetMp4Resolution(m_iMp4Width,m_iMp4Height); pProfile->SetTitle(m_strMyMP4Title.AllocSysString()); pProfile->SetAlbum(m_strMyMP4Album.AllocSysString()); pProfile->SetAuthor(m_strMyMP4Author.AllocSysString()); pProfile->SetComment(m_strMyMP4Comment.AllocSysString()); pProfile->SetCopyright(m_strMyMP4Copyright.AllocSysString());
Connect Video Capture Filter to Direct MP4 Encoder Directshow Filter, connectFilters() can be found in VC++ sample.
hr = dsHelper.connectFilters(pGraph, pVCap, mMP4EncoderFilter);
Connect Audio Capture Filter to Direct MP4 Encoder Directshow Filter, connectFilters() can be found in VC++ sample.
hr = dsHelper.connectFilters(pGraph, pACap, mMP4EncoderFilter);
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();
|