source: trunk/Utilities/Miscellaneous/MfHevcSinkWriter01/MfHevcSinkWriter01.cpp @ 937

Last change on this file since 937 was 865, checked in by roman, 4 years ago
  • Property svn:mime-type set to application/octet-stream
File size: 5.6 KB
Line 
1// MfHevcSinkWriter01.cpp : This file contains the 'main' function. Program execution begins and ends there.
2//
3
4#include "pch.h"
5#include <iostream>
6#include <windows.h>
7#include <wrl.h>
8#include <mfapi.h>
9#include <mfidl.h>
10#include <mfreadwrite.h>
11
12#pragma comment(lib, "mfplat.lib")
13#pragma comment(lib, "mfuuid.lib")
14#pragma comment(lib, "mfreadwrite.lib")
15
16using namespace Microsoft::WRL;
17
18inline HRESULT Check(HRESULT Value)
19{
20        if(FAILED(Value))
21                throw Value;
22        return Value;
23}
24
25int main()
26{
27        Check(CoInitialize(NULL));
28
29        Check(MFStartup(MF_VERSION));
30
31        ComPtr<IMFSinkWriter> SinkWriter;
32        Check(MFCreateSinkWriterFromURL(L"D:\\temp.mp4", nullptr, nullptr, SinkWriter.GetAddressOf()));
33
34        ComPtr<IMFMediaType> OutputMediaType;
35        Check(MFCreateMediaType(OutputMediaType.GetAddressOf()));
36        Check(OutputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
37        Check(OutputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_HEVC));
38        Check(MFSetAttributeSize(OutputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
39        //Check(OutputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
40        Check(MFSetAttributeRatio(OutputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1));
41        //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_PROFILE, eAVEncH265VProfile_Main_420_8));
42        //Check(OutputMediaType->SetUINT32(MF_MT_MPEG2_LEVEL, eAVEncH265VLevel1));
43        Check(OutputMediaType->SetUINT32(MF_MT_AVG_BITRATE, 1000000));
44
45        DWORD StreamIndex;
46        Check(SinkWriter->AddStream(OutputMediaType.Get(), &StreamIndex));
47
48        ComPtr<IMFMediaType> InputMediaType;
49        Check(MFCreateMediaType(InputMediaType.GetAddressOf()));
50        Check(InputMediaType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video));
51        Check(InputMediaType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12));
52        Check(MFSetAttributeSize(InputMediaType.Get(), MF_MT_FRAME_SIZE, 640, 480));
53        //Check(InputMediaType->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive));
54        Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_FRAME_RATE, 30, 1)),
55        //Check(MFSetAttributeRatio(InputMediaType.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)),
56
57        Check(SinkWriter->SetInputMediaType(StreamIndex, InputMediaType.Get(), nullptr));
58
59    std::cout << "Hello World!\n"; 
60}
61
62// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
63// Debug program: F5 or Debug > Start Debugging menu
64
65// Tips for Getting Started:
66//   1. Use the Solution Explorer window to add/manage files
67//   2. Use the Team Explorer window to connect to source control
68//   3. Use the Output window to see build output and other messages
69//   4. Use the Error List window to view errors
70//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
71//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Note: See TracBrowser for help on using the repository browser.