- Timestamp:
- Jul 13, 2017, 8:02:57 AM (6 years ago)
- Location:
- trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/Application.cpp
r655 r770 1 1 //////////////////////////////////////////////////////////// 2 // Copyright (C) Roman Ryltsov, 2015-201 62 // Copyright (C) Roman Ryltsov, 2015-2017 3 3 // Created by Roman Ryltsov roman@alax.info 4 4 // … … 37 37 __C(MFCreateSourceResolver(&pSourceResolver)); 38 38 #pragma region Media Source 39 CCom QIPtr<IMFMediaSource> pMediaSource;39 CComPtr<IMFMediaSource> pMediaSource; 40 40 //{ 41 41 // static const LPCTSTR g_pszPath = … … 48 48 // __D(pMediaSource, E_NOINTERFACE); 49 49 //} 50 CComPtr<IMFMediaSource> pVideoMediaSource, pAudioMediaSource; 51 const SIZE g_Extent = { 640, 360 }; 52 const LONG g_nFrameRateNumerator = 30000; 53 const LONG g_nFrameRateDenominator = 1001; 54 const LONG g_nDuration = 1 * 60; // minutes 55 const LONG g_nVideoBitrate = (2 << 10) * 1000; // 2 MBps 56 const LONG g_nSampleRate = 48000; 57 const LONG g_nChannelCount = 1; 58 const LONG g_nBitDepth = 16; 59 const LONG g_nAudioBitrate = 20 * 1000; 60 #pragma region Video 61 if(TRUE) 50 62 { 51 63 using namespace AlaxInfoDirectShowReferenceSource; 52 CComPtr<IVideoMediaSource> pVideoMediaSource; 53 __C(pVideoMediaSource.CoCreateInstance(__uuidof(VideoMediaSource))); 54 __C(pVideoMediaSource->SetMediaType(640, 480, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_ARGB32)))); 55 //__C(pVideoMediaSource->SetMediaTypeAspectRatio(...)); 56 __C(pVideoMediaSource->SetMediaTypeRate(10000, 1000)); 57 __C(pVideoMediaSource->put_Duration(5.0)); 58 pMediaSource = pVideoMediaSource; 59 } 64 CComPtr<IVideoMediaSource> pSource; 65 __C(pSource.CoCreateInstance(__uuidof(VideoMediaSource))); 66 __C(pSource->SetMediaType(g_Extent.cx, g_Extent.cy, CComVariant(_PersistHelper::StringFromIdentifier(MEDIASUBTYPE_ARGB32)))); 67 //__C(pSource->SetMediaTypeAspectRatio(...)); 68 __C(pSource->SetMediaTypeRate(g_nFrameRateNumerator, g_nFrameRateDenominator)); 69 __C(pSource->put_Duration((DOUBLE) g_nDuration)); 70 pVideoMediaSource = pSource; 71 } 72 #pragma endregion 73 #pragma region Audio 74 if(TRUE) 75 { 76 using namespace AlaxInfoDirectShowReferenceSource; 77 CComPtr<IAudioMediaSource> pSource; 78 __C(pSource.CoCreateInstance(__uuidof(AudioMediaSource))); 79 __C(pSource->SetMediaType(NULL, g_nSampleRate, g_nChannelCount, g_nBitDepth)); 80 __C(pSource->put_Duration((DOUBLE) g_nDuration)); 81 pAudioMediaSource = pSource; 82 } 83 #pragma endregion 84 __D(pVideoMediaSource || pAudioMediaSource, E_UNNAMED); 85 if(pVideoMediaSource && pAudioMediaSource) 86 { 87 CComPtr<IMFCollection> pCollection; 88 __C(MFCreateCollection(&pCollection)); 89 __C(pCollection->AddElement(pVideoMediaSource)); 90 __C(pCollection->AddElement(pAudioMediaSource)); 91 __C(MFCreateAggregateSource(pCollection, &pMediaSource)); 92 } else 93 pMediaSource = pVideoMediaSource ? pVideoMediaSource : pAudioMediaSource; 94 _A(pMediaSource); 60 95 #pragma endregion 61 96 CPath sFilePath; … … 72 107 MF::CTopology pTopology; 73 108 //pTopology.Create(); 109 #pragma region Profile 74 110 CComPtr<IMFTranscodeProfile> pTranscodeProfile; 75 111 { 76 112 __C(MFCreateTranscodeProfile(&pTranscodeProfile)); 113 #pragma region Video 114 if(pVideoMediaSource) 77 115 { 78 116 MF::CAttributes pAttributes; 79 117 pAttributes.Create(8); 80 pAttributes[MF_MT_SUBTYPE] = MFVideoFormat_H264; 81 pAttributes[MF_MT_AVG_BITRATE] = (UINT32) (5 << 10) * 1000; // 12 MBps 82 pAttributes[MF_MT_FRAME_SIZE].SetSize(640, 480); 83 pAttributes[MF_MT_FRAME_RATE].SetRatio(10000, 1000); 118 pAttributes[MF_MT_SUBTYPE] = 119 MFVideoFormat_H264; 120 //MFVideoFormat_HEVC; 121 pAttributes[MF_MT_AVG_BITRATE] = (UINT32) g_nVideoBitrate; 122 pAttributes[MF_MT_FRAME_SIZE].SetSize(g_Extent.cx, g_Extent.cy); 123 pAttributes[MF_MT_FRAME_RATE].SetRatio(g_nFrameRateNumerator, g_nFrameRateDenominator); 84 124 __C(pTranscodeProfile->SetVideoAttributes(pAttributes)); 125 pAttributes.Trace(); 85 126 } 127 #pragma endregion 128 #pragma region Audio 129 if(pAudioMediaSource) 86 130 { 131 // NOTE: The following audio attributes can be set: https://msdn.microsoft.com/en-us/library/windows/desktop/dd369143 132 // Audio Media Types 133 // MF_TRANSCODE_DONOT_INSERT_ENCODER 134 // MF_TRANSCODE_ENCODINGPROFILE 135 // MF_TRANSCODE_QUALITYVSSPEED 87 136 MF::CAttributes pAttributes; 88 pAttributes.Create(1); 89 pAttributes[MF_TRANSCODE_CONTAINERTYPE] = MFTranscodeContainerType_MPEG4; 90 __C(pTranscodeProfile->SetContainerAttributes(pAttributes)); 137 pAttributes.Create(8); 138 pAttributes[MF_MT_SUBTYPE] = MFAudioFormat_AAC; 139 pAttributes[MF_MT_AUDIO_SAMPLES_PER_SECOND] = (UINT32) g_nSampleRate; 140 pAttributes[MF_MT_AUDIO_NUM_CHANNELS] = (UINT32) g_nChannelCount; 141 pAttributes[MF_MT_AUDIO_BITS_PER_SAMPLE] = (UINT32) g_nBitDepth; 142 pAttributes[MF_MT_AUDIO_AVG_BYTES_PER_SECOND] = (UINT32) g_nAudioBitrate; 143 __C(pTranscodeProfile->SetAudioAttributes(pAttributes)); 144 pAttributes.Trace(); 91 145 } 92 } 146 #pragma endregion 147 MF::CAttributes pAttributes; 148 pAttributes.Create(1); 149 pAttributes[MF_TRANSCODE_CONTAINERTYPE] = MFTranscodeContainerType_MPEG4; 150 __C(pTranscodeProfile->SetContainerAttributes(pAttributes)); 151 } 152 #pragma endregion 93 153 __C(MFCreateTranscodeTopology(pMediaSource, CT2CW((LPCTSTR) sFilePath), pTranscodeProfile, &pTopology.m_p)); 94 154 pTopology.Trace(); … … 102 162 MF::CMediaEvent pMediaEvent; 103 163 __C(pMediaSession->GetEvent(0, &pMediaEvent)); 164 pMediaEvent.Trace(); 104 165 MediaEventType Type; 105 166 __C(pMediaEvent->GetType(&Type)); 106 167 HRESULT nStatus; 107 168 __C(pMediaEvent->GetStatus(&nStatus)); 108 _Z4(atlTraceGeneral, 4, _T("Type %s, nStatus %s\n"), MF::CMediaEvent::FormatType(Type), MF::FormatResult(nStatus));109 169 switch(Type) 110 170 { 111 171 case MESessionTopologySet: 172 { 173 MF::CPropVariant vValue; 174 if(SUCCEEDED(pMediaEvent->GetValue(&vValue)) && vValue.vt == VT_UNKNOWN) 175 { 176 MF::CTopology pTopology; 177 pTopology.m_p = CComQIPtr<IMFTopology>(vValue.punkVal); 178 pTopology.Trace(); 179 } 180 } 112 181 break; 113 182 case MESessionTopologyStatus: -
trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/MfGenerate2.vcxproj
r655 r770 23 23 <Keyword>Win32Proj</Keyword> 24 24 <RootNamespace>MfGenerate2</RootNamespace> 25 <WindowsTargetPlatformVersion>10.0.1 0586.0</WindowsTargetPlatformVersion>25 <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion> 26 26 </PropertyGroup> 27 27 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> -
trunk/Utilities/DirectShowReferenceSource/Sample/MfGenerate2/targetver.h
r655 r770 1 1 //////////////////////////////////////////////////////////// 2 // Copyright (C) Roman Ryltsov, 2015 2 // Copyright (C) Roman Ryltsov, 2015-2017 3 3 // Created by Roman Ryltsov roman@alax.info 4 4 // … … 13 13 // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 14 14 15 #include <SDKDDKVer.h> 15 #include <winsdkver.h> 16 #include <sdkddkver.h>
Note: See TracChangeset
for help on using the changeset viewer.