Skip to Content
Internet Protocol
Unreal Engine Plugin

RTMP Publisher

Stream Unreal Engine 5.8 to Twitch, YouTube, MediaMTX or nginx-rtmp over RTMP/RTMPS: viewport, render target or scene capture with GPU H.264 and AAC audio.

The RTMP publisher streams video and audio from Unreal to any RTMP/RTMPS server: Twitch, YouTube, MediaMTX, nginx-rtmp, or another Unreal running an RTMP Server. It captures the viewport, a render target or a scene capture, encodes H.264 on the GPU and AAC audio, and reconnects on its own. See the RTMP overview for complete flows.

Unreal Engine 5.8 and DirectX 12 only

RTMP is supported only on Unreal Engine 5.8, Win64, with the DirectX 12 RHI. Set Project Settings > Platforms > Windows > Default RHI to DirectX 12. On DirectX 11 or Vulkan the GPU encoder refuses to start, and publishing fails with an error.

GPU

  • It needs an NVIDIA (NVENC) or AMD (AMF) GPU: there is no software H.264 encoder. Without one of these GPUs, Start reports a clear error through On Error.

References

#include "IPRtmpPublisher.h"

How to use

Blueprint: add a Construct Object from Class node, set Class to IPRtmp Publisher and Outer to self, and store the result in a variable.

Construct IPRtmp Publisher
Class
Outer
Return Value
Function

Fill an IP Rtmp Publish Config struct (Make struct) and call Start with the server URL and the stream key.

C++: Use the code bellow

#include "IPRtmpPublisher.h"

FIPRtmpPublishConfig Config;
Config.VideoSource = EIPPublishVideoSource::Viewport;   // or RenderTarget / SceneCapture
Config.Width = 1280; Config.Height = 720; Config.FrameRate = 30;
Config.VideoBitrateKbps = 4500; Config.KeyframeIntervalSeconds = 2;
Config.AudioSource = EIPPublishAudioSource::Submix;     // main submix, or Manual / None

UIPRtmpPublisher* Publisher = NewObject<UIPRtmpPublisher>(this);
Publisher->Start(TEXT("rtmp://live.twitch.tv/app"), StreamKey, Config);

Keep a reference

Store the publisher in a variable (Blueprint) or a UPROPERTY (C++). An object that nothing references is destroyed by the garbage collector, and the stream stops.

How it works

  • Video: H.264 encoded by the GPU through the engine's AVCodecs: NVENC first, then AMF. There is no CPU readback. Frames are captured at the configured rate, up to the game frame rate.
  • Audio: AAC-LC at 48 kHz stereo, encoded by Media Foundation.
  • Network: rtmp:// and rtmps://, with a bounded send queue. Under congestion P-frames are dropped first. Reconnection uses exponential backoff from 1 to 30 s, and a keyframe is forced after each reconnection.
  • The stream key is never logged: URLs are logged as rtmp://host/app/***, and On Error messages never contain it.

Nodes

Start

  • Starts publishing to Url: rtmp://host[:port]/app or rtmps://host[:port]/app.
  • Stream Key is appended as the stream name. Leave it empty if the URL already ends with it.
  • Returns false, and triggers On Error, on invalid input: bad URL, Render Target source without a render target, Scene Capture source without a scene capture, no supported GPU encoder...
  • Width and Height are rounded down to even values (minimum 16), and Frame Rate is clamped to 1-120.
  • If the Submix audio source has no audio device (audio disabled), it publishes video only and reports it through On Error.
StartTarget is IPRtmp Publisher
Target
Url
Stream Key
In Config
Return Value
Function

Stop

  • Graceful stop: the stream is unpublished, nothing reconnects afterwards and the state goes back to Idle.
StopTarget is IPRtmp Publisher
Target
Function

Get State

Get State
Return Value
Pure function

Is Publishing

  • Return true while the server accepts the stream (state Publishing).
