UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VideoEncoderInput.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "CoreMinimal.h"
7#include "CudaModule.h"
8#include "HAL/Platform.h"
10#include "Templates/Function.h"
13#include "VideoCommon.h"
14
15
16#if PLATFORM_DESKTOP && !PLATFORM_APPLE
17#include "vulkan/vulkan_core.h"
18#endif
19
20#if PLATFORM_WINDOWS
21struct ID3D11Device;
22struct ID3D11Texture2D;
23struct ID3D12Device;
24struct ID3D12Resource;
25#endif
26
27
28namespace amf {
29 struct AMFVulkanSurface;
30}
31
32namespace AVEncoder
33{
34 class FVideoEncoderInputFrame;
35
36#if PLATFORM_DESKTOP && !PLATFORM_APPLE
37 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FVulkanDataStruct
38 {
42 };
43#endif
44
45 class UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FVideoEncoderInput
46 {
47 public:
48 // --- construct video encoder input based on expected input frame format
51
52 // create input for an encoder that encodes a D3D11 texture
53 static AVENCODER_API TSharedPtr<FVideoEncoderInput> CreateForD3D11(void* InApplicationD3D11Device, bool IsResizable = false, bool IsShared = false);
54
55 // create input for an encoder that encodes a D3D12 texture
56 static AVENCODER_API TSharedPtr<FVideoEncoderInput> CreateForD3D12(void* InApplicationD3D12Device, bool IsResizable = false, bool IsShared = false);
57
58 // create input for an encoder that encodes a CUarray
60
61 // create input for an encoder that encodes a VkImage
63
64 // --- properties
66
70
71 // --- available encoders
72
73 // get a list of supported video encoders
75 virtual const TArray<FVideoEncoderInfo>& GetAvailableEncoders() = 0;
77
78 // --- create encoders
79
80 // --- encoder input frames - user managed
81
82 // new packet callback prototype void(uint32 LayerIndex, const FCodecPacket& Packet)
83 using OnFrameReleasedCallback = TFunction<void(const FVideoEncoderInputFrame* /* InReleasedFrame */)>;
84
85 // create a user managed buffer
86 virtual FVideoEncoderInputFrame* CreateBuffer(OnFrameReleasedCallback InOnFrameReleased) = 0;
87
88 // destroy user managed buffer
89 virtual void DestroyBuffer(FVideoEncoderInputFrame* Buffer) = 0;
90
91 // --- encoder input frames - managed by this object
92
93 // obtain a video frame that can be used as a buffer for input to a video encoder
94 virtual TSharedPtr<FVideoEncoderInputFrame> ObtainInputFrame() = 0;
95
96 // release (free) an input frame and make it available for future use
97 virtual void ReleaseInputFrame(FVideoEncoderInputFrame* InFrame) = 0;
98
99 // destroy/release any frames that are not currently in use
100 virtual void Flush() = 0;
101
102 #if PLATFORM_WINDOWS
105 #endif
106
107 virtual CUcontext GetCUDAEncoderContext() const = 0;
108
109 #if PLATFORM_DESKTOP && !PLATFORM_APPLE
110 virtual void* GetVulkanEncoderDevice() const = 0;
111 #endif
112
113 protected:
114 FVideoEncoderInput() = default;
115 virtual ~FVideoEncoderInput() = default;
116 FVideoEncoderInput(const FVideoEncoderInput&) = delete;
117 FVideoEncoderInput& operator=(const FVideoEncoderInput&) = delete;
118
120 EVideoFrameFormat FrameFormat = EVideoFrameFormat::Undefined;
122
124 uint32 NumBuffers = 0;
125
126 bool bIsResizable = false;
127
129 };
130
131
132 // TODO this should go elsewhere and be made cross platform
133 class UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FVideoEncoderInputFrame
134 {
135 public:
136 // Obtain (increase reference count) of this input frame
137 const FVideoEncoderInputFrame* Obtain() const { NumReferences.Increment(); return this; }
138 // Release (decrease reference count) of this input frame
139 virtual void Release() const = 0;
140
141 // the callback type used to create a registered encoder
142 using FCloneDestroyedCallback = TFunction<void(const FVideoEncoderInputFrame* /* InCloneAboutToBeDestroyed */)>;
143
144 // Clone frame - this will create a copy that references the original until destroyed
145 virtual const FVideoEncoderInputFrame* Clone(FCloneDestroyedCallback InCloneDestroyedCallback) const = 0;
146
147 void SetFrameID(uint32 id) { FrameID = id; }
148 uint32 GetFrameID() const { return FrameID; }
149
151 int64 GetTimestampUs() const { return TimestampUs; }
152
154 int64 GetTimestampRTP() const { return TimestampRTP; }
155
156 // current format of frame
158 EVideoFrameFormat GetFormat() const { return Format; }
160 // width of frame buffer
161 void SetWidth(uint32 InWidth) { Width = InWidth; }
162 uint32 GetWidth() const { return Width; }
163 // height of frame buffer
164 void SetHeight(uint32 InHeight) { Height = InHeight; }
165 uint32 GetHeight() const { return Height; }
166
168
169 // --- YUV420P
170
171 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FYUV420P
172 {
173 const uint8* Data[3] = { nullptr, nullptr, nullptr };
174 uint32 StrideY = 0;
175 uint32 StrideU = 0;
176 uint32 StrideV = 0;
177 };
178
180 const FYUV420P& GetYUV420P() const
181 {
182 return YUV420P;
183 }
184
185 FYUV420P& GetYUV420P() { return YUV420P; }
186
188
189#if PLATFORM_WINDOWS
190 // --- D3D11
191
192 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FD3D11
193 {
194 ID3D11Texture2D* Texture = nullptr;
195 ID3D11Device* EncoderDevice = nullptr;
197 void* SharedHandle = nullptr;
198 };
199
200 const FD3D11& GetD3D11() const { return D3D11; }
201 FD3D11& GetD3D11() { return D3D11; }
202
203 // the callback type used to create a registered encoder
205
207
208 // --- D3D12
209
210 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FD3D12
211 {
212 ID3D12Resource* Texture = nullptr;
213 ID3D12Device* EncoderDevice = nullptr;
215 };
216
217 const FD3D12& GetD3D12() const { return D3D12; }
218 FD3D12& GetD3D12() { return D3D12; }
219
220 // the callback type used to create a registered encoder
222
224
225#endif // PLATFORM_WINDOWS
226
227 enum class UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") EUnderlyingRHI
228 {
229 Undefined,
230 D3D11,
231 D3D12,
232 Vulkan
233 };
234
235 // --- CUDA
236 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FCUDA
237 {
238 CUarray EncoderTexture = nullptr;
239 CUcontext EncoderDevice = nullptr;
240 void* SharedHandle = nullptr;
241
243 EUnderlyingRHI UnderlyingRHI = EUnderlyingRHI::Undefined;
245 };
246
247 const FCUDA& GetCUDA() const { return CUDA; }
248 FCUDA& GetCUDA() { return CUDA; }
249
250 // the callback type used to create a registered encoder
252
254
255#if PLATFORM_DESKTOP && !PLATFORM_APPLE
256 // --- Vulkan
257 struct UE_DEPRECATED(5.4, "AVEncoder has been deprecated. Please use the AVCodecs plugin family instead.") FVulkan
258 {
263 mutable void* EncoderSurface = nullptr;
264 };
265
266 const FVulkan& GetVulkan() const { return Vulkan; }
267 FVulkan& GetVulkan() { return Vulkan; }
268
269 // the callback type used to create a registered encoder
273
276#endif
277
279 protected:
280 AVENCODER_API FVideoEncoderInputFrame();
281 AVENCODER_API explicit FVideoEncoderInputFrame(const FVideoEncoderInputFrame& CloneFrom);
282
283
287 mutable FThreadSafeCounter NumReferences;
288 uint32 Width;
289 uint32 Height;
291 bool bFreeYUV420PData;
292
296
297#if PLATFORM_WINDOWS
302#endif
303
304 FCUDA CUDA;
306
307#if PLATFORM_DESKTOP && !PLATFORM_APPLE
310#endif
311 };
312
313
314} /* namespace AVEncoder */
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition CUDA.Build.cs:9
Definition ThreadSafeCounter.h:14
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition RefCounting.h:454
Definition SharedPointer.h:692
Definition AudioEncoder.cpp:7
GeometryCollection::Facades::FMuscleActivationData Data
Definition MuscleActivationConstraints.h:15
const int32 NumBuffers
Definition ISlateRHIRendererModule.h:15
VkBuffer CreateBuffer(FVulkanDevice *InDevice, VkDeviceSize Size, VkBufferUsageFlags BufferUsageFlags, VkMemoryRequirements &OutMemoryRequirements)
Definition VulkanUtil.cpp:725
Definition VideoEncoderInput.h:28