forked from multitheftauto/mtasa-blue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCVideoEncoder.h
More file actions
79 lines (69 loc) · 2.53 KB
/
Copy pathCVideoEncoder.h
File metadata and controls
79 lines (69 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: Client/core/Graphics/CVideoEncoder.h
*
* Multi Theft Auto is available from https://multitheftauto.com/
*
*****************************************************************************/
#pragma once
#include <string>
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <d3d11.h>
///////////////////////////////////////////////////////////////////////////////
//
// CVideoEncoder
//
// Encodes frames to H.264 video using Windows Media Foundation
// GPU-accelerated encoding with D3D11 texture input
//
///////////////////////////////////////////////////////////////////////////////
class CVideoEncoder
{
public:
CVideoEncoder();
~CVideoEncoder();
/// Start video recording session
/// @param path Output MP4 file path
/// @param width Frame width
/// @param height Frame height
/// @param fps Frames per second
/// @param bitrate Video bitrate in bps
/// @return Success
bool Start(const std::string& path, int width, int height, int fps, int bitrate);
/// Add frame from GPU texture
/// @param gpuTexture D3D11 texture containing frame data
/// @return Success
bool AddFrame(ID3D11Texture2D* gpuTexture);
/// Stop recording and finalize MP4 file
/// @return Success
bool Stop();
/// Check if encoder is active
bool IsInitialized() const { return m_bInitialized; }
private:
IMFSinkWriter* m_pSinkWriter;
DWORD m_dwStreamIndex;
LONGLONG m_iFrameCount;
int m_iFPS;
int m_iWidth;
int m_iHeight;
int m_iBitrate;
bool m_bInitialized;
// Cached staging resources reused across AddFrame() calls.
// Invalidated if source texture dimensions/format change.
ID3D11Device* m_pCachedDevice;
ID3D11DeviceContext* m_pCachedContext;
ID3D11Texture2D* m_pCachedStagingTexture;
UINT m_uCachedStagingWidth;
UINT m_uCachedStagingHeight;
DXGI_FORMAT m_CachedStagingFormat;
bool InitializeMediaFoundation();
bool CreateSinkWriter(const std::string& path);
bool ConfigureVideoStream();
IMFSample* CreateSampleFromTexture(ID3D11Texture2D* texture);
bool EnsureStagingResources(ID3D11Device* pDevice, const D3D11_TEXTURE2D_DESC& srcDesc);
void ReleaseCachedResources();
};