Encoder Architecture
The LCK SDK uses a platform-abstracted encoder interface with hardware-accelerated implementations.
┌─────────────────────────────────────────┐
│ ILCKEncoder │
│ (Abstract Interface) │
└────────────────┬────────────────────────┘
│
┌────────────┴────────────┐
│ │
┌───▼───────────────┐ ┌────▼──────────────┐
│ FLCKWindowsEncoder│ │ FLCKAndroidEncoder│
│ (MediaFoundation) │ │ (MediaCodec) │
└───────────────────┘ └───────────────────┘
ILCKEncoder Interface
class LCKCORE_API ILCKEncoder
{
public:
virtual ~ILCKEncoder() = default;
// Initialization
virtual bool Initialize(int32 Width, int32 Height, int32 Framerate,
int32 VideoBitrate, int32 AudioBitrate, int32 Samplerate) = 0;
virtual void Shutdown() = 0;
// Encoding
virtual void EncodeTexture(UTextureRenderTarget2D* Texture, float TimeSeconds) = 0;
virtual void EncodeAudio(TArrayView<const float> PCMData) = 0;
// State
virtual bool IsEncoding() const = 0;
virtual bool StartEncoding() = 0;
virtual bool StopEncoding() = 0;
// Output
virtual FString GetOutputPath() const = 0;
};
ILCKEncoderFactory
Factory interface for creating platform-specific encoders.
class ILCKEncoderFactory : public IModularFeature
{
public:
static FName GetModularFeatureName();
virtual TSharedPtr<ILCKEncoder> CreateEncoder() = 0;
virtual FString GetFactoryName() const = 0;
virtual int32 GetPriority() const = 0;
};
Encoder Selection
Encoders register via Unreal’s modular feature system. The system selects the highest priority available encoder:
// Get available encoder factories
TArray<ILCKEncoderFactory*> Factories;
IModularFeatures::Get().GetModularFeatureImplementations<ILCKEncoderFactory>(
ILCKEncoderFactory::GetModularFeatureName(),
Factories
);
// Sort by priority (highest first)
Factories.Sort([](const ILCKEncoderFactory& A, const ILCKEncoderFactory& B) {
return A.GetPriority() > B.GetPriority();
});
// Create encoder from highest priority factory
TSharedPtr<ILCKEncoder> Encoder = Factories[0]->CreateEncoder();
FLCKWindowsEncoder
Uses Windows Media Foundation for hardware-accelerated H.264 encoding.Features:
- Hardware acceleration via GPU
- H.264 Baseline to High profile
- AAC-LC audio encoding
- Direct GPU texture access
Requirements:
- Windows 10 or later
- DirectX 11 compatible GPU
- Media Foundation runtime
// Windows encoder automatically selected on Windows platform
// No additional configuration needed
Supported GPUs:
- NVIDIA GeForce GTX 600+
- AMD Radeon HD 7000+
- Intel HD Graphics 4000+
FLCKAndroidEncoder
Uses Android MediaCodec for hardware-accelerated encoding.Features:
- Hardware acceleration via SoC
- H.264 encoding
- AAC audio encoding
- Vulkan texture interop
Requirements:
- Android 8.0+ (API 26+)
- Vulkan support recommended
- Hardware codec support
// Android encoder automatically selected on Android platform
// Ensure Vulkan is enabled for best performance
Tested Devices:
- Meta Quest 2, Quest 3, Quest Pro
- Samsung Galaxy S10+
- Pixel 4+
Encoding Pipeline
Frame Capture
Scene capture component renders to render target texture
Texture Transfer
GPU texture data transferred to encoder (zero-copy when possible)
Video Encoding
Hardware encoder compresses frame to H.264
Audio Mixing
FLCKAudioMix combines audio sources
Audio Encoding
PCM audio encoded to AAC
Muxing
Video and audio streams combined into MP4 container
Frame Timing
// Encoder expects consistent frame timing
// Match capture rate to recording framerate
CaptureComponent->bCaptureEveryFrame = false;
// The subsystem handles frame timing internally
// based on configured framerate
Memory Usage
| Resolution | Approx. Memory |
|---|
| 720p | ~50 MB |
| 1080p | ~100 MB |
| 1440p | ~150 MB |
| 2160p | ~250 MB |
High resolutions increase memory pressure significantly. Monitor memory usage on mobile VR devices.
Thread Safety
EncodeTexture() must be called from game thread
EncodeAudio() is safe from any thread
- Internal encoding runs on dedicated worker threads
Error Handling
// Check encoder state before operations
if (!Encoder->IsEncoding())
{
if (!Encoder->StartEncoding())
{
UE_LOG(LogLCKEncoding, Error, TEXT("Failed to start encoder"));
// Handle initialization failure
}
}
// Monitor for encoding errors via logs
// LogLCKEncoding category reports encoder issues
| Property | Value |
|---|
| Container | MP4 (fragmented) |
| Video Codec | H.264 / AVC |
| Video Profile | Main (default) |
| Audio Codec | AAC-LC |
| Audio Channels | Stereo (2) |
Output files are saved to the platform’s standard video/gallery location on Android, or to the project’s Saved folder on desktop.