├── .gitignore ├── Common └── MFUtility.h ├── LICENSE ├── MFAudio ├── MFAudio.cpp ├── MFAudio.sln └── MFAudio.vcxproj ├── MFAudioCaptureToSAR ├── MFAudioCaptureToSAR.cpp ├── MFAudioCaptureToSAR.sln └── MFAudioCaptureToSAR.vcxproj ├── MFBitmapMftToEVR ├── MFBitmapMftToEVR.cpp ├── MFBitmapMftToEVR.sln └── MFBitmapMftToEVR.vcxproj ├── MFBitmapToEVR ├── MFBitmapToEVR.cpp ├── MFBitmapToEVR.sln └── MFBitmapToEVR.vcxproj ├── MFCaptureRawFramesToFile ├── MFCaptureRawFramesToFile.cpp ├── MFCaptureRawFramesToFile.sln ├── MFCaptureRawFramesToFile.vcxproj ├── app.ico ├── app.rc └── resource.h ├── MFH264RoundTrip ├── MFH264RoundTrip.cpp ├── MFH264RoundTrip.sln └── MFH264RoundTrip.vcxproj ├── MFListTransforms ├── MFListTransforms.cpp ├── MFListTransforms.sln └── MFListTransforms.vcxproj ├── MFMP4ToYUVWithMFT ├── MFMP4ToYUVWithMFT.cpp ├── MFMP4ToYUVWithMFT.sln └── MFMP4ToYUVWithMFT.vcxproj ├── MFMP4ToYUVWithoutMFT ├── MFMP4ToYUVWithoutMFT.cpp ├── MFMP4ToYUVWithoutMFT.sln ├── MFMP4ToYUVWithoutMFT.vcxproj └── rawframes.yuv ├── MFSampleGrabber ├── MFSampleGrabber.sln ├── MFSampleGrabber.vcxproj ├── MFSampleGrabber.vcxproj.filters ├── SampleGrabber.cpp ├── SampleGrabber.h └── main.cpp ├── MFTopology ├── MFTopology.cpp ├── MFTopology.sln └── MFTopology.vcxproj ├── MFVideoEVR ├── MFVideoEVR.cpp ├── MFVideoEVR.sln └── MFVideoEVR.vcxproj ├── MFVideoEVRWebcam ├── MFVideoEVRWebcam.cpp ├── MFVideoEVRWebcam.sln └── MFVideoEVRWebcam.vcxproj ├── MFVideoEVRWebcamMFT ├── MFVideoEVRWebcamMFT.cpp ├── MFVideoEVRWebcamMFT.sln └── MFVideoEVRWebcamMFT.vcxproj ├── MFWebCamRtp ├── MFWebCamRtp.cpp ├── MFWebCamRtp.sln ├── MFWebCamRtp.vcxproj └── test.sdp ├── MFWebCamToFile ├── MFWebCamToFile.cpp ├── MFWebCamToFile.sln └── MFWebCamToFile.vcxproj ├── MFWebCamToH264Buffer ├── MFWebCamToH264Buffer.cpp ├── MFWebCamToH264Buffer.sln └── MFWebCamToH264Buffer.vcxproj ├── MFWebCamWebRTC ├── MFWebCamWebRTC.cpp ├── MFWebCamWebRTC.sln ├── MFWebCamWebRTC.vcxproj ├── localhost.pem ├── localhost_key.pem └── mfwebrtc.html ├── MFWebCamWebRTCH264 ├── MFWebCamWebRTCH264.cpp ├── MFWebCamWebRTCH264.sln ├── MFWebCamWebRTCH264.vcxproj ├── localhost.pem ├── localhost_key.pem └── mfwebrtc.html ├── MFWebcamAndMicrophoneToFile ├── MFWebcamAndMicrophoneToFile.cpp ├── MFWebcamAndMicrophoneToFile.sln ├── MFWebcamAndMicrophoneToFile.vcxproj └── capture.mp4 ├── MediaFiles ├── LICENSE-Macroform ├── Macroform_-_Simplicity.mp3 ├── Macroform_-_Simplicity.wav ├── big_buck_bunny.mp4 ├── big_buck_bunny_48k.mp4 └── sound_in_sync_test.mp4 ├── README.md ├── WpfMediaUWA ├── Readme.txt ├── WpfMedia │ ├── App.xaml │ ├── App.xaml.cs │ ├── ApplicationInsights.config │ ├── Assets │ │ ├── LockScreenLogo.scale-200.png │ │ ├── SplashScreen.scale-200.png │ │ ├── Square150x150Logo.scale-200.png │ │ ├── Square44x44Logo.scale-200.png │ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ │ ├── StoreLogo.png │ │ ├── Wide310x150Logo.scale-200.png │ │ ├── big_buck_bunny.mp4 │ │ └── max4.mp4 │ ├── MainPage.xaml │ ├── MainPage.xaml.cs │ ├── Package.appxmanifest │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── Default.rd.xml │ ├── WpfMedia.csproj │ └── WpfMedia_TemporaryKey.pfx └── WpfMediaUWA.sln └── wpfmediauwa └── SampleMaker ├── MFUtility.h ├── Mp4Sampler.cpp ├── Mp4Sampler.h ├── SampleMaker.cpp ├── SampleMaker.h ├── SampleMaker.vcxproj ├── pch.cpp └── pch.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | **/.vs 31 | **/x64 32 | **/Debug 33 | **/bin 34 | **/obj 35 | **/*.user 36 | MFWebCamToFile/sample.mp4 37 | MFMP4ToYUVWithMFT/rawframes.yuv 38 | MFCaptureRawFramesToFile/rawframes.yuv 39 | MFH264RoundTrip/rawframes.yuv 40 | MFWebCamToFile/capture.mp4 41 | MFWebCamToH264Buffer/sample.mp4 42 | **/capture_postmft.bmp 43 | **/capture_premft.bmp -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | 26 | -------------------------------------------------------------------------------- /MFAudio/MFAudio.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Filename: MFAudio.cpp 3 | * 4 | * Description: 5 | * This file contains a C++ console application that plays the audio stream from 6 | * a sample file using the Windows Media Foundation API and the Streaming 7 | * Audio Renderer: 8 | * https://msdn.microsoft.com/en-us/library/windows/desktop/aa369729%28v=vs.85%29.aspx. 9 | * 10 | * Author: 11 | * Aaron Clauson (aaron@sipsorcery.com) 12 | * 13 | * History: 14 | * 01 Jan 2015 Aaron Clauson Created, Hobart, Australia. 15 | * 03 Jan 2019 Aaron Clauson Revisited to get sample working. 16 | * 17 | * License: Public Domain (no warranty, use at own risk) 18 | /******************************************************************************/ 19 | 20 | #include "../Common/MFUtility.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #pragma comment(lib, "mf.lib") 31 | #pragma comment(lib, "mfplat.lib") 32 | #pragma comment(lib, "mfplay.lib") 33 | #pragma comment(lib, "mfreadwrite.lib") 34 | #pragma comment(lib, "mfuuid.lib") 35 | 36 | #define MEDIA_FILE_PATH L"../MediaFiles/Macroform_-_Simplicity.mp3" 37 | #define AUDIO_DEVICE_INDEX 0 // Select the first audio rendering device returned by the system. 38 | 39 | int main() 40 | { 41 | IMFSourceReader* pSourceReader = NULL; 42 | IMFMediaType* pFileAudioMediaType = NULL; 43 | IMFMediaSink* pAudioSink = NULL; 44 | IMFStreamSink* pStreamSink = NULL; 45 | IMFMediaTypeHandler* pSinkMediaTypeHandler = NULL; 46 | IMFMediaType* pSinkSupportedType = NULL; 47 | IMFMediaType* pSinkMediaType = NULL; 48 | IMFSinkWriter* pSinkWriter = NULL; 49 | DWORD sinkMediaTypeCount = 0; 50 | 51 | CHECK_HR(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE), 52 | "COM initialisation failed."); 53 | 54 | CHECK_HR(MFStartup(MF_VERSION), 55 | "Media Foundation initialisation failed."); 56 | 57 | ListAudioOutputDevices(); 58 | 59 | // Source. 60 | CHECK_HR(MFCreateSourceReaderFromURL( 61 | MEDIA_FILE_PATH, 62 | NULL, 63 | &pSourceReader), 64 | "Failed to create source reader from file."); 65 | 66 | CHECK_HR(pSourceReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &pFileAudioMediaType), 67 | "Error retrieving current media type from first audio stream."); 68 | 69 | CHECK_HR(pSourceReader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, TRUE), 70 | "Failed to set the first audio stream on the source reader."); 71 | 72 | std::cout << GetMediaTypeDescription(pFileAudioMediaType) << std::endl; 73 | 74 | // Sink. 75 | CHECK_HR(GetAudioOutputDevice(AUDIO_DEVICE_INDEX, &pAudioSink), 76 | "Failed to get audio renderer device."); 77 | 78 | CHECK_HR(pAudioSink->GetStreamSinkByIndex(0, &pStreamSink), 79 | "Failed to get audio renderer stream by index."); 80 | 81 | CHECK_HR(pStreamSink->GetMediaTypeHandler(&pSinkMediaTypeHandler), 82 | "Failed to get media type handler."); 83 | 84 | CHECK_HR(pSinkMediaTypeHandler->GetMediaTypeCount(&sinkMediaTypeCount), 85 | "Error getting sink media type count."); 86 | 87 | // Find a media type that the stream sink supports. 88 | for (UINT i = 0; i < sinkMediaTypeCount; i++) 89 | { 90 | CHECK_HR(pSinkMediaTypeHandler->GetMediaTypeByIndex(i, &pSinkSupportedType), 91 | "Error getting media type from sink media type handler."); 92 | 93 | std::cout << GetMediaTypeDescription(pSinkSupportedType) << std::endl; 94 | 95 | if (pSinkMediaTypeHandler->IsMediaTypeSupported(pSinkSupportedType, NULL) == S_OK) { 96 | std::cout << "Matching media type found." << std::endl; 97 | break; 98 | } 99 | else { 100 | std::cout << "Sink media type does not match." << std::endl; 101 | SAFE_RELEASE(pSinkSupportedType); 102 | } 103 | } 104 | 105 | if (pSinkSupportedType != NULL) { 106 | // Set the supported type on the reader. 107 | CHECK_HR(pSourceReader->SetCurrentMediaType(0, NULL, pSinkSupportedType), 108 | "Failed to set media type on reader."); 109 | 110 | CHECK_HR(MFCreateSinkWriterFromMediaSink(pAudioSink, NULL, &pSinkWriter), 111 | "Failed to create sink writer for default speaker."); 112 | 113 | CHECK_HR(pSinkWriter->SetInputMediaType(0, pSinkSupportedType, NULL), 114 | "Error setting sink media type."); 115 | 116 | // Start the read-write loop. 117 | std::cout << "Read audio samples from file and write to speaker." << std::endl; 118 | 119 | CHECK_HR(pSinkWriter->BeginWriting(), 120 | "Sink writer begin writing call failed."); 121 | 122 | while (true) 123 | { 124 | IMFSample* audioSample = NULL; 125 | DWORD streamIndex, flags; 126 | LONGLONG llAudioTimeStamp; 127 | 128 | CHECK_HR(pSourceReader->ReadSample( 129 | MF_SOURCE_READER_FIRST_AUDIO_STREAM, 130 | 0, // Flags. 131 | &streamIndex, // Receives the actual stream index. 132 | &flags, // Receives status flags. 133 | &llAudioTimeStamp, // Receives the time stamp. 134 | &audioSample // Receives the sample or NULL. 135 | ), "Error reading audio sample."); 136 | 137 | if (flags & MF_SOURCE_READERF_ENDOFSTREAM) 138 | { 139 | printf("\tEnd of stream"); 140 | break; 141 | } 142 | if (flags & MF_SOURCE_READERF_NEWSTREAM) 143 | { 144 | printf("\tNew stream\n"); 145 | break; 146 | } 147 | if (flags & MF_SOURCE_READERF_NATIVEMEDIATYPECHANGED) 148 | { 149 | printf("\tNative type changed\n"); 150 | break; 151 | } 152 | if (flags & MF_SOURCE_READERF_CURRENTMEDIATYPECHANGED) 153 | { 154 | printf("\tCurrent type changed\n"); 155 | break; 156 | } 157 | if (flags & MF_SOURCE_READERF_STREAMTICK) 158 | { 159 | printf("Stream tick.\n"); 160 | CHECK_HR(pSinkWriter->SendStreamTick(0, llAudioTimeStamp), 161 | "Error sending stream tick."); 162 | } 163 | 164 | if (!audioSample) 165 | { 166 | printf("Null audio sample.\n"); 167 | } 168 | else 169 | { 170 | CHECK_HR(pSinkWriter->WriteSample(0, audioSample), 171 | "The stream sink writer was not happy with the sample."); 172 | } 173 | } 174 | } 175 | else { 176 | printf("No matching media type could be found.\n"); 177 | } 178 | 179 | done: 180 | 181 | printf("finished.\n"); 182 | int c = getchar(); 183 | 184 | SAFE_RELEASE(pSourceReader); 185 | SAFE_RELEASE(pFileAudioMediaType); 186 | SAFE_RELEASE(pAudioSink); 187 | SAFE_RELEASE(pStreamSink); 188 | SAFE_RELEASE(pSinkMediaTypeHandler); 189 | SAFE_RELEASE(pSinkSupportedType); 190 | SAFE_RELEASE(pSinkMediaType); 191 | SAFE_RELEASE(pSinkWriter); 192 | 193 | return 0; 194 | } 195 | -------------------------------------------------------------------------------- /MFAudio/MFAudio.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29123.88 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFAudio", "MFAudio.vcxproj", "{B2C108DF-7550-4D54-8288-71C19CDF2090}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Debug|Win32.Build.0 = Debug|Win32 18 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Debug|x64.ActiveCfg = Debug|x64 19 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Debug|x64.Build.0 = Debug|x64 20 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Release|Win32.ActiveCfg = Release|Win32 21 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Release|Win32.Build.0 = Release|Win32 22 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Release|x64.ActiveCfg = Release|x64 23 | {B2C108DF-7550-4D54-8288-71C19CDF2090}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {8D78867F-95F3-4488-885C-5B713C9ECD48} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFAudio/MFAudio.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {B2C108DF-7550-4D54-8288-71C19CDF2090} 26 | Win32Proj 27 | MFSpeaker 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | 37 | 38 | Application 39 | true 40 | v142 41 | Unicode 42 | 43 | 44 | Application 45 | false 46 | v142 47 | true 48 | Unicode 49 | 50 | 51 | Application 52 | false 53 | v142 54 | true 55 | Unicode 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 92 | stdcpp17 93 | 94 | 95 | Console 96 | true 97 | %(AdditionalDependencies) 98 | 99 | 100 | 101 | 102 | 103 | 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | stdcpp17 108 | 109 | 110 | Console 111 | true 112 | %(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | 119 | 120 | MaxSpeed 121 | true 122 | true 123 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 124 | stdcpp17 125 | 126 | 127 | Console 128 | true 129 | true 130 | true 131 | 132 | 133 | 134 | 135 | Level3 136 | 137 | 138 | MaxSpeed 139 | true 140 | true 141 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 142 | stdcpp17 143 | 144 | 145 | Console 146 | true 147 | true 148 | true 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /MFAudioCaptureToSAR/MFAudioCaptureToSAR.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Filename: MFAudioCaptureToSAR.cpp 3 | * 4 | * Description: 5 | * This file contains a C++ console application that is attempting to play the 6 | * audio from a capture device using the Windows Media Foundation API. 7 | * Playback is done using the Streaming Audio Renderer: 8 | * https://msdn.microsoft.com/en-us/library/windows/desktop/aa369729%28v=vs.85%29.aspx 9 | * 10 | * Author: 11 | * Aaron Clauson (aaron@sipsorcery.com) 12 | * 13 | * History: 14 | * 27 Jan 2020 Aaron Clauson Created, Dublin, Ireland. 15 | * 16 | * License: Public Domain (no warranty, use at own risk) 17 | /******************************************************************************/ 18 | 19 | #include "..\Common\MFUtility.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #pragma comment(lib, "mf.lib") 37 | #pragma comment(lib, "evr.lib") 38 | #pragma comment(lib, "mfplat.lib") 39 | #pragma comment(lib, "mfplay.lib") 40 | #pragma comment(lib, "mfreadwrite.lib") 41 | #pragma comment(lib, "mfuuid.lib") 42 | 43 | #define AUDIO_CAPTURE_DEVICE_INDEX 0 // Adjust according to desired audio capture device. 44 | #define AUDIO_OUTPUT_DEVICE_INDEX 0 // Adjust according to desired audio output device. 45 | 46 | int main() 47 | { 48 | IMFMediaSource* pAudioSource = NULL; 49 | IMFSourceReader* pAudioReader = NULL; 50 | IMFMediaSink* pAudioSink = NULL; 51 | IMFStreamSink* pStreamSink = NULL; 52 | IMFSinkWriter* pAudioSinkWriter = NULL; 53 | IMFMediaTypeHandler* pSinkMediaTypeHandler = NULL; 54 | IMFMediaType* pSinkSupportedType = NULL; 55 | BOOL fSelected = false; 56 | DWORD sourceStreamCount = 0, sinkStreamCount = 0, sinkStreamIndex = 0, sinkMediaTypeCount = 0; 57 | 58 | CHECK_HR(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE), 59 | "COM initialisation failed."); 60 | 61 | CHECK_HR(MFStartup(MF_VERSION), 62 | "Media Foundation initialisation failed."); 63 | 64 | /*CHECK_HR(ListAudioOutputDevices(), 65 | "Failed to list audio output devices.");*/ 66 | 67 | //CHECK_HR(ListCaptureDevices(DeviceType::Audio), 68 | // "Error listing audio capture devices."); 69 | 70 | // ----- Set up audio capture (microphone) source. ----- 71 | 72 | CHECK_HR(GetSourceFromCaptureDevice(DeviceType::Audio, AUDIO_CAPTURE_DEVICE_INDEX, &pAudioSource, &pAudioReader), 73 | "Failed to get microphone source reader."); 74 | 75 | CHECK_HR(pAudioReader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, TRUE), 76 | "Failed to set the first audio stream on the source reader."); 77 | 78 | // ----- Set up Audio sink (Streaming Audio Renderer). ----- 79 | 80 | CHECK_HR(GetAudioOutputDevice(AUDIO_OUTPUT_DEVICE_INDEX, &pAudioSink), 81 | "Failed to create streaming audio sink."); 82 | 83 | CHECK_HR(pAudioSink->GetStreamSinkByIndex(0, &pStreamSink), 84 | "Failed to get audio sink stream by index."); 85 | 86 | CHECK_HR(pStreamSink->GetMediaTypeHandler(&pSinkMediaTypeHandler), 87 | "Failed to get media type handler for stream sink."); 88 | 89 | CHECK_HR(pSinkMediaTypeHandler->GetMediaTypeCount(&sinkMediaTypeCount), 90 | "Error getting sink media type count."); 91 | 92 | std::cout << "Sink media type count " << sinkMediaTypeCount << "." << std::endl; 93 | 94 | // ----- Wire up the source and sink. ----- 95 | 96 | // Find a media type that the stream sink supports. 97 | for (UINT i = 0; i < sinkMediaTypeCount; i++) 98 | { 99 | CHECK_HR(pSinkMediaTypeHandler->GetMediaTypeByIndex(i, &pSinkSupportedType), 100 | "Error getting media type from sink media type handler."); 101 | 102 | if (pSinkMediaTypeHandler->IsMediaTypeSupported(pSinkSupportedType, NULL) == S_OK) 103 | { 104 | std::cout << "Matching media type found." << std::endl; 105 | std::cout << GetMediaTypeDescription(pSinkSupportedType) << std::endl; 106 | break; 107 | } 108 | else { 109 | std::cout << "Sink and source media type incompatible." << std::endl; 110 | //std::cout << GetMediaTypeDescription(pSinkSupportedType) << std::endl; 111 | SAFE_RELEASE(pSinkSupportedType); 112 | } 113 | } 114 | 115 | if (pSinkSupportedType != NULL) { 116 | 117 | // Set the supported type on the reader. 118 | CHECK_HR(pAudioReader->SetCurrentMediaType(0, NULL, pSinkSupportedType), 119 | "Failed to set media type on reader."); 120 | 121 | CHECK_HR(MFCreateSinkWriterFromMediaSink(pAudioSink, NULL, &pAudioSinkWriter), 122 | "Failed to create sink writer from audio sink."); 123 | 124 | CHECK_HR(pAudioSinkWriter->SetInputMediaType(0, pSinkSupportedType, NULL), 125 | "Error setting sink media type."); 126 | 127 | CHECK_HR(pAudioSinkWriter->BeginWriting(), 128 | "Failed to being writing on audio sink writer."); 129 | 130 | // ----- Source and sink now configured. Set up remaining infrastructure and then start sampling. ----- 131 | 132 | // Start the sample read-write loop. 133 | IMFSample* pAudioSample = NULL; 134 | DWORD streamIndex, flags; 135 | LONGLONG llTimeStamp; 136 | 137 | while (true) 138 | { 139 | CHECK_HR(pAudioReader->ReadSample( 140 | MF_SOURCE_READER_FIRST_AUDIO_STREAM, 141 | 0, // Flags. 142 | &streamIndex, // Receives the actual stream index. 143 | &flags, // Receives status flags. 144 | &llTimeStamp, // Receives the time stamp. 145 | &pAudioSample // Receives the sample or NULL. 146 | ), "Error reading audio sample."); 147 | 148 | if (flags & MF_SOURCE_READERF_ENDOFSTREAM) 149 | { 150 | printf("End of stream.\n"); 151 | break; 152 | } 153 | if (flags & MF_SOURCE_READERF_STREAMTICK) 154 | { 155 | printf("Stream tick.\n"); 156 | CHECK_HR(pAudioSinkWriter->SendStreamTick(0, llTimeStamp), "Error sending stream tick."); 157 | } 158 | 159 | if (!pAudioSample) 160 | { 161 | printf("Null audio sample.\n"); 162 | } 163 | else 164 | { 165 | LONGLONG sampleDuration = 0; 166 | 167 | CHECK_HR(pAudioSample->SetSampleTime(llTimeStamp), "Error setting the audio sample time."); 168 | CHECK_HR(pAudioSample->GetSampleDuration(&sampleDuration), "Failed to get audio sample duration."); 169 | 170 | printf("Audio sample, duration %llu, sample time %llu.\n", sampleDuration, llTimeStamp); 171 | 172 | CHECK_HR(pAudioSinkWriter->WriteSample(0, pAudioSample), "Sink writer write sample failed."); 173 | } 174 | 175 | SAFE_RELEASE(pAudioSample); 176 | } 177 | } 178 | 179 | done: 180 | 181 | printf("finished.\n"); 182 | auto c = getchar(); 183 | 184 | SAFE_RELEASE(pAudioSource); 185 | SAFE_RELEASE(pAudioReader); 186 | SAFE_RELEASE(pAudioSink); 187 | SAFE_RELEASE(pSinkSupportedType); 188 | SAFE_RELEASE(pStreamSink); 189 | SAFE_RELEASE(pAudioSinkWriter); 190 | SAFE_RELEASE(pSinkMediaTypeHandler); 191 | 192 | return 0; 193 | } 194 | -------------------------------------------------------------------------------- /MFAudioCaptureToSAR/MFAudioCaptureToSAR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFAudioCaptureToSAR", "MFAudioCaptureToSAR.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|x64 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|x64 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.ActiveCfg = Release|Win32 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {51C31229-FD64-4312-B893-449F58B70CA2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFAudioCaptureToSAR/MFAudioCaptureToSAR.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFAudo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFBitmapMftToEVR/MFBitmapMftToEVR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFBitmapMftToEVR", "MFBitmapMftToEVR.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|x64 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|x64 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.ActiveCfg = Release|Win32 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A0499910-76B7-4F65-A47B-3DD196247CA2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFBitmapMftToEVR/MFBitmapMftToEVR.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFVideo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFBitmapToEVR/MFBitmapToEVR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFBitmapToEVR", "MFBitmapToEVR.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|x64 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|x64 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.ActiveCfg = Release|Win32 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {A0499910-76B7-4F65-A47B-3DD196247CA2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFBitmapToEVR/MFBitmapToEVR.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFVideo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/MFCaptureRawFramesToFile.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Filename: MFCaptureRawFramesToFile.cpp 3 | * 4 | * Description: 5 | * This file contains a C++ console application that captures individual frames 6 | * from a webcam and dumps them in binary format to an output file. 7 | * 8 | * To convert the raw yuv data dumped at the end of this sample use the ffmpeg 9 | * commands below: 10 | * ffmpeg -vcodec rawvideo -s 640x480 -pix_fmt yuv420p -i rawframes.yuv -vframes 1 out.jpeg 11 | * ffmpeg -vcodec rawvideo -s 640x480 -pix_fmt yuv420p -i rawframes.yuv out.avi 12 | * 13 | * More info see: https://ffmpeg.org/ffmpeg.html#Video-and-Audio-file-format-conversion 14 | * 15 | * Note: The webcam index and the source reader media output type will need 16 | * adjustment depending on the the configuration of video devices on the machine 17 | * running this sample. 18 | * 19 | * Author: 20 | * Aaron Clauson (aaron@sipsorcery.com) 21 | * 22 | * History: 23 | * 06 Mar 2015 Aaron Clauson (aaron@sipsorcery.com) Created. 24 | * 25 | * License: Public Domain (no warranty, use at own risk) 26 | /******************************************************************************/ 27 | 28 | #include "../Common/MFUtility.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #pragma comment(lib, "mf.lib") 41 | #pragma comment(lib, "mfplat.lib") 42 | #pragma comment(lib, "mfplay.lib") 43 | #pragma comment(lib, "mfreadwrite.lib") 44 | #pragma comment(lib, "mfuuid.lib") 45 | #pragma comment(lib, "wmcodecdspuuid.lib") 46 | 47 | #define WEBCAM_DEVICE_INDEX 0 // Adjust according to desired video capture device. 48 | #define SAMPLE_COUNT 100 // Adjust depending on number of samples to capture. 49 | #define CAPTURE_FILENAME "rawframes.yuv" 50 | #define FRAME_WIDTH 640 51 | #define FRAME_HEIGHT 480 52 | 53 | int main() 54 | { 55 | IMFMediaSource* videoSource = NULL; 56 | UINT32 videoDeviceCount = 0; 57 | IMFAttributes* videoConfig = NULL; 58 | IMFActivate** videoDevices = NULL; 59 | IMFSourceReader* videoReader = NULL; 60 | WCHAR* webcamFriendlyName = NULL; 61 | IMFMediaType* videoSourceOutputType = NULL; 62 | IMFMediaType* pSrcOutMediaType = NULL; 63 | UINT webcamNameLength = 0; 64 | 65 | std::ofstream outputBuffer(CAPTURE_FILENAME, std::ios::out | std::ios::binary); 66 | 67 | CHECK_HR(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE), 68 | "COM initialisation failed."); 69 | 70 | CHECK_HR(MFStartup(MF_VERSION), 71 | "Media Foundation initialisation failed."); 72 | 73 | // Get the first available webcam. 74 | CHECK_HR(MFCreateAttributes(&videoConfig, 1), 75 | "Error creating video configuation."); 76 | 77 | // Request video capture devices. 78 | CHECK_HR(videoConfig->SetGUID( 79 | MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, 80 | MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID), 81 | "Error initialising video configuration object."); 82 | 83 | CHECK_HR(MFEnumDeviceSources(videoConfig, &videoDevices, &videoDeviceCount), 84 | "Error enumerating video devices."); 85 | 86 | CHECK_HR(videoDevices[WEBCAM_DEVICE_INDEX]->GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &webcamFriendlyName, &webcamNameLength), 87 | "Error retrieving video device friendly name."); 88 | 89 | wprintf(L"First available webcam: %s\n", webcamFriendlyName); 90 | 91 | CHECK_HR(videoDevices[WEBCAM_DEVICE_INDEX]->ActivateObject(IID_PPV_ARGS(&videoSource)), 92 | "Error activating video device."); 93 | 94 | // Create a source reader. 95 | CHECK_HR(MFCreateSourceReaderFromMediaSource( 96 | videoSource, 97 | videoConfig, 98 | &videoReader), 99 | "Error creating video source reader."); 100 | 101 | // The list of media types supported by the webcam. 102 | //ListModes(videoReader); 103 | 104 | /*CHECK_HR(videoReader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, &videoSourceOutputType), 105 | "Error retrieving current media type from first video stream.");*/ 106 | 107 | // Note the webcam needs to support this media type. 108 | CHECK_HR(MFCreateMediaType(&pSrcOutMediaType), "Failed to create media type."); 109 | CHECK_HR(pSrcOutMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), "Failed to set video media type."); 110 | CHECK_HR(pSrcOutMediaType->SetGUID(MF_MT_SUBTYPE, WMMEDIASUBTYPE_I420), "Failed to set video media sub type to I420."); 111 | CHECK_HR(MFSetAttributeSize(pSrcOutMediaType, MF_MT_FRAME_SIZE, FRAME_WIDTH, FRAME_HEIGHT), "Failed to set frame size."); 112 | //CHECK_HR(CopyAttribute(videoSourceOutputType, pSrcOutMediaType, MF_MT_DEFAULT_STRIDE), "Failed to copy default stride attribute."); 113 | 114 | CHECK_HR(videoReader->SetCurrentMediaType(0, NULL, pSrcOutMediaType), 115 | "Failed to set media type on source reader."); 116 | 117 | printf("Reading video samples from webcam."); 118 | 119 | IMFSample *videoSample = NULL; 120 | DWORD streamIndex, flags; 121 | LONGLONG llVideoTimeStamp, llSampleDuration; 122 | int sampleCount = 0; 123 | 124 | while (sampleCount <= SAMPLE_COUNT) 125 | { 126 | CHECK_HR(videoReader->ReadSample( 127 | MF_SOURCE_READER_FIRST_VIDEO_STREAM, 128 | 0, // Flags. 129 | &streamIndex, // Receives the actual stream index. 130 | &flags, // Receives status flags. 131 | &llVideoTimeStamp, // Receives the time stamp. 132 | &videoSample // Receives the sample or NULL. 133 | ), "Error reading video sample."); 134 | 135 | if (flags & MF_SOURCE_READERF_STREAMTICK) 136 | { 137 | printf("Stream tick.\n"); 138 | } 139 | 140 | if (videoSample) 141 | { 142 | printf("Writing sample %i.\n", sampleCount); 143 | 144 | CHECK_HR(videoSample->SetSampleTime(llVideoTimeStamp), "Error setting the video sample time."); 145 | CHECK_HR(videoSample->GetSampleDuration(&llSampleDuration), "Error getting video sample duration."); 146 | 147 | IMFMediaBuffer *buf = NULL; 148 | DWORD bufLength; 149 | CHECK_HR(videoSample->ConvertToContiguousBuffer(&buf), "ConvertToContiguousBuffer failed."); 150 | CHECK_HR(buf->GetCurrentLength(&bufLength), "Get buffer length failed."); 151 | 152 | printf("Sample length %i.\n", bufLength); 153 | 154 | byte *byteBuffer; 155 | DWORD buffCurrLen = 0; 156 | DWORD buffMaxLen = 0; 157 | CHECK_HR(buf->Lock(&byteBuffer, &buffMaxLen, &buffCurrLen), "Failed to lock video sample buffer."); 158 | 159 | outputBuffer.write((char *)byteBuffer, bufLength); 160 | 161 | CHECK_HR(buf->Unlock(), "Failed to unlock video sample buffer."); 162 | 163 | buf->Release(); 164 | videoSample->Release(); 165 | } 166 | 167 | sampleCount++; 168 | } 169 | 170 | outputBuffer.close(); 171 | 172 | done: 173 | 174 | printf("finished.\n"); 175 | int c = getchar(); 176 | 177 | SAFE_RELEASE(videoSource); 178 | SAFE_RELEASE(videoConfig); 179 | SAFE_RELEASE(videoDevices); 180 | SAFE_RELEASE(videoReader); 181 | SAFE_RELEASE(videoSourceOutputType); 182 | SAFE_RELEASE(pSrcOutMediaType); 183 | 184 | return 0; 185 | } 186 | -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/MFCaptureRawFramesToFile.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFCaptureRawFramesToFile", "MFCaptureRawFramesToFile.vcxproj", "{C3B44D3F-81AA-4B8E-9858-E2B37B1D9426}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C3B44D3F-81AA-4B8E-9858-E2B37B1D9426}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {C3B44D3F-81AA-4B8E-9858-E2B37B1D9426}.Debug|Win32.Build.0 = Debug|Win32 16 | {C3B44D3F-81AA-4B8E-9858-E2B37B1D9426}.Release|Win32.ActiveCfg = Release|Win32 17 | {C3B44D3F-81AA-4B8E-9858-E2B37B1D9426}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/MFCaptureRawFramesToFile.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C3B44D3F-81AA-4B8E-9858-E2B37B1D9426} 15 | 16 | 17 | ManagedCProj 18 | MFCaptureRawFramesToFile 19 | 20 | 21 | 22 | Application 23 | true 24 | v142 25 | false 26 | Unicode 27 | 28 | 29 | Application 30 | false 31 | v142 32 | false 33 | Unicode 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | 48 | 49 | false 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;%(PreprocessorDefinitions) 56 | NotUsing 57 | 58 | 59 | true 60 | %(AdditionalDependencies) 61 | Console 62 | 63 | 64 | 65 | 66 | Level3 67 | WIN32;NDEBUG;%(PreprocessorDefinitions) 68 | Use 69 | 70 | 71 | true 72 | 73 | Console 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MFCaptureRawFramesToFile/app.ico -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/app.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MFCaptureRawFramesToFile/app.rc -------------------------------------------------------------------------------- /MFCaptureRawFramesToFile/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by app.rc 4 | -------------------------------------------------------------------------------- /MFH264RoundTrip/MFH264RoundTrip.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFH264RoundTrip", "MFH264RoundTrip.vcxproj", "{3348C871-ECFF-4A67-A26C-31DF5CB58537}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3348C871-ECFF-4A67-A26C-31DF5CB58537}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {3348C871-ECFF-4A67-A26C-31DF5CB58537}.Debug|Win32.Build.0 = Debug|Win32 16 | {3348C871-ECFF-4A67-A26C-31DF5CB58537}.Release|Win32.ActiveCfg = Release|Win32 17 | {3348C871-ECFF-4A67-A26C-31DF5CB58537}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFH264RoundTrip/MFH264RoundTrip.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {3348C871-ECFF-4A67-A26C-31DF5CB58537} 15 | Win32Proj 16 | MFH264RoundTrip 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | Unicode 24 | false 25 | 26 | 27 | Application 28 | false 29 | v142 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 56 | 57 | 58 | Console 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 71 | 72 | 73 | Console 74 | true 75 | true 76 | true 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /MFListTransforms/MFListTransforms.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Filename: MFListTransforms.cpp 3 | * 4 | * Description: 5 | * This file contains a C++ console application that attempts to list the Media 6 | * Foundation Transforms (MFT) available on the system. 7 | * See https://docs.microsoft.com/en-us/windows/win32/medfound/registering-and-enumerating-mfts. 8 | * 9 | * Author: 10 | * Aaron Clauson (aaron@sipsorcery.com) 11 | * 12 | * History: 13 | * 26 Feb 2015 Aaron Clauson Created, Hobart, Australia. 14 | * 04 Jan 2020 Aaron Clauson Tidied up and got it doing something useful. 15 | * 16 | * License: Public Domain (no warranty, use at own risk) 17 | /******************************************************************************/ 18 | 19 | #include "../Common/MFUtility.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #pragma comment(lib, "mf.lib") 30 | #pragma comment(lib, "mfplat.lib") 31 | #pragma comment(lib, "mfplay.lib") 32 | #pragma comment(lib, "mfreadwrite.lib") 33 | #pragma comment(lib, "mfuuid.lib") 34 | 35 | void ListTansforms(MFT_REGISTER_TYPE_INFO* pInput, MFT_REGISTER_TYPE_INFO* pOutput); 36 | HRESULT DisplayMFT(IMFActivate* pMFActivate); 37 | 38 | int _tmain(int argc, _TCHAR* argv[]) 39 | { 40 | CHECK_HR(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE), 41 | "COM initialisation failed."); 42 | 43 | CHECK_HR(MFStartup(MF_VERSION), 44 | "Media Foundation initialisation failed."); 45 | 46 | // Audio subtype GUIDS : https://docs.microsoft.com/en-us/windows/win32/medfound/audio-subtype-guids 47 | // Video subtype GUIDS : https://docs.microsoft.com/en-us/windows/win32/medfound/video-subtype-guids 48 | 49 | MFT_REGISTER_TYPE_INFO videoYuv = { MFMediaType_Video, MFVideoFormat_YUY2 }; 50 | MFT_REGISTER_TYPE_INFO videoRgb24 = { MFMediaType_Video, MFVideoFormat_RGB24 }; 51 | MFT_REGISTER_TYPE_INFO videoH264 = { MFMediaType_Video, MFVideoFormat_H264 }; 52 | MFT_REGISTER_TYPE_INFO videoVP8 = { MFMediaType_Video, MFVideoFormat_VP80 }; 53 | MFT_REGISTER_TYPE_INFO audioPcm = { MFMediaType_Audio, MFAudioFormat_PCM }; 54 | MFT_REGISTER_TYPE_INFO audioMp3 = { MFMediaType_Audio, MFAudioFormat_MP3 }; 55 | 56 | std::cout << "Video MFT's for input: YUV2, output: all" << std::endl; 57 | ListTansforms(&videoYuv, NULL); 58 | std::cout << std::endl; 59 | 60 | std::cout << "Video MFT's for input: YUV2, output: H264" << std::endl; 61 | ListTansforms(&videoYuv, &videoH264); 62 | std::cout << std::endl; 63 | 64 | std::cout << "Video MFT's for input: YUV2, output: VP8" << std::endl; 65 | ListTansforms(&videoYuv, &videoVP8); 66 | std::cout << std::endl; 67 | 68 | std::cout << "Video MFT's for input: RGB24, output: H264" << std::endl; 69 | ListTansforms(&videoRgb24, &videoH264); 70 | std::cout << std::endl; 71 | 72 | std::cout << "Audio MFT's for input: PCM, output: all" << std::endl; 73 | ListTansforms(&audioPcm, NULL); 74 | std::cout << std::endl; 75 | 76 | std::cout << "Audio MFT's for input: PCM, output: MP3" << std::endl; 77 | ListTansforms(&audioPcm, &audioMp3); 78 | std::cout << std::endl; 79 | 80 | done: 81 | printf("finished.\n"); 82 | auto c = getchar(); 83 | 84 | return 0; 85 | } 86 | 87 | /** 88 | * Prints out a list of all the Media Foundation Transforms that match for 89 | * the input media type and the optional output media type. 90 | * @param[in] pInput: pointer to the MFT input type to match. 91 | * @param[in] pOutput: Optional. Pointer to the MFT output type to match. If 92 | NULL all MFT's for the input type will be listed. 93 | * Remarks: 94 | * Copied from https://github.com/mvaneerde/blog/blob/develop/mftenum/mftenum/mftenum.cpp. 95 | */ 96 | void ListTansforms(MFT_REGISTER_TYPE_INFO* pInput, MFT_REGISTER_TYPE_INFO* pOutput) 97 | { 98 | IMFActivate** ppActivate = NULL; 99 | IMFTransform* pDecoder = NULL; 100 | UINT32 mftCount = 0; 101 | 102 | auto category = (pInput->guidMajorType == MFMediaType_Audio) ? MFT_CATEGORY_AUDIO_ENCODER : MFT_CATEGORY_VIDEO_ENCODER; 103 | CHECK_HR(MFTEnumEx(category, 104 | NULL, //MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER, 105 | pInput, 106 | pOutput, 107 | &ppActivate, 108 | &mftCount 109 | ), "MFTEnumEx failed."); 110 | 111 | printf("MFT count %d.\n", mftCount); 112 | 113 | for (int i = 0; i < mftCount; i++) { 114 | auto hr = DisplayMFT(ppActivate[i]); 115 | } 116 | 117 | done: 118 | 119 | for (UINT32 i = 0; i < mftCount; i++) 120 | { 121 | ppActivate[i]->Release(); 122 | } 123 | CoTaskMemFree(ppActivate); 124 | } 125 | 126 | /** 127 | * Prints out the friendly name for a Media Foundation Transform. 128 | * 129 | * Remarks: 130 | * Copied from https://github.com/mvaneerde/blog/blob/develop/mftenum/mftenum/mftenum.cpp. 131 | */ 132 | HRESULT DisplayMFT(IMFActivate* pMFActivate) { 133 | HRESULT hr; 134 | 135 | // get the CLSID GUID from the IMFAttributes of the activation object 136 | GUID guidMFT = { 0 }; 137 | hr = pMFActivate->GetGUID(MFT_TRANSFORM_CLSID_Attribute, &guidMFT); 138 | if (MF_E_ATTRIBUTENOTFOUND == hr) { 139 | std::cout << "IMFTransform has no CLSID." << std::endl; 140 | return hr; 141 | } 142 | else if (FAILED(hr)) { 143 | std::cerr << "IMFAttributes::GetGUID(MFT_TRANSFORM_CLSID_Attribute) failed: hr = " << hr << std::endl; 144 | return hr; 145 | } 146 | 147 | LPWSTR szGuid = NULL; 148 | hr = StringFromIID(guidMFT, &szGuid); 149 | if (FAILED(hr)) { 150 | std::cerr << "StringFromIID failed: hr = " << hr << std::endl; 151 | return hr; 152 | } 153 | 154 | // get the friendly name string from the IMFAttributes of the activation object 155 | LPWSTR szFriendlyName = NULL; 156 | UINT len = 0; 157 | hr = pMFActivate->GetAllocatedString( 158 | MFT_FRIENDLY_NAME_Attribute, 159 | &szFriendlyName, 160 | &len 161 | ); 162 | 163 | if (MF_E_ATTRIBUTENOTFOUND == hr) { 164 | std::cout << "IMFTransform has no friendly name." << std::endl; 165 | return hr; 166 | } 167 | else if (FAILED(hr)) { 168 | std::cerr << "IMFAttributes::GetAllocatedString(MFT_FRIENDLY_NAME_Attribute) failed: hr = " << hr << std::endl; 169 | return hr; 170 | } 171 | //CoTaskMemFreeOnExit freeFriendlyName(szFriendlyName); 172 | 173 | std::wcout << szFriendlyName << " (" << szGuid << ")" << std::endl; 174 | 175 | CoTaskMemFree(szGuid); 176 | CoTaskMemFree(szFriendlyName); 177 | 178 | return S_OK; 179 | } -------------------------------------------------------------------------------- /MFListTransforms/MFListTransforms.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFListTransforms", "MFListTransforms.vcxproj", "{C99EC353-03F5-4031-81C5-A3D026F7CF94}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C99EC353-03F5-4031-81C5-A3D026F7CF94}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {C99EC353-03F5-4031-81C5-A3D026F7CF94}.Debug|Win32.Build.0 = Debug|Win32 16 | {C99EC353-03F5-4031-81C5-A3D026F7CF94}.Release|Win32.ActiveCfg = Release|Win32 17 | {C99EC353-03F5-4031-81C5-A3D026F7CF94}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFListTransforms/MFListTransforms.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C99EC353-03F5-4031-81C5-A3D026F7CF94} 15 | Win32Proj 16 | MFListTransforms 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v142 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /MFMP4ToYUVWithMFT/MFMP4ToYUVWithMFT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFMP4ToYUVWithMFT", "MFMP4ToYUVWithMFT.vcxproj", "{261BE08B-B880-483C-979D-CF9DD79CDB59}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Debug|Win32.Build.0 = Debug|Win32 16 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Release|Win32.ActiveCfg = Release|Win32 17 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFMP4ToYUVWithMFT/MFMP4ToYUVWithMFT.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {261BE08B-B880-483C-979D-CF9DD79CDB59} 15 | ManagedCProj 16 | MFMP4ToYUVWithMFT 17 | 10.0 18 | 19 | 20 | 21 | Application 22 | true 23 | v142 24 | false 25 | Unicode 26 | 27 | 28 | Application 29 | false 30 | v142 31 | true 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | 47 | 48 | false 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;%(PreprocessorDefinitions) 55 | NotUsing 56 | 57 | 58 | true 59 | %(AdditionalDependencies) 60 | Console 61 | 62 | 63 | 64 | 65 | Level3 66 | WIN32;NDEBUG;%(PreprocessorDefinitions) 67 | Use 68 | 69 | 70 | true 71 | 72 | Console 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /MFMP4ToYUVWithoutMFT/MFMP4ToYUVWithoutMFT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFMP4ToYUVWithoutMFT", "MFMP4ToYUVWithoutMFT.vcxproj", "{261BE08B-B880-483C-979D-CF9DD79CDB59}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Debug|x86.ActiveCfg = Debug|Win32 15 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Debug|x86.Build.0 = Debug|Win32 16 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Release|x86.ActiveCfg = Release|Win32 17 | {261BE08B-B880-483C-979D-CF9DD79CDB59}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {B5D43FFC-27C6-43A3-AA6D-FCB5FAB0B41C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MFMP4ToYUVWithoutMFT/MFMP4ToYUVWithoutMFT.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {261BE08B-B880-483C-979D-CF9DD79CDB59} 15 | ManagedCProj 16 | MFMP4ToYUVWithMFT 17 | 10.0 18 | 19 | 20 | 21 | Application 22 | true 23 | v142 24 | false 25 | Unicode 26 | 27 | 28 | Application 29 | false 30 | v142 31 | true 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | true 46 | 47 | 48 | false 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;%(PreprocessorDefinitions) 55 | NotUsing 56 | 57 | 58 | true 59 | %(AdditionalDependencies) 60 | Console 61 | 62 | 63 | 64 | 65 | Level3 66 | WIN32;NDEBUG;%(PreprocessorDefinitions) 67 | Use 68 | 69 | 70 | true 71 | 72 | Console 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /MFMP4ToYUVWithoutMFT/rawframes.yuv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MFMP4ToYUVWithoutMFT/rawframes.yuv -------------------------------------------------------------------------------- /MFSampleGrabber/MFSampleGrabber.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29209.62 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFSampleGrabber", "MFSampleGrabber.vcxproj", "{BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Debug|x64.ActiveCfg = Debug|x64 17 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Debug|x64.Build.0 = Debug|x64 18 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Debug|x86.ActiveCfg = Debug|Win32 19 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Debug|x86.Build.0 = Debug|Win32 20 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Release|x64.ActiveCfg = Release|x64 21 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Release|x64.Build.0 = Release|x64 22 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Release|x86.ActiveCfg = Release|Win32 23 | {BED9F4DA-F0C5-46A3-9C84-83ED8C4B1257}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {C63CBFDA-9E27-4678-B330-798A0E8FBAB7} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFSampleGrabber/MFSampleGrabber.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | 26 | 27 | Header Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /MFSampleGrabber/SampleGrabber.cpp: -------------------------------------------------------------------------------- 1 | #include "SampleGrabber.h" 2 | 3 | // SampleGrabberCB implementation 4 | 5 | void printf_guid(REFGUID guid) { 6 | printf("Guid = {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}\n", 7 | guid.Data1, guid.Data2, guid.Data3, 8 | guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], 9 | guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); 10 | } 11 | 12 | // Create a new instance of the object. 13 | HRESULT SampleGrabberCB::CreateInstance(SampleGrabberCB **ppCB, REFGUID majorMediaType) 14 | { 15 | *ppCB = new (std::nothrow) SampleGrabberCB(); 16 | 17 | if(ppCB == NULL) 18 | { 19 | return E_OUTOFMEMORY; 20 | } 21 | 22 | (*ppCB)->_majorMediaType = majorMediaType; 23 | 24 | return S_OK; 25 | } 26 | 27 | STDMETHODIMP SampleGrabberCB::QueryInterface(REFIID riid, void** ppv) 28 | { 29 | static const QITAB qit[] = 30 | { 31 | QITABENT(SampleGrabberCB, IMFSampleGrabberSinkCallback), 32 | QITABENT(SampleGrabberCB, IMFClockStateSink), 33 | {0} 34 | }; 35 | return QISearch(this, qit, riid, ppv); 36 | } 37 | 38 | STDMETHODIMP_(ULONG) SampleGrabberCB::AddRef() 39 | { 40 | return InterlockedIncrement(&m_cRef); 41 | } 42 | 43 | STDMETHODIMP_(ULONG) SampleGrabberCB::Release() 44 | { 45 | ULONG cRef = InterlockedDecrement(&m_cRef); 46 | if(cRef == 0) 47 | { 48 | delete this; 49 | } 50 | return cRef; 51 | 52 | } 53 | 54 | // IMFClockStateSink methods. 55 | 56 | // In these example, the IMFClockStateSink methods do not perform any actions. 57 | // You can use these methods to track the state of the sample grabber sink. 58 | 59 | STDMETHODIMP SampleGrabberCB::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset) 60 | { 61 | return S_OK; 62 | } 63 | 64 | STDMETHODIMP SampleGrabberCB::OnClockStop(MFTIME hnsSystemTime) 65 | { 66 | return S_OK; 67 | } 68 | 69 | STDMETHODIMP SampleGrabberCB::OnClockPause(MFTIME hnsSystemTime) 70 | { 71 | return S_OK; 72 | } 73 | 74 | STDMETHODIMP SampleGrabberCB::OnClockRestart(MFTIME hnsSystemTime) 75 | { 76 | return S_OK; 77 | } 78 | 79 | STDMETHODIMP SampleGrabberCB::OnClockSetRate(MFTIME hnsSystemTime, float flRate) 80 | { 81 | return S_OK; 82 | } 83 | 84 | // IMFSampleGrabberSink methods. 85 | 86 | STDMETHODIMP SampleGrabberCB::OnSetPresentationClock(IMFPresentationClock* pClock) 87 | { 88 | return S_OK; 89 | } 90 | 91 | STDMETHODIMP SampleGrabberCB::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, 92 | LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer, 93 | DWORD dwSampleSize) 94 | { 95 | // Display information about the sample. 96 | printf_guid(guidMajorMediaType); 97 | //printf_guid(_majorMediaType); 98 | printf("Sample: start = %I64d, duration = %I64d, bytes = %d\n", llSampleTime, llSampleDuration, dwSampleSize); 99 | return S_OK; 100 | } 101 | 102 | STDMETHODIMP SampleGrabberCB::OnShutdown() 103 | { 104 | return S_OK; 105 | } 106 | -------------------------------------------------------------------------------- /MFSampleGrabber/SampleGrabber.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #pragma comment(lib, "mfplat") 11 | #pragma comment(lib, "mf") 12 | #pragma comment(lib, "mfuuid") 13 | #pragma comment(lib, "Shlwapi") 14 | 15 | template void SafeRelease(T **ppT) 16 | { 17 | if(*ppT) 18 | { 19 | (*ppT)->Release(); 20 | *ppT = NULL; 21 | } 22 | } 23 | 24 | #define CHECK_HR(x) if (FAILED(x)) { goto done; } 25 | 26 | // The class that implements the callback interface. 27 | class SampleGrabberCB: public IMFSampleGrabberSinkCallback 28 | { 29 | long m_cRef; 30 | 31 | SampleGrabberCB(): m_cRef(1) {} 32 | 33 | private: 34 | GUID _majorMediaType; 35 | 36 | public: 37 | static HRESULT CreateInstance(SampleGrabberCB **ppCB, REFGUID majorMediaType); 38 | 39 | // IUnknown methods 40 | STDMETHODIMP QueryInterface(REFIID iid, void** ppv); 41 | STDMETHODIMP_(ULONG) AddRef(); 42 | STDMETHODIMP_(ULONG) Release(); 43 | 44 | // IMFClockStateSink methods 45 | STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset); 46 | STDMETHODIMP OnClockStop(MFTIME hnsSystemTime); 47 | STDMETHODIMP OnClockPause(MFTIME hnsSystemTime); 48 | STDMETHODIMP OnClockRestart(MFTIME hnsSystemTime); 49 | STDMETHODIMP OnClockSetRate(MFTIME hnsSystemTime, float flRate); 50 | 51 | // IMFSampleGrabberSinkCallback methods 52 | STDMETHODIMP OnSetPresentationClock(IMFPresentationClock* pClock); 53 | STDMETHODIMP OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, 54 | LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE * pSampleBuffer, 55 | DWORD dwSampleSize); 56 | STDMETHODIMP OnShutdown(); 57 | }; -------------------------------------------------------------------------------- /MFTopology/MFTopology.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFTopology", "MFTopology.vcxproj", "{C152E878-1BB8-4133-9322-B99AE1B3C3DF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C152E878-1BB8-4133-9322-B99AE1B3C3DF}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {C152E878-1BB8-4133-9322-B99AE1B3C3DF}.Debug|Win32.Build.0 = Debug|Win32 16 | {C152E878-1BB8-4133-9322-B99AE1B3C3DF}.Release|Win32.ActiveCfg = Release|Win32 17 | {C152E878-1BB8-4133-9322-B99AE1B3C3DF}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFTopology/MFTopology.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {C152E878-1BB8-4133-9322-B99AE1B3C3DF} 15 | Win32Proj 16 | MFTopology 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | Unicode 24 | false 25 | 26 | 27 | Application 28 | false 29 | v142 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 56 | 57 | 58 | Console 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 71 | 72 | 73 | Console 74 | true 75 | true 76 | true 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /MFVideoEVR/MFVideoEVR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFVideoEVR", "MFVideoEVR.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|Win32.Build.0 = Debug|Win32 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|Win32.ActiveCfg = Release|Win32 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|Win32.Build.0 = Release|Win32 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /MFVideoEVR/MFVideoEVR.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFVideo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFVideoEVRWebcam/MFVideoEVRWebcam.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFVideoEVRWebcam", "MFVideoEVRWebcam.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|x64 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|x64 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.ActiveCfg = Release|Win32 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {51C31229-FD64-4312-B893-449F58B70CA2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFVideoEVRWebcam/MFVideoEVRWebcam.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFVideo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFVideoEVRWebcamMFT/MFVideoEVRWebcamMFT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFVideoEVRWebcamMFT", "MFVideoEVRWebcamMFT.vcxproj", "{A1498E34-8C3E-4977-98F7-216C34633DBC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.ActiveCfg = Debug|x64 17 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x64.Build.0 = Debug|x64 18 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.ActiveCfg = Debug|Win32 19 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Debug|x86.Build.0 = Debug|Win32 20 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.ActiveCfg = Release|x64 21 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x64.Build.0 = Release|x64 22 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.ActiveCfg = Release|Win32 23 | {A1498E34-8C3E-4977-98F7-216C34633DBC}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {51C31229-FD64-4312-B893-449F58B70CA2} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFVideoEVRWebcamMFT/MFVideoEVRWebcamMFT.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | {A1498E34-8C3E-4977-98F7-216C34633DBC} 26 | Win32Proj 27 | MFVideo 28 | 10.0 29 | 30 | 31 | 32 | Application 33 | true 34 | v142 35 | Unicode 36 | false 37 | 38 | 39 | Application 40 | true 41 | v142 42 | Unicode 43 | false 44 | 45 | 46 | Application 47 | false 48 | v142 49 | true 50 | Unicode 51 | 52 | 53 | Application 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | NotUsing 90 | Level3 91 | Disabled 92 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 93 | true 94 | 95 | 96 | Console 97 | true 98 | mfplat.lib;%(AdditionalDependencies) 99 | 100 | 101 | 102 | 103 | NotUsing 104 | Level3 105 | Disabled 106 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 107 | true 108 | 109 | 110 | Console 111 | true 112 | mfplat.lib;%(AdditionalDependencies) 113 | 114 | 115 | 116 | 117 | Level3 118 | Use 119 | MaxSpeed 120 | true 121 | true 122 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 123 | true 124 | 125 | 126 | Console 127 | true 128 | true 129 | true 130 | 131 | 132 | 133 | 134 | Level3 135 | Use 136 | MaxSpeed 137 | true 138 | true 139 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 140 | true 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /MFWebCamRtp/MFWebCamRtp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebCamRtp", "MFWebCamRtp.vcxproj", "{923E40AD-BBE5-4697-857B-90F3AB8DA965}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|Win32.Build.0 = Debug|Win32 18 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.ActiveCfg = Debug|x64 19 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.Build.0 = Debug|x64 20 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|Win32.ActiveCfg = Release|Win32 21 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|Win32.Build.0 = Release|Win32 22 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.ActiveCfg = Release|x64 23 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1D8A20DB-700C-43BE-93BD-6E5524C97A09} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFWebCamRtp/test.sdp: -------------------------------------------------------------------------------- 1 | v=0 2 | o=- 0 0 IN IP4 127.0.0.1 3 | s=No Name 4 | t=0 0 5 | c=IN IP4 127.0.0.1 6 | m=video 1234 RTP/AVP 96 7 | a=rtpmap:96 H264/90000 8 | a=fmtp:96 packetization-mode=1 -------------------------------------------------------------------------------- /MFWebCamToFile/MFWebCamToFile.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Filename: MFWebCamToFile.cpp 3 | * 4 | * Description: 5 | * This file contains a C++ console application that captures the real-time video 6 | * stream from a webcam to an MP4 file. 7 | * 8 | * Note: The webcam index and the source reader media output type will need 9 | * adjustment depending on the configuration of video devices on the machine 10 | * running this sample. 11 | * 12 | * Author: 13 | * Aaron Clauson (aaron@sipsorcery.com) 14 | * 15 | * History: 16 | * 26 Feb 2015 Aaron Clauson Created, Hobart, Australia. 17 | * 10 Jan 2020 Aaron Clauson Added defines for webcam resolution. 18 | * 19 | * License: Public Domain (no warranty, use at own risk) 20 | /******************************************************************************/ 21 | 22 | #include "../Common/MFUtility.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #pragma comment(lib, "mf.lib") 35 | #pragma comment(lib, "mfplat.lib") 36 | #pragma comment(lib, "mfplay.lib") 37 | #pragma comment(lib, "mfreadwrite.lib") 38 | #pragma comment(lib, "mfuuid.lib") 39 | #pragma comment(lib, "wmcodecdspuuid.lib") 40 | 41 | #define WEBCAM_DEVICE_INDEX 0 // Adjust according to desired video capture device. 42 | #define SAMPLE_COUNT 100 // Adjust depending on number of samples to capture. 43 | #define CAPTURE_FILENAME L"capture.mp4" 44 | #define OUTPUT_FRAME_WIDTH 640 // Adjust if the webcam does not support this frame width. 45 | #define OUTPUT_FRAME_HEIGHT 480 // Adjust if the webcam does not support this frame height. 46 | #define OUTPUT_FRAME_RATE 30 // Adjust if the webcam does not support this frame rate. 47 | 48 | int main() 49 | { 50 | IMFMediaSource *pVideoSource = NULL; 51 | UINT32 videoDeviceCount = 0; 52 | IMFAttributes *videoConfig = NULL; 53 | IMFActivate **videoDevices = NULL; 54 | IMFSourceReader *pVideoReader = NULL; 55 | WCHAR *webcamFriendlyName; 56 | IMFMediaType* pSourceOutputType = NULL; 57 | IMFSinkWriter *pWriter = NULL; 58 | IMFMediaType *pVideoOutType = NULL; 59 | DWORD writerVideoStreamIndex = 0; 60 | UINT webcamNameLength = 0; 61 | 62 | CHECK_HR(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE), 63 | "COM initialisation failed."); 64 | 65 | CHECK_HR(MFStartup(MF_VERSION), 66 | "Media Foundation initialisation failed."); 67 | 68 | // Get the first available webcam. 69 | CHECK_HR(MFCreateAttributes(&videoConfig, 1), 70 | "Error creating video configuration."); 71 | 72 | // Request video capture devices. 73 | CHECK_HR(videoConfig->SetGUID( 74 | MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, 75 | MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID), 76 | "Error initialising video configuration object."); 77 | 78 | CHECK_HR(MFEnumDeviceSources(videoConfig, &videoDevices, &videoDeviceCount), 79 | "Error enumerating video devices."); 80 | 81 | CHECK_HR(videoDevices[WEBCAM_DEVICE_INDEX]->GetAllocatedString(MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &webcamFriendlyName, &webcamNameLength), 82 | "Error retrieving video device friendly name."); 83 | 84 | wprintf(L"First available webcam: %s\n", webcamFriendlyName); 85 | 86 | CHECK_HR(videoDevices[WEBCAM_DEVICE_INDEX]->ActivateObject(IID_PPV_ARGS(&pVideoSource)), 87 | "Error activating video device."); 88 | 89 | // Create a source reader. 90 | CHECK_HR(MFCreateSourceReaderFromMediaSource( 91 | pVideoSource, 92 | videoConfig, 93 | &pVideoReader), 94 | "Error creating video source reader."); 95 | 96 | // Note the webcam needs to support this media type. 97 | MFCreateMediaType(&pSourceOutputType); 98 | CHECK_HR(pSourceOutputType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video), "Failed to set major video type."); 99 | CHECK_HR(pSourceOutputType->SetGUID(MF_MT_SUBTYPE, WMMEDIASUBTYPE_I420), "Failed to set video sub type to I420."); 100 | //CHECK_HR(pSourceOutputType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB24), "Failed to set video sub type."); 101 | CHECK_HR(MFSetAttributeRatio(pSourceOutputType, MF_MT_FRAME_RATE, OUTPUT_FRAME_RATE, 1), "Failed to set frame rate on source reader out type."); 102 | CHECK_HR(MFSetAttributeSize(pSourceOutputType, MF_MT_FRAME_SIZE, OUTPUT_FRAME_WIDTH, OUTPUT_FRAME_HEIGHT), "Failed to set frame size."); 103 | 104 | CHECK_HR(pVideoReader->SetCurrentMediaType(0, NULL, pSourceOutputType), 105 | "Failed to set media type on source reader."); 106 | 107 | // Create the MP4 sink writer. 108 | CHECK_HR(MFCreateSinkWriterFromURL( 109 | CAPTURE_FILENAME, 110 | NULL, 111 | NULL, 112 | &pWriter), 113 | "Error creating mp4 sink writer."); 114 | 115 | CHECK_HR(MFTRegisterLocalByCLSID( 116 | __uuidof(CColorConvertDMO), 117 | MFT_CATEGORY_VIDEO_PROCESSOR, 118 | L"", 119 | MFT_ENUM_FLAG_SYNCMFT, 120 | 0, 121 | NULL, 122 | 0, 123 | NULL 124 | ), 125 | "Error registering colour converter DSP.\n"); 126 | 127 | // Configure the output video type on the sink writer. 128 | CHECK_HR(MFCreateMediaType(&pVideoOutType), "Configure encoder failed to create media type for video output sink."); 129 | CHECK_HR(pSourceOutputType->CopyAllItems(pVideoOutType), "Error copying media type attributes from source output media type."); 130 | // Only thing we want to change from source to sink is to get an mp4 output. 131 | CHECK_HR(pVideoOutType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_H264), "Failed to set video writer attribute, video format (H.264)."); 132 | CHECK_HR(pVideoOutType->SetUINT32(MF_MT_AVG_BITRATE, 240000), "Error setting average bit rate."); 133 | CHECK_HR(pVideoOutType->SetUINT32(MF_MT_INTERLACE_MODE, 2), "Error setting interlace mode."); 134 | CHECK_HR(MFSetAttributeRatio(pVideoOutType, MF_MT_MPEG2_PROFILE, eAVEncH264VProfile_Base, 1), "Failed to set profile on H264 MFT out type."); 135 | 136 | CHECK_HR(pWriter->AddStream(pVideoOutType, &writerVideoStreamIndex), 137 | "Failed to add the video stream to the sink writer."); 138 | 139 | CHECK_HR(pWriter->SetInputMediaType(writerVideoStreamIndex, pSourceOutputType, NULL), 140 | "Error setting the sink writer video input type."); 141 | 142 | CHECK_HR(pWriter->BeginWriting(), 143 | "Failed to begin writing on the H.264 sink."); 144 | 145 | DWORD streamIndex, flags; 146 | LONGLONG llVideoTimeStamp; 147 | IMFSample *videoSample = NULL; 148 | LONGLONG llVideoBaseTime = 0; 149 | int sampleCount = 0; 150 | 151 | printf("Recording...\n"); 152 | 153 | while (sampleCount < SAMPLE_COUNT) 154 | { 155 | CHECK_HR(pVideoReader->ReadSample( 156 | MF_SOURCE_READER_ANY_STREAM, // Stream index. 157 | 0, // Flags. 158 | &streamIndex, // Receives the actual stream index. 159 | &flags, // Receives status flags. 160 | &llVideoTimeStamp, // Receives the time stamp. 161 | &videoSample // Receives the sample or NULL. 162 | ), "Error reading video sample."); 163 | 164 | if (videoSample) 165 | { 166 | // Re-base the time stamp. 167 | llVideoTimeStamp -= llVideoBaseTime; 168 | 169 | CHECK_HR(videoSample->SetSampleTime(llVideoTimeStamp), "Set video sample time failed."); 170 | CHECK_HR(pWriter->WriteSample(writerVideoStreamIndex, videoSample), "Write video sample failed."); 171 | 172 | SAFE_RELEASE(&videoSample); 173 | } 174 | 175 | sampleCount++; 176 | } 177 | 178 | printf("Finalising the capture.\n"); 179 | 180 | if (pWriter) 181 | { 182 | CHECK_HR(pWriter->Finalize(), "Error finalising H.264 sink writer."); 183 | } 184 | 185 | 186 | done: 187 | 188 | printf("finished.\n"); 189 | auto c = getchar(); 190 | 191 | SAFE_RELEASE(pVideoSource); 192 | SAFE_RELEASE(videoConfig); 193 | SAFE_RELEASE(videoDevices); 194 | SAFE_RELEASE(pVideoReader); 195 | SAFE_RELEASE(pVideoOutType); 196 | SAFE_RELEASE(pSourceOutputType); 197 | SAFE_RELEASE(pWriter); 198 | 199 | return 0; 200 | } 201 | -------------------------------------------------------------------------------- /MFWebCamToFile/MFWebCamToFile.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebCamToFile", "MFWebCamToFile.vcxproj", "{2F529D37-BDC1-481A-B49E-883FC0C0CA64}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Debug|Win32.Build.0 = Debug|Win32 16 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Release|Win32.ActiveCfg = Release|Win32 17 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFWebCamToFile/MFWebCamToFile.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64} 15 | Win32Proj 16 | MFWebCamToFile 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | Unicode 24 | false 25 | 26 | 27 | Application 28 | false 29 | v142 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 56 | 57 | 58 | Console 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 71 | 72 | 73 | Console 74 | true 75 | true 76 | true 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /MFWebCamToH264Buffer/MFWebCamToH264Buffer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.21005.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebCamToH264Buffer", "MFWebCamToH264Buffer.vcxproj", "{923E40AD-BBE5-4697-857B-90F3AB8DA965}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|Win32.Build.0 = Debug|Win32 16 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|Win32.ActiveCfg = Release|Win32 17 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /MFWebCamToH264Buffer/MFWebCamToH264Buffer.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {923E40AD-BBE5-4697-857B-90F3AB8DA965} 15 | Win32Proj 16 | MFWebCamToH264Buffer 17 | 18 | 19 | 20 | Application 21 | true 22 | v142 23 | Unicode 24 | false 25 | 26 | 27 | Application 28 | false 29 | v142 30 | true 31 | Unicode 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | true 45 | 46 | 47 | false 48 | 49 | 50 | 51 | 52 | 53 | Level3 54 | Disabled 55 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 56 | 57 | 58 | Console 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 71 | 72 | 73 | Console 74 | true 75 | true 76 | true 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /MFWebCamWebRTC/MFWebCamWebRTC.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebCamWebRTC", "MFWebCamWebRTC.vcxproj", "{923E40AD-BBE5-4697-857B-90F3AB8DA965}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.ActiveCfg = Debug|x64 17 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.Build.0 = Debug|x64 18 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x86.ActiveCfg = Debug|Win32 19 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x86.Build.0 = Debug|Win32 20 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.ActiveCfg = Release|x64 21 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.Build.0 = Release|x64 22 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x86.ActiveCfg = Release|Win32 23 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1D8A20DB-700C-43BE-93BD-6E5524C97A09} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFWebCamWebRTC/localhost.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFCDCCAvCgAwIBAgIUfWHUqwAh+2e7k1C2ZDFVsDqGiR8wDQYJKoZIhvcNAQEL 3 | BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE5MDgyNDAzMTU1N1oXDTI5MDgy 4 | MTAzMTU1N1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF 5 | AAOCAg8AMIICCgKCAgEAqB125PDXNETF9T90XhiSV7SH5FbPvGr9oc0jWvXOM+9g 6 | J9yL1NaMGfXZhFtt4xAEjqs+vRwtHQANzjyU2gXMTnw8UdtX8fPe8+mjAC9xD8CK 7 | RoHXhOaOafUaJvQSGhXmUOj7L9e1SDfxT4l67NnlFFCMUV+EvwnMAQjjOxzyJ/zw 8 | Q9/2+gEEqZJS1vmplXppPjRUVPZ0/tyhJxD624WPda97HiaRRhVebriPQhd2ES4m 9 | NzgmyfBjlegfSlpFw2Fe0DWN2atBpHpNUjbE0Gw65hD6N/nau5yhVJk2LrKjnAfQ 10 | xq0tB4S6jnaUTgl3eDiRpGfRn9ZkvrkzPxs2nA1WPskIosr1HXu6ArTg8P7c2B7A 11 | qg3KxtlA1moUXZ9C7phJyjjEevl0F2bY0HLWOGVI+ZjeuYmgJU3xLdcLWbHGxUiV 12 | a7CCtKSo6jmkkC9X73d6/Fw1p4nWhzvULh11Na6Lu3YJVDxkIpVrUxWDr3ys42eI 13 | 2N49h1FwvhtTVei5A4SKR2LWq5g74Rtmq7+Qmnl5OxMHxVM+fFhfS/eSQmnG0rLf 14 | 15ZYEiIKyaZfOwbupcPfpnHOqGN8NXv/53kEvbnZvpk5hHXkA8J0gCix24cPSUy3 15 | mYUQdYoCrn+6cIcfMrjZU+Wdm0V5sZUkEJSslsB6SgAg8NeywUwvQUS7bih+Bz8C 16 | AwEAAaNSMFAwLAYDVR0RBCUwI4IJbG9jYWxob3N0hwR/AAABhxAAAAAAAAAAAAAA 17 | AAAAAAABMAsGA1UdDwQEAwIEsDATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG 18 | 9w0BAQsFAAOCAgEAQrNcJvI5KhsodBBKtdvjj+kxcgGJ9rva4q9SGtG3umgGAHUh 19 | 8odjBXcJfiQwj3VMC6avllEBKjiYlN7jOmMn5RZ8xp1akmNO5HttusD/0dDIPKIY 20 | 1GYf1GkdZgRquS7Ahq3mOee4EB1uUzT/VeksJf5jUBETIOfMEOW6Vxb8v8GpRm01 21 | utxumx4RDLJVkWMoiyt4S0m6bT1F17d2dyzmrCrUicV/Gw4L2SKKbSWRn6AKtjkU 22 | qRKXXDAaDbM5JCpiIdiBSyDw3euCWvNxNVSwbBz2f4iNcGmrNyT5zHtWeom1GQAo 23 | uyNfFJrEPOrhI7v08tiKDZVRwQMCtsiV7F4kmqEiPjNXeb93IAaWKGg6eqxJ2PGu 24 | orq3uYJreVPXTjgaPWdx3Ljmn7aOPigO3aWcqs/8BukQMmac25zvcC0EGqfgHCUQ 25 | w/CuYZAm90y3sI9+DyWpNDFA8nE/FtK5KsLVgpxXN26BntImjrlFci7TfYWX8eGv 26 | wNP+akFPIFGGqFM9cNz9/JCtOBelAtuCFLkMH97Y7V6gdWLWtbmtn0mdnN+meIkP 27 | Wb4r2rQ+riJcDsuWW6vDD4Laco9srfk2vgaznLowGS4AUsyiHMc4eV4wVxKM35/f 28 | Fq+136fdqUT1/imD+fMYspZxODcEDiYuyISg0m1KeMz/YL9qnISwpx+cooM= 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /MFWebCamWebRTC/localhost_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | 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 51 | 1g4YquBYvf2ugySqc6cZD7O0e1JJ 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /MFWebCamWebRTC/mfwebrtc.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 |
68 | 69 | 70 | -------------------------------------------------------------------------------- /MFWebCamWebRTCH264/MFWebCamWebRTCH264.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebCamWebRTC", "MFWebCamWebRTCH264.vcxproj", "{923E40AD-BBE5-4697-857B-90F3AB8DA965}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.ActiveCfg = Debug|x64 17 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x64.Build.0 = Debug|x64 18 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x86.ActiveCfg = Debug|Win32 19 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Debug|x86.Build.0 = Debug|Win32 20 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.ActiveCfg = Release|x64 21 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x64.Build.0 = Release|x64 22 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x86.ActiveCfg = Release|Win32 23 | {923E40AD-BBE5-4697-857B-90F3AB8DA965}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {1D8A20DB-700C-43BE-93BD-6E5524C97A09} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /MFWebCamWebRTCH264/localhost.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFCDCCAvCgAwIBAgIUfWHUqwAh+2e7k1C2ZDFVsDqGiR8wDQYJKoZIhvcNAQEL 3 | BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTE5MDgyNDAzMTU1N1oXDTI5MDgy 4 | MTAzMTU1N1owFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF 5 | AAOCAg8AMIICCgKCAgEAqB125PDXNETF9T90XhiSV7SH5FbPvGr9oc0jWvXOM+9g 6 | J9yL1NaMGfXZhFtt4xAEjqs+vRwtHQANzjyU2gXMTnw8UdtX8fPe8+mjAC9xD8CK 7 | RoHXhOaOafUaJvQSGhXmUOj7L9e1SDfxT4l67NnlFFCMUV+EvwnMAQjjOxzyJ/zw 8 | Q9/2+gEEqZJS1vmplXppPjRUVPZ0/tyhJxD624WPda97HiaRRhVebriPQhd2ES4m 9 | NzgmyfBjlegfSlpFw2Fe0DWN2atBpHpNUjbE0Gw65hD6N/nau5yhVJk2LrKjnAfQ 10 | xq0tB4S6jnaUTgl3eDiRpGfRn9ZkvrkzPxs2nA1WPskIosr1HXu6ArTg8P7c2B7A 11 | qg3KxtlA1moUXZ9C7phJyjjEevl0F2bY0HLWOGVI+ZjeuYmgJU3xLdcLWbHGxUiV 12 | a7CCtKSo6jmkkC9X73d6/Fw1p4nWhzvULh11Na6Lu3YJVDxkIpVrUxWDr3ys42eI 13 | 2N49h1FwvhtTVei5A4SKR2LWq5g74Rtmq7+Qmnl5OxMHxVM+fFhfS/eSQmnG0rLf 14 | 15ZYEiIKyaZfOwbupcPfpnHOqGN8NXv/53kEvbnZvpk5hHXkA8J0gCix24cPSUy3 15 | mYUQdYoCrn+6cIcfMrjZU+Wdm0V5sZUkEJSslsB6SgAg8NeywUwvQUS7bih+Bz8C 16 | AwEAAaNSMFAwLAYDVR0RBCUwI4IJbG9jYWxob3N0hwR/AAABhxAAAAAAAAAAAAAA 17 | AAAAAAABMAsGA1UdDwQEAwIEsDATBgNVHSUEDDAKBggrBgEFBQcDATANBgkqhkiG 18 | 9w0BAQsFAAOCAgEAQrNcJvI5KhsodBBKtdvjj+kxcgGJ9rva4q9SGtG3umgGAHUh 19 | 8odjBXcJfiQwj3VMC6avllEBKjiYlN7jOmMn5RZ8xp1akmNO5HttusD/0dDIPKIY 20 | 1GYf1GkdZgRquS7Ahq3mOee4EB1uUzT/VeksJf5jUBETIOfMEOW6Vxb8v8GpRm01 21 | utxumx4RDLJVkWMoiyt4S0m6bT1F17d2dyzmrCrUicV/Gw4L2SKKbSWRn6AKtjkU 22 | qRKXXDAaDbM5JCpiIdiBSyDw3euCWvNxNVSwbBz2f4iNcGmrNyT5zHtWeom1GQAo 23 | uyNfFJrEPOrhI7v08tiKDZVRwQMCtsiV7F4kmqEiPjNXeb93IAaWKGg6eqxJ2PGu 24 | orq3uYJreVPXTjgaPWdx3Ljmn7aOPigO3aWcqs/8BukQMmac25zvcC0EGqfgHCUQ 25 | w/CuYZAm90y3sI9+DyWpNDFA8nE/FtK5KsLVgpxXN26BntImjrlFci7TfYWX8eGv 26 | wNP+akFPIFGGqFM9cNz9/JCtOBelAtuCFLkMH97Y7V6gdWLWtbmtn0mdnN+meIkP 27 | Wb4r2rQ+riJcDsuWW6vDD4Laco9srfk2vgaznLowGS4AUsyiHMc4eV4wVxKM35/f 28 | Fq+136fdqUT1/imD+fMYspZxODcEDiYuyISg0m1KeMz/YL9qnISwpx+cooM= 29 | -----END CERTIFICATE----- 30 | -------------------------------------------------------------------------------- /MFWebCamWebRTCH264/localhost_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | 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 51 | 1g4YquBYvf2ugySqc6cZD7O0e1JJ 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /MFWebCamWebRTCH264/mfwebrtc.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /MFWebcamAndMicrophoneToFile/MFWebcamAndMicrophoneToFile.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29709.97 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MFWebcamAndMicrophoneToFile", "MFWebcamAndMicrophoneToFile.vcxproj", "{2F529D37-BDC1-481A-B49E-883FC0C0CA64}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x86 = Debug|x86 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Debug|x86.ActiveCfg = Debug|Win32 15 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Debug|x86.Build.0 = Debug|Win32 16 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Release|x86.ActiveCfg = Release|Win32 17 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64}.Release|x86.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {98FCC355-F65A-43CE-98AA-3ED4468D4D2C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /MFWebcamAndMicrophoneToFile/MFWebcamAndMicrophoneToFile.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | {2F529D37-BDC1-481A-B49E-883FC0C0CA64} 18 | Win32Proj 19 | MFWebCamToFile 20 | 21 | 22 | 23 | Application 24 | true 25 | v142 26 | Unicode 27 | false 28 | 29 | 30 | Application 31 | false 32 | v142 33 | true 34 | Unicode 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | true 48 | 49 | 50 | false 51 | 52 | 53 | 54 | 55 | 56 | Level3 57 | Disabled 58 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 59 | 60 | 61 | Console 62 | true 63 | 64 | 65 | 66 | 67 | Level3 68 | 69 | 70 | MaxSpeed 71 | true 72 | true 73 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 74 | 75 | 76 | Console 77 | true 78 | true 79 | true 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /MFWebcamAndMicrophoneToFile/capture.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MFWebcamAndMicrophoneToFile/capture.mp4 -------------------------------------------------------------------------------- /MediaFiles/LICENSE-Macroform: -------------------------------------------------------------------------------- 1 | These files are distributed under the Creative Commons Attribution-ShareAlike 2 | 3.0 license through explicit permission from their authors. 3 | 4 | The license can be found at: 5 | https://creativecommons.org/licenses/by-nd/2.0/ 6 | 7 | Artist: Macroform Music https://macroformmusic.com/. -------------------------------------------------------------------------------- /MediaFiles/Macroform_-_Simplicity.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MediaFiles/Macroform_-_Simplicity.mp3 -------------------------------------------------------------------------------- /MediaFiles/Macroform_-_Simplicity.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MediaFiles/Macroform_-_Simplicity.wav -------------------------------------------------------------------------------- /MediaFiles/big_buck_bunny.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MediaFiles/big_buck_bunny.mp4 -------------------------------------------------------------------------------- /MediaFiles/big_buck_bunny_48k.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MediaFiles/big_buck_bunny_48k.mp4 -------------------------------------------------------------------------------- /MediaFiles/sound_in_sync_test.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/MediaFiles/sound_in_sync_test.mp4 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unofficial Windows Media Foundation Samples 2 | 3 | Official samples are available [here](https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/mediafoundation) and a brief overview web page [here](https://docs.microsoft.com/en-us/windows/win32/medfound/media-foundation-sdk-samples). 4 | 5 | Update Sep 2020: A new official Media Foundation samples repository has been created at [microsoft/media-foundation](https://github.com/microsoft/media-foundation). 6 | 7 | A set of minimal sample applications that demonstrate how to use certain parts of Microsoft's Windows Media Foundation API. The original motivation for these samples was an attempt to find a way to stream audio and video from a webcam, encoded as H264 and/or VP8, over RTP and then render at the remote destination. As of January 2020 the MFWebCamRtp sample has been used to stream H264 samples from a webcam source to ffplay. 8 | 9 | ### Rendering 10 | 11 | - MFAudio - Play audio from file on speaker. 12 | 13 | - MFAudioCaptureToSAR - Capture on default audio capture device (microphone) and playback on default audio output device (speaker). 14 | 15 | - MFBitmapMftToEVR - Performs a colour conversion on a bitmap byte array and then displays on the Enhanced Video Renderer. 16 | 17 | - MFBitmapToEVR - Displays a byte array representing a bitmap on the Enhanced Video Renderer. 18 | 19 | - MFTopology - Plays audio and video from an mp4 file using the Enhanced Video Renderer and Streaming Audio Renderer. 20 | 21 | - MFVideoEVR - Display video from an mp4 file in Window WITHOUT using a topology. Write samples to video renderer directly from buffer. 22 | 23 | - MFVideoEVRWebcam - Same as the `MFVideoEVR` sample but replacing the file source with a webcam. 24 | 25 | - MFVideoEVRWebcamMFT - Same as the `MFVideoEVRWebcam` sample but manually wires up a color conversion MFT transform instead of setting MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING on the video source reader. 26 | 27 | - WpfMediaUWA - Initial foray into how Media Foundation can work with WPF in a Universal Windows Application (UWA). UWA is currently impractical due to [deployment constraints](https://docs.microsoft.com/en-us/windows/apps/desktop/choose-your-platform), i.e. Windows Store only. Hopefully in 2020 with the introduction of [Windows UI 3.0](https://docs.microsoft.com/en-us/uwp/toolkits/) using the types of controls in this sample will become practical. 28 | 29 | ### Plumbing 30 | 31 | - MFCaptureRawFramesToFile - Captures 100 samples from default webcam to file. 32 | 33 | - MFListTransforms - Lists the available MFT Transforms to convert between two media types. 34 | 35 | - MFMP4ToYUVWithMFT - Reads H264 encoded video frames from an mp4 file and decodes them to a YUV pixel format and dumps them to an output file. 36 | 37 | - MFMP4ToYUVWithoutMFT - Same as the previous (MFMP4ToYUVWithMFT) sample but WITHOUT having to wire up the H264 decoder. Reads H264 encoded video frames from an mp4 file and decodes them to a YUV pixel format and dumps them to an output file. 38 | 39 | - MFSampleGrabber - Copy of the Sample Grabber Sink example from https://docs.microsoft.com/en-us/windows/win32/medfound/using-the-sample-grabber-sink but grabbing both audio and video samples from an mp4 file rather than solely audio samples. 40 | 41 | - MFWebCamToFile - Captures 100 samples from default webcam to an mp4 file. 42 | 43 | ### Webcam -> H264 -> RTP 44 | 45 | - MFH264RoundTrip - Captures video frames, H264 encode to byte array, decode to YUV (replicates encode, transmit, decode). 46 | 47 | - MFWebCamRtp - Stream webcam video over RTP to ffplay. 48 | 49 | - MFWebCamToH264Buffer - Captures the video stream from a webcam to an H264 byte array by directly using the MFT H264 Encoder. 50 | 51 | ### Webcam -> H264/VP8 -> WebRTC -> Web Browser 52 | 53 | - MFWebCamWebRTC - Stream VP8 encoded webcam video to a WebRTC client (only works with Chrome). 54 | 55 | - MFWebCamWebRTCH264 - **Not Working** Stream H264 encoded webcam video to a WebRTC client. 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /WpfMediaUWA/Readme.txt: -------------------------------------------------------------------------------- 1 | Date: 29 Oct 2015 2 | Author: Aaron Clauson 3 | Solution Name: WpfMediaUWA.sln 4 | 5 | Description: 6 | 7 | Initial foray into how Media Foundation can work with WPF in a Universal Windows Application 8 | targetted for Windows 10. 9 | 10 | The goal was to create a WPF application that could do two things: 11 | 12 | 1. Display the live feed from a webcam, 13 | 2. Display video from an H264 bitstream decoded by the Media Foundation. 14 | 15 | (There was an intermediate step which was to display an RGB24 bitmap generated via 16 | Media Foundation and that't the roving square stuff) 17 | 18 | For once it was surprising how easy it was to get the sample working once the 19 | whole Universal Windows approach is understood a bit better. In particular using a webcam 20 | in WPF is now literally a handful of lines of code which is a huge improvement on the 21 | past (doing this on Windows 7 took literally hundreds of lines of code). 22 | 23 | Getting the output from an mp4 file onto a WPF surface also turned out to be surprisingly 24 | smooth expecially considering I haven't been able to acheive the same thing with a Win32 25 | window handle despite a lot fo effort. -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/App.xaml: -------------------------------------------------------------------------------- 1 |  7 | 8 | 9 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Windows.ApplicationModel; 3 | using Windows.ApplicationModel.Activation; 4 | using Windows.UI.Xaml; 5 | using Windows.UI.Xaml.Controls; 6 | using Windows.UI.Xaml.Navigation; 7 | 8 | namespace WpfMedia 9 | { 10 | sealed partial class App : Application 11 | { 12 | /// 13 | /// Initializes the singleton application object. This is the first line of authored code 14 | /// executed, and as such is the logical equivalent of main() or WinMain(). 15 | /// 16 | public App() 17 | { 18 | Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync( 19 | Microsoft.ApplicationInsights.WindowsCollectors.Metadata | 20 | Microsoft.ApplicationInsights.WindowsCollectors.Session); 21 | this.InitializeComponent(); 22 | this.Suspending += OnSuspending; 23 | } 24 | 25 | /// 26 | /// Invoked when the application is launched normally by the end user. Other entry points 27 | /// will be used such as when the application is launched to open a specific file. 28 | /// 29 | /// Details about the launch request and process. 30 | protected override void OnLaunched(LaunchActivatedEventArgs e) 31 | { 32 | 33 | #if DEBUG 34 | if (System.Diagnostics.Debugger.IsAttached) 35 | { 36 | this.DebugSettings.EnableFrameRateCounter = true; 37 | } 38 | #endif 39 | 40 | Frame rootFrame = Window.Current.Content as Frame; 41 | 42 | // Do not repeat app initialization when the Window already has content, 43 | // just ensure that the window is active 44 | if (rootFrame == null) 45 | { 46 | // Create a Frame to act as the navigation context and navigate to the first page 47 | rootFrame = new Frame(); 48 | 49 | rootFrame.NavigationFailed += OnNavigationFailed; 50 | 51 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 52 | { 53 | //TODO: Load state from previously suspended application 54 | } 55 | 56 | // Place the frame in the current Window 57 | Window.Current.Content = rootFrame; 58 | } 59 | 60 | if (rootFrame.Content == null) 61 | { 62 | // When the navigation stack isn't restored navigate to the first page, 63 | // configuring the new page by passing required information as a navigation 64 | // parameter 65 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 66 | } 67 | // Ensure the current window is active 68 | Window.Current.Activate(); 69 | } 70 | 71 | /// 72 | /// Invoked when Navigation to a certain page fails 73 | /// 74 | /// The Frame which failed navigation 75 | /// Details about the navigation failure 76 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 77 | { 78 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 79 | } 80 | 81 | /// 82 | /// Invoked when application execution is being suspended. Application state is saved 83 | /// without knowing whether the application will be terminated or resumed with the contents 84 | /// of memory still intact. 85 | /// 86 | /// The source of the suspend request. 87 | /// Details about the suspend request. 88 | private void OnSuspending(object sender, SuspendingEventArgs e) 89 | { 90 | var deferral = e.SuspendingOperation.GetDeferral(); 91 | //TODO: Save application state and stop any background activity 92 | deferral.Complete(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/ApplicationInsights.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/StoreLogo.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/big_buck_bunny.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/big_buck_bunny.mp4 -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Assets/max4.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/Assets/max4.mp4 -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading.Tasks; 4 | using Windows.Media.Capture; 5 | using Windows.Media.Core; 6 | using Windows.Media.MediaProperties; 7 | using Windows.UI.Xaml; 8 | using Windows.UI.Xaml.Controls; 9 | using Windows.UI.Xaml.Navigation; 10 | 11 | namespace WpfMedia 12 | { 13 | public sealed partial class MainPage : Page 14 | { 15 | private const int WIDTH = 640; 16 | private const int HEIGHT = 480; 17 | private const int MP4_WIDTH = 640; 18 | private const int MP4_HEIGHT = 480; 19 | private const int FRAME_RATE = 30; 20 | 21 | private MediaCapture _mediaCapture; 22 | VideoStreamDescriptor _videoDesc; 23 | Windows.Media.Core.MediaStreamSource _mss; 24 | SurfaceGenerator.SampleMaker _sampleMaker; 25 | SurfaceGenerator.Mp4Sampler _mp4Sampler; 26 | 27 | public MainPage() 28 | { 29 | this.InitializeComponent(); 30 | } 31 | 32 | protected async override void OnNavigatedTo(NavigationEventArgs e) 33 | { 34 | base.OnNavigatedTo(e); 35 | 36 | var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; 37 | Debug.WriteLine("Installed location folder path " + folder.Path + "."); 38 | 39 | //InitialiseRovingSquareSampleMedia(); 40 | 41 | InitialiseMp4FileMedia(folder.Path + @"\Assets\big_buck_bunny.mp4"); 42 | 43 | await InitialiseWebCamAsync(); 44 | } 45 | 46 | public void InitialiseRovingSquareSampleMedia() 47 | { 48 | VideoEncodingProperties videoProperties = VideoEncodingProperties.CreateUncompressed(MediaEncodingSubtypes.Bgra8, (uint)WIDTH, (uint)HEIGHT); 49 | _videoDesc = new VideoStreamDescriptor(videoProperties); 50 | _videoDesc.EncodingProperties.FrameRate.Numerator = FRAME_RATE; 51 | _videoDesc.EncodingProperties.FrameRate.Denominator = 1; 52 | _videoDesc.EncodingProperties.Bitrate = (uint)(1 * FRAME_RATE * WIDTH * HEIGHT * 4); 53 | 54 | _mss = new Windows.Media.Core.MediaStreamSource(_videoDesc); 55 | TimeSpan spanBuffer = new TimeSpan(0); 56 | _mss.BufferTime = spanBuffer; 57 | _mss.Starting += mss_Starting; 58 | _mss.SampleRequested += mss_SampleRequested; 59 | 60 | _sampleMaker = new SurfaceGenerator.SampleMaker(); 61 | 62 | _remoteVideo.MediaFailed += _remoteVideo_MediaFailed; 63 | _remoteVideo.SetMediaStreamSource(_mss); 64 | _remoteVideo.Play(); 65 | } 66 | 67 | public void InitialiseMp4FileMedia(string path) 68 | { 69 | try 70 | { 71 | VideoEncodingProperties videoProperties = VideoEncodingProperties.CreateH264(); 72 | _videoDesc = new VideoStreamDescriptor(videoProperties); 73 | _videoDesc.EncodingProperties.FrameRate.Numerator = FRAME_RATE; 74 | _videoDesc.EncodingProperties.FrameRate.Denominator = 1; 75 | //_videoDesc.EncodingProperties.Bitrate = (uint)(1 * FRAME_RATE * MP4_WIDTH * MP4_HEIGHT * 4); 76 | 77 | _mss = new Windows.Media.Core.MediaStreamSource(_videoDesc); 78 | TimeSpan spanBuffer = new TimeSpan(0); 79 | _mss.BufferTime = spanBuffer; 80 | _mss.Starting += mp4_Starting; 81 | _mss.SampleRequested += mp4_SampleRequested; 82 | 83 | _mp4Sampler = new SurfaceGenerator.Mp4Sampler(); 84 | 85 | _remoteVideo.MediaFailed += _remoteVideo_MediaFailed; 86 | _remoteVideo.SetMediaStreamSource(_mss); 87 | _remoteVideo.Play(); 88 | } 89 | catch(Exception excp) 90 | { 91 | Debug.WriteLine("Exception InitialiseMp4FileMedia. " + excp); 92 | } 93 | } 94 | 95 | public async Task InitialiseWebCamAsync() 96 | { 97 | _mediaCapture = new MediaCapture(); 98 | 99 | await _mediaCapture.InitializeAsync(); 100 | 101 | _localCamera.Source = _mediaCapture; 102 | 103 | await _mediaCapture.StartPreviewAsync(); 104 | } 105 | 106 | void mss_SampleRequested(Windows.Media.Core.MediaStreamSource sender, MediaStreamSourceSampleRequestedEventArgs args) 107 | { 108 | if (args.Request.StreamDescriptor is VideoStreamDescriptor) 109 | { 110 | _sampleMaker.GenerateSample(args.Request); 111 | } 112 | } 113 | 114 | void mp4_SampleRequested(Windows.Media.Core.MediaStreamSource sender, MediaStreamSourceSampleRequestedEventArgs args) 115 | { 116 | try 117 | { 118 | if (args.Request.StreamDescriptor is VideoStreamDescriptor) 119 | { 120 | _mp4Sampler.GetSample(args.Request); 121 | } 122 | } 123 | catch(Exception excp) 124 | { 125 | Debug.WriteLine("Exception mp4_SampleRequeste. " + excp.Message); 126 | } 127 | } 128 | 129 | void mss_Starting(Windows.Media.Core.MediaStreamSource sender, MediaStreamSourceStartingEventArgs args) 130 | { 131 | Debug.WriteLine("Starting."); 132 | 133 | _sampleMaker.Initialize(_mss, _videoDesc); 134 | 135 | args.Request.SetActualStartPosition(new TimeSpan(0)); 136 | } 137 | 138 | void mp4_Starting(Windows.Media.Core.MediaStreamSource sender, MediaStreamSourceStartingEventArgs args) 139 | { 140 | Debug.WriteLine("Starting."); 141 | 142 | //_sampleMaker.Initialize(_mss, _videoDesc); 143 | var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; 144 | _mp4Sampler.Initialise(folder.Path + @"\Assets\big_buck_bunny.mp4"); 145 | 146 | args.Request.SetActualStartPosition(new TimeSpan(0)); 147 | } 148 | 149 | private void _remoteVideo_MediaFailed(object sender, ExceptionRoutedEventArgs e) 150 | { 151 | Debug.WriteLine("Load media failed. " + e.ErrorMessage); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | WpfMedia 7 | aaron 8 | Assets\StoreLogo.png 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UwapWin10")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UwapWin10")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMedia/WpfMedia_TemporaryKey.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sipsorcery/mediafoundationsamples/74c2f7cfcca2dc585a44f78931cc6a2630c0e106/WpfMediaUWA/WpfMedia/WpfMedia_TemporaryKey.pfx -------------------------------------------------------------------------------- /WpfMediaUWA/WpfMediaUWA.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SampleMaker", "SampleMaker\SampleMaker.vcxproj", "{4C7EC778-0E55-43C9-A381-A7B952A1A802}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfMedia", "WpfMedia\WpfMedia.csproj", "{40028F1B-C6CE-4187-BE63-1912A34E5CEF}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|ARM = Debug|ARM 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|ARM = Release|ARM 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|ARM.Build.0 = Debug|ARM 22 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|ARM.Deploy.0 = Debug|ARM 23 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|x64.ActiveCfg = Debug|x64 24 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|x64.Build.0 = Debug|x64 25 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|x86.ActiveCfg = Debug|Win32 26 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Debug|x86.Build.0 = Debug|Win32 27 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|ARM.ActiveCfg = Release|ARM 28 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|ARM.Build.0 = Release|ARM 29 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|x64.ActiveCfg = Release|x64 30 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|x64.Build.0 = Release|x64 31 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|x86.ActiveCfg = Release|Win32 32 | {4C7EC778-0E55-43C9-A381-A7B952A1A802}.Release|x86.Build.0 = Release|Win32 33 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|ARM.ActiveCfg = Debug|ARM 34 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|ARM.Build.0 = Debug|ARM 35 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|ARM.Deploy.0 = Debug|ARM 36 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x64.ActiveCfg = Debug|x64 37 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x64.Build.0 = Debug|x64 38 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x64.Deploy.0 = Debug|x64 39 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x86.ActiveCfg = Debug|x86 40 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x86.Build.0 = Debug|x86 41 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Debug|x86.Deploy.0 = Debug|x86 42 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|ARM.ActiveCfg = Release|ARM 43 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|ARM.Build.0 = Release|ARM 44 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|ARM.Deploy.0 = Release|ARM 45 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x64.ActiveCfg = Release|x64 46 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x64.Build.0 = Release|x64 47 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x64.Deploy.0 = Release|x64 48 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x86.ActiveCfg = Release|x86 49 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x86.Build.0 = Release|x86 50 | {40028F1B-C6CE-4187-BE63-1912A34E5CEF}.Release|x86.Deploy.0 = Release|x86 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /wpfmediauwa/SampleMaker/Mp4Sampler.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include "Mp4Sampler.h" 3 | 4 | namespace SurfaceGenerator 5 | { 6 | Mp4Sampler::Mp4Sampler() 7 | { 8 | } 9 | 10 | void Mp4Sampler::Initialise(Platform::String^ path) 11 | { 12 | HRESULT hr = S_OK; 13 | IMFSourceResolver *pSourceResolver = nullptr; 14 | MF_OBJECT_TYPE objectType = MF_OBJECT_INVALID; 15 | IUnknown* uSource = nullptr; 16 | IMFMediaSource *mediaFileSource = nullptr; 17 | 18 | CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 19 | MFStartup(MF_VERSION); 20 | 21 | CHECK_HR(hr = MFCreateSourceResolver(&pSourceResolver), "MFCreateSourceResolver failed.\n"); 22 | 23 | OutputDebugStringW(L"Attempting to creafe MF source reader for "); 24 | OutputDebugStringW(path->Begin()); 25 | OutputDebugStringW(L"\n"); 26 | 27 | CHECK_HR(hr = pSourceResolver->CreateObjectFromURL( 28 | //L"E:\\Data\\LiveMesh\\Source\\mediafoundationsamples\\MediaFiles\\big_buck_bunny.mp4", // URL of the source. 29 | path->Begin(), 30 | //L"rtsp://10.1.1.2/slamtv60.264", 31 | MF_RESOLUTION_MEDIASOURCE, // Create a source object. 32 | NULL, // Optional property store. 33 | &objectType, // Receives the created object type. 34 | &uSource // Receives a pointer to the media source. 35 | ), "Failed to create media source resolver for file.\n"); 36 | 37 | CHECK_HR(uSource->QueryInterface(IID_PPV_ARGS(&mediaFileSource)), "Failed to create media file source.\n"); 38 | 39 | CHECK_HR(MFCreateSourceReaderFromMediaSource(mediaFileSource, NULL, &_videoReader), "Error creating media source reader.\n"); 40 | 41 | return; 42 | 43 | done: 44 | 45 | throw Platform::Exception::CreateException(hr, "Mp4Sample Initialise failed."); 46 | } 47 | 48 | void Mp4Sampler::GetSample(Windows::Media::Core::MediaStreamSourceSampleRequest ^ request) 49 | { 50 | Microsoft::WRL::ComPtr spRequest; 51 | HRESULT hr = S_OK; 52 | IMFSample *videoSample = NULL; 53 | DWORD streamIndex, flags; 54 | LONGLONG llTimeStamp; 55 | 56 | CHECK_HR(hr = reinterpret_cast(request)->QueryInterface(spRequest.ReleaseAndGetAddressOf()), "Failed to get MF interface for media sample request.\n"); 57 | 58 | while (true) 59 | { 60 | CHECK_HR(hr = _videoReader->ReadSample( 61 | MF_SOURCE_READER_FIRST_VIDEO_STREAM, 62 | 0, // Flags. 63 | &streamIndex, // Receives the actual stream index. 64 | &flags, // Receives status flags. 65 | &llTimeStamp, // Receives the time stamp. 66 | &videoSample // Receives the sample or NULL. 67 | ), "Error reading video sample."); 68 | 69 | if (flags & MF_SOURCE_READERF_ENDOFSTREAM) 70 | { 71 | OutputDebugStringW(L"End of stream.\n"); 72 | return; 73 | } 74 | if (flags & MF_SOURCE_READERF_STREAMTICK) 75 | { 76 | OutputDebugStringW(L"Stream tick.\n"); 77 | } 78 | 79 | if (!videoSample) 80 | { 81 | OutputDebugStringW(L"Null video sample.\n"); 82 | } 83 | else 84 | { 85 | OutputDebugStringW(L"Attempting to write sample to stream sink.\n"); 86 | 87 | CHECK_HR(hr = videoSample->SetSampleTime(llTimeStamp), "Error setting the video sample time.\n"); 88 | 89 | CHECK_HR(hr = spRequest->SetSample(videoSample), "Error setting sample on media sample request.\n"); 90 | 91 | return; 92 | } 93 | } 94 | 95 | done: 96 | 97 | throw Platform::Exception::CreateException(hr, "Mp4Sample GetSample failed."); 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /wpfmediauwa/SampleMaker/Mp4Sampler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace SurfaceGenerator 4 | { 5 | public ref class Mp4Sampler sealed 6 | { 7 | public: 8 | Mp4Sampler(); 9 | void Initialise(Platform::String^ path); 10 | void GetSample(Windows::Media::Core::MediaStreamSourceSampleRequest ^ request); 11 | 12 | private: 13 | IMFSourceReader * _videoReader = nullptr; 14 | }; 15 | } -------------------------------------------------------------------------------- /wpfmediauwa/SampleMaker/SampleMaker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace SurfaceGenerator 4 | { 5 | public ref class SampleMaker sealed 6 | { 7 | public: 8 | SampleMaker(); 9 | virtual ~SampleMaker(); 10 | void Initialize(Windows::Media::Core::MediaStreamSource ^ mss, Windows::Media::Core::VideoStreamDescriptor ^ videoDesc); 11 | void GenerateSample(Windows::Media::Core::MediaStreamSourceSampleRequest ^ request); 12 | 13 | private: 14 | HRESULT ConvertPropertiesToMediaType(_In_ Windows::Media::MediaProperties::IMediaEncodingProperties ^mep, _Outptr_ IMFMediaType **ppMT); 15 | static HRESULT AddAttribute(_In_ GUID guidKey, _In_ Windows::Foundation::IPropertyValue ^value, _In_ IMFAttributes *pAttr); 16 | HRESULT GenerateSampleFrame(UINT32 ui32Width, UINT32 ui32Height, int iFrameRotation, IMFMediaBuffer * pBuffer); 17 | 18 | Microsoft::WRL::ComPtr _spSampleAllocator; 19 | Microsoft::WRL::ComPtr _spDeviceManager; 20 | Microsoft::WRL::ComPtr _spD3DDevice; 21 | Microsoft::WRL::ComPtr _spD3DContext; 22 | HANDLE _hDevice; 23 | ULONGLONG _ulVideoTimestamp; 24 | int _iVideoFrameNumber; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /wpfmediauwa/SampleMaker/pch.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | -------------------------------------------------------------------------------- /wpfmediauwa/SampleMaker/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "MFUtility.h" 16 | 17 | --------------------------------------------------------------------------------