RTMP Target
  • 19 Mar 2024
  • 8 Minutes to read
  • Dark
    Light
  • PDF

RTMP Target

  • Dark
    Light
  • PDF

Article Summary

The RTMP target is a generic RTMP Encoder that supports CPU-based encoding (X264) and GPU-based encoding (NVENC). For audio encoding, the RTMP Target supports the AAC encoder.

The component is based on the libraries from the FFmpeg application family and the NVENC library from NVidia.

Using the NVENC encoder (GPU) requires an NVENC-compatible GPU such as the RTXA4000, P2200, P4000, or the T40. Most NVidia GPU:s support NVENC, but the capabilities differ. This matrix can be helpful when determining your GPU features:
https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new

Using the NVENC option is an excellent way of offloading load from the CPU. NVENC does not affect the GPU either, as it is managed by a separate and dedicated chipset. When using multiple instances of the RTMP Target, you can mix between X264 (CPU) and NVENC (GPU).

  • Autostart when the application starts - check this option to enable target at application launch. For autostart of targets, the Autostart target options also must be activated on the application level (See the chapter Runtime Performance)

  • Primary RTMP server address - the primary RTMP(S) server address. The primary address is the first choice of ingesting URL used by the RTMP target.
    It is possible to generate a random stream name by using a macro: @@RandomId() or @@HostName()
     The generated URL will be displayed in the log, and the field “Current rtmp endpoint”
     Example: rtmp://yourrtmpserveraddress/@@RandomId()
     Example: rtmp://yourrtmpserveraddress/@@HostName()

  • Backup RTMP server address - an optional back RTMP server address. If a backup server is provided, Composer will alternate between the primary and the backup server when there is a connection issue.

  • Player URL - (Optional) Playout URL of your stream. Click the "Open Player" button to launch your player in a browser. (Purpose is to have quick access to monitor your playout stream)

  • Reconnect interval - if the RTMP connection terminates/fails, the RTMP Target will reconnect automatically. The reconnect interval determines how long the component will wait until it tries to reconnect.

  • Video bitrate - outgoing video bitrate.

  • Warn on low average bitrate (<10%) - if the average outgoing bitrate is less than 10% of the defined bitrate in “Video bitrate”, a warning will be logged.

  • Audio bitrate - outgoing audio bitrate.

  • H264 B frame distance - the number of b-frames used in a GOP

  • H264 Gop size - GOP (Group of pictures) length in frames. Typically this is 2x or 1x the framerate. The available options are:

  • H264 profile - H264 profile. The available options are:

     If you are using Vindral CDN and your Vindral Transcoder is set to PASS-THROUGH, you must select the baseline profile to provide support for playback on iOS devices (Web SDK).

  • Debug

    • Log bitrate to disk - this option is used for analyzing encoded frame sizes. It´s a feature sometimes which can be helpful when studying encoding performance. If activated, Composer will create a .CSV file in the root of the application folder. The .CSV file will have a name based on the GUID of the RTMP Target + date/time. Example: 9da53b93-03ce-41cf-b552-7296c93b555a-2021-07-15T16.54.29.csv
       The .CSV files can be opened in Excel or similar spreadsheet applications.
       Content of the .CSV file:

  • CBR configuration
    To create a CBR-stream (Constant Bitrate) suitable for live streaming and CDN providers that support adaptive bitrate (ABR), you typically want to create an RTMP output with a stable bitrate. Smaller fluctuation in the bitrate is often ok, but you typically don't want the bitrate to vary too much. This concept is called CBR. For example, depending on the content, a 2Mbit/s stream running a CBR configuration might vary between 1.5 and 2.0Mbit/s.

    • Use CBR configuration - activates the max and min video-rate multipliers and buffer size

      • Max video rate (multiplier) - Sets the max video bitrate. The value is a multiplier, typically between 1.0 and 3.0. The maximum video bitrate will be set to multiplier*video bitrate. Example: 1.1*2.4Mbit/s=2.64Mbit/s

      • Min video rate (multiplier) - Sets the min video bitrate. Same concept as for the Max video rate. The value is a multiplier, typically between 0.5 and 1.0.

      • Buffer size (multiplier) - buffer length used by the encoder to maintain max- and min bitrates. Typically this multiplier is set to a value between 0.5 and 3.0. If a low value is specified, the encoder will frequently check for the output bit rate and constrain it to the specified video (average) bit rate. Hence, lowering the buffer lengths reduces the bitrate variation that the encoder can produce. Specifying too small a buffer size would cause the encoder to degrade the output image quality because it would have to (frequently) conform to the limitations and would not have enough free space to use some optimizations (for example, optimizations based on the frame repetitions and similar), because the buffer would not contain enough frames for the optimizations to be effective. 

  • X264 encoder configuration

    • H264 quality speed control- controls the encoding speed (versus quality). For ultra low latency setups, very fast or superfast options are common. The alternatives are:

      • ultrafast, superfast, very fast, faster, fast, medium, slow, slower, very slow, placebo

    • H264 tune- encoder tuning. Select zero latency for live streaming. The alternatives are:

      • film, animation, grain, still image, psnr, ssim, fast decode, zero latency

    • H264 threads- number of CPU threads used for encoding. The ideal setting depends on your CPU and needs to be tested. The alternatives are:

      • Zero (auto), One, Two, Three, Four, Five, Six, Seven, Eight

  • NVENC (GPU)


    NOTE!

    Since version R1 2023 (1.5.x) Composer uses FFmpeg 5.x for encoding. Previous versions of Composer used FFmpeg 4.x. The upgrade of FFmpeg means some NVENC configuration parameters have been changed or work slightly differently. This change was initialized by FFmpeg and NVidia, and Composer is affected by those changes.

    If you are upgrading from Composer 1.x to 1.5.x, you might need to review your NVENC configuration.

    • Use NVENC as a video encoder - option to use NVENC (GPU) for encoding. By using NVENC, the CPU is offloaded. Note: the following options are not applicable for NVENC: H264 Quality Speed Control, H264 Tune, and H264 Threads.
      Note: the number of NVENC-encoders you can run in parallel depends on your GPU model.

    • Advanced options (JSON) - This configuration is rarely changed. However, there might be use cases where tweaking the low-level parameters of NVENC is needed.

       The default value is {"no - scenecut": "1","zerolatency": "1","strict_gop": "1","gpu": "any","preset": "p4","rc": "cbr","delay": "0","rc-lookahead": "0","surfaces": "1"}

      CBR with NVENC
      In Composer there are two important configurations related to CBR. The first one is the CBR Configuration (see more info earlier in this chapter).
      Activate CBR configuration to set max video rate multiplier, min video multiplier, and buffer size. In many cases, the value 1.0 is a good starting point. However, depending on the content, you might wanna adjust these parameters. Unfortunately, there is no single configuration that works for all use cases.

      The second part is related to the NVENC configuration parameters. Activate NVENC and adjust the Advanced options:
      The parameter that matters for CBR is the rate control parameter ("rc"). Set this to "cbr" (default from Composer version 1.5.x.

  • Commands

    • Start sending - starts the encoder and the RTMP stream

    • Disconnect - stops the encoder and the RTMP stream

    • Reconnect - Reconnects the RTMP stream. If both a Primary and Backup RTMP server address is specified, it will alternate between the primary and the backup server address

    • Current connection status

  • Performance and properties

    • Outgoing bitrate - current outgoing bitrate

    • Video frames written - the total number of written (sent) video frames (Same fps as project framerate)

    • Audio frames written - the total number of written (sent) audio frames (48000/1024 = 47.5 fps)

    • Video PTS - latest video timestamp

    • Audio PTS - latest audio timestamp

    • PTS Diff - the difference between the latest Video PTS and Audio PTS

    • Rtmp message - the latest message (info, warn, error)

    • Rtmp message time - Date and time for last Rtmp message

    • Number of reconnects - the total number of RTMP reconnects since the start

    • Output queue size - number of frames

    • Video encode time (ms) - The encoding time for the last video frame

    • Video encode time max (ms) - Max encoding time for a video frame (since started)

    • Network write time (ms) - The time it took to write the last frame to the network stack

    • Last video frame size (bytes) - The last video frame size (in bytes)

    • Avg video frame size (bytes) - The average video frame size (in bytes) since the start

    • Max video frame size (bytes) - The maximum video frame size (in bytes) since the start

    • Min video frame size (bytes) - The minimum video frame size in (in bytes) since the start

    • Last audio frame size (bytes) - The last audio frame size (in bytes)

    • Max video bitrate (Mbits/s) - The maximum bitrate measured over one second

    • Min video bitrate (Mbit/s) - The minimum bitrate measured over one second

    • Avg video bitrate (Mbit/s) - The average bitrate measured over the whole session

    • Uptime since the start - Time since the RTMP-target was started.

    • Current RTMP endpoint - The current RTMP server address used (Primary or Backup server address)

    • Error counter - The number of errors since the RTMP-target was started

    • Last Error DateTime

    • Warning counter - The number of warnings since the RTMP-target was started 

    • Last Warning DateTime

  • VideoPixelFormat - internal videoformat 

Logging

If Use extended logging (under “Performance”) is enabled, statistics about the RTMP target are logged.

Example:
[2023-09-12 11:53:12.239 [Information] [2055] [SystemLabel] TargetStatistics {"GetStatistics": "", "Name": "RTMP Target", "ConnectionStatus": "Connected", "UpTimeSinceStartTimeSpan": "00:00:18.9664998", "CurrentRTMPEndPoint": "rtmp://myrtmpingesturl.com/live/mystream", "OutgoingBitRateMbitPerSecond": "1.118671", "NumAutoReconnectsperformed": "0", "AverageVideoEncoderTimeMs": "6.6467999999986205", "MaxVideoEncoderTimeMS": "19.94959999999992", "AverageNetworkWriteTimeMs": "0.09729999999763095", "OutputQueueSize": "0", "ErrorCount": "0", "LastErrorDateTime": "", "WarningCount": "0", "LastWarningDateTime": "", "VideoFramesWritten": "569", "AudioFramesWritten": "889"}

RTMP Server Authentication

To connect to an RTMP server that requires authentication, provide the username and password in the server address using the following format: rtmp(s)://username:password@serveradress. Example:

 rtmps://myname:mypassword@rtmp.server.com/live/mystream

Ingesting RTMP(S) into CDN:s

Composer is compatible with any CDN that uses RTMP as an ingest.

Vindral Live CDN

Vindral Live CDN is for ultra-low latency playback and can be licensed separately. Find more information in the Vindral Live CDN documentation.

Documentation for Vindral Live CDN is out of scope for this section. However, there are a few things worth mentioning 

  • h264 configuration: if your stream is set up to pass through on the highest bitrate (ask RealSprint for this information):

    • For playback support on iOS devices:

      • use h264 profile “baseline”

      • Do not use b-frames. The number of b-frames should be set to 0.

  • The ingested stream needs to contain both audio and video. Streams with video only will not be playable.

  • If you are using the transcoding service for all ABR-streams (qualities), including the highest quality, you can use h264-profiles such as Main or High, as well as B-frames, for your ingest stream. 

Limelight CDN

 Limelight CDN is supported by Composer RTMP-target.

To provide authentication parameters, add username and password to the server address. For example: if your ingest URL is “ingest-url”, add username and password as follows:

rtmps://[USERNAME}:[PASSWORD]@ingest-url

Limelight ingest, and egress has been verified using the following RTMP-target configuration:

 More information on X264 and NVENC


Was this article helpful?