The AVEncoder module provides a simple API to encode Video Audio. 更多...
类 | |
| class | FAudioEncoder |
| Similar functionality to FVideoEncoder 更多... | |
| struct | FAudioEncoderConfig |
| Audio encoder initial configuration 更多... | |
| class | FAudioEncoderFactory |
| Allows querying existing audio encoders. 更多... | |
| struct | FAVPacket |
| Encoded output. 更多... | |
| struct | FEncoderVideoFrameCookie |
| When sending a frame to the video encoder, it is possible to specify a cookie that will be passed back to the user code in the encoder callback. 更多... | |
| class | FVideoEncoder |
| Base class for video encoders. 更多... | |
| struct | FVideoEncoderConfig |
| Video encoder initial configuration. 更多... | |
| class | FVideoEncoderFactory |
| Allows querying existing video encoders. 更多... | |
| class | IAudioEncoderListener |
| Interface that should be implemented to react to audio encoder's events 更多... | |
| class | IVideoEncoderListener |
| Interface that should be implemented to react to video encoder's events 更多... | |
类型定义 | |
| using | FBufferId = uint32 |
| Identifies the internal buffer being used by the video encoder. | |
The AVEncoder module provides a simple API to encode Video Audio.
Initially, it was created to remove the duplicated encoding code done for Pixel Streaming and gameplay recording (GameplayMediaEncoder module), so at the moment it only supports what those systems require (h264 for video, and aac for audio)
Both audio and video encoders are exposed through factories, and the existing framework allows registering user made encoders.
The following is a simplified example, capturing gameplay video, ignoring errors for simplicity. For a full example on how to capture gameplay video and audio look at the GameplayMediaEncoder module.
class FFoo : private AVEncoder::IVideoEncoderListener { TUniquePtr<AVEncoder::FVideoEncoder> VideoEncoder; FTimespan StartTime = 0; FTimespan LastVideoFrameTimestamp = 0; FFoo() { } bool Initialize() { // Find a h264 video encoder (returns nullptr) AVEncoder::FVideoEncoderFactory* VideoEncoderFactory = AVEncoder::FVideoEncoderFactory::FindFactory("h264"); if (!VideoEncoderFactory) return false; // Create encoder VideoEncoder = VideoEncoderFactory->CreateEncoder("h264"); if (!VideoEncoder) return false; // Desired settings AVEncoder::FVideoEncoderConfig Config; Config.Width = 1920; Config.Height = 1080; Config.Framerate = 60; Config.Bitrate = 4000000; // 4mbps if (!VideoEncoder->Initialize(Config)) return false; // Register ourselves to receive the encoded frames VideoEncoder->RegisterListener(this); // Register back buffer capture with UE4 FSlateApplication::Get().GetRenderer()->OnBackBufferReadyToPresent().AddRaw(this, &FGameplayMediaEncoder::OnBackBufferReady); StartTime = FTimespan::FromSeconds(FPlatformTime::Seconds()); return true; } // Back buffer capture callback from UE4 void OnBackBufferReady(SWindow& SlateWindow, const FTexture2DRHIRef& BackBuffer) { FTimespan Now = FTimespan::FromSeconds(FPlatformTime::Seconds()) - StartTime; AVEncoder::FBufferId BufferId; // Initialize copy of the backbuffer to the encoder. if (!VideoEncoder->CopyTexture(BackBuffer, Now, Now - LastVideoFameTimestamp, BufferId)) return; // Encode the frame VideoEncoder->Encode(BufferId, false); LastVideoInputTimestamp = Now; } // AVEncoder::IVideoEncoderListener interface void OnEncodedVideoFrame(const AVEncoder::FAVPacket& Packet, AVEncoder::FEncoderVideoFrameCookie* Cookie) override { // Encoded frame is in `Packet` } };