Is Publishing
Return Value
Pure function

Get Stats

Get Stats
Return Value
Pure function

Push Audio Samples

  • Audio for the Manual audio source (microphone, generated audio...): interleaved float samples between -1 and 1, any channel count and sample rate. They are converted to 48 kHz stereo.
  • From C++, PushAudio(const float* Interleaved, int32 NumFrames, int32 NumChannels, int32 SampleRate) does the same and can be called from any thread.
Push Audio SamplesTarget is IPRtmp Publisher
Target
Interleaved
Num Channels
Sample Rate
Function

Events

On State Changed

Bind Event to On State Changed
Target
Event
On State ChangedCustom Event
State
Event binding

On Publishing

  • The server accepted the stream. Also triggered after each successful reconnection.
Bind Event to On Publishing
Target
Event
On PublishingCustom Event
Event binding

On Reconnecting

  • The connection dropped and the publisher is retrying. Attempt counts the retries.
Bind Event to On Reconnecting
Target
Event
On ReconnectingCustom Event
Attempt
Event binding

On Error

  • An error happened. The message never contains the stream key.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Message
Event binding

Structs and enums

Publish Config

FIPRtmpPublishConfig, passed to Start.

FieldTypeDefaultDescription
Video SourceEIPPublishVideoSourceViewportWhat is encoded as video.
Render TargetTexture Render Target 2DnoneUsed when Video Source is Render Target.
Scene CaptureScene Capture Component 2DnoneUsed when Video Source is Scene Capture. If it has no Texture Target, one of the output size is created.
Width, HeightInteger1280 × 720Output size; the source is scaled. Even values, minimum 16.
Frame RateInteger30Capture rate (1-120). Frames are skipped when the game runs faster; it cannot exceed the game frame rate.
Video Bitrate KbpsInteger4500Constant bitrate (minimum 100).
Keyframe Interval SecondsInteger21-10. Twitch and YouTube require 2 s.
Audio SourceEIPPublishAudioSourceSubmixWhere the audio comes from.
SubmixSound SubmixnoneSubmix to capture. Empty uses the main submix.
Audio Bitrate KbpsInteger160AAC-LC 48 kHz stereo: 96, 128, 160 or 192.
ReconnectBooleantrueReconnect with exponential backoff (1 to 30 s) when the connection drops.
Max Reconnect AttemptsInteger00 retries forever.

Video Source

EIPPublishVideoSource

ValueDescription
ViewportThe game viewport's back buffer: what the player sees, UI included.
Render TargetA render target you draw into (materials, UMG widget renderer, canvas...).
Scene CaptureA scene capture component (another camera), captured at the publish frame rate.

Audio Source

EIPPublishAudioSource

ValueDescription
NoneNo audio track.
SubmixThe engine's audio output: the main submix, or the one set in Submix.
ManualSamples pushed with Push Audio Samples.

Publisher State

EIPRtmpPublisherState

ValueDescription
IdleNot publishing.
ConnectingConnecting to the server.
PublishingThe server accepted the stream.
ReconnectingConnection lost: retrying with exponential backoff.
ErrorStopped because of an error (see On Error).

Publisher Stats

FIPRtmpPublisherStats, returned by Get Stats.

FieldTypeDescription
StateEIPRtmpPublisherStateCurrent state.
FpsFloatEncoded video frames per second.
Sent KbpsFloatBytes actually written to the network, in kbit/s.
Dropped Video FramesInteger64Video frames not encoded (encoder busy) or not sent (network congestion).
Dropped Audio FramesInteger64Audio frames lost (capture overrun or network congestion).
Queued BytesInteger64Bytes waiting in the send queue.
Rtt MsFloatRound-trip time to the server in ms (-1 when unknown).
Reconnect AttemptsIntegerReconnections so far.
Video Encoder, Audio EncoderStringName of the encoders in use.
Edit on GitHub

On this page