Set Up RTSP Pusher

Comprehensive guide to RTSP Pusher: Configure TCP, UDP, and RTSP modes. Learn about RILF header, rtspserver.cfg setup, and FFMpeg integration.

Introduction

The RTSP Pusher enables external sources to push audio/video data into the Happytimesoft RTSP Server, which then broadcasts it as a standard RTSP stream.

This is ideal for custom encoders, simulation tools, or when you need full control over the stream ingestion process.

Pusher vs. Server Mode

[Pusher Mode]
Source → Pusher → RTSP Server → Clients
[Server Mode]
Clients ← RTSP Server ← Sources

In Pusher mode, the server actively receives pushed data. In standard Server mode, the server waits for clients to request streams from predefined sources.

Three Push Modes Explained

The Pusher supports three transport modes, each with different requirements.

Mode Configuration Use Case
RTSP No <pusher> config needed. URL suffix can be any string. Using FFMpeg or standard RTSP pushers.
TCP Requires <pusher> config with <mode>TCP</mode>. Custom applications needing reliable delivery.
UDP Requires <pusher> config with <mode>UDP</mode>. Low-latency applications, less reliable.

TCP Mode: The RILF Header

When using TCP mode, you must prepend a 4-byte RILF header before each RTP packet.

[TCP Packet Structure]
[RILF Header (4B)] + [RTP Packet]
Magic (0x24) | Channel (0) | RTP Length (16-bit)
C Structure: RILF Header
typedef struct
{
    uint32_t magic     : 8;  // 0x24
    uint32_t channel   : 8;  // 0
    uint32_t rtp_len   : 16; // RTP payload length (inc. RTP header)
} RILF;

This header allows the server to frame the incoming RTP packets correctly over the TCP stream.

Step 1: Configure rtspserver.cfg

Add a <pusher> node for TCP/UDP modes. Not needed for RTSP mode.

Example: rtspserver.cfg for TCP Pusher
<pusher>
    <suffix>pusher1</suffix>
    <video>
        <codec>H264</codec>
    </video>
    <audio>
        <codec>G711</codec>
        <samplerate>8000</samplerate>
        <channels>1</channels>
    </audio>
    <transfer>
        <mode>TCP</mode>
        <vport>50001</vport>
        <aport>50002</aport>
    </transfer>
</pusher>

Step 2: Push Stream with FFMpeg

For RTSP mode, you can use FFMpeg to push any file as an RTSP stream.

FFMpeg: Push via UDP
ffmpeg -re -i test.mp4 -vcodec libx264 -acodec copy -preset ultrafast -f rtsp -rtsp_transport udp rtsp://yourip/pusher
FFMpeg: Push via TCP
ffmpeg -re -i test.mp4 -vcodec libx264 -acodec copy -preset ultrafast -f rtsp -rtsp_transport tcp rtsp://yourip/pusher

Note: Replace yourip with the server's IP address. The suffix /pusher can be any string in RTSP mode.

Step 3: Access the Pushed Stream

After starting the RTSP Server and pushing data, clients can access the stream using the configured suffix:

  • rtsp://yourip/pusher1 (for TCP/UDP mode)
  • rtsp://yourip/any-suffix (for RTSP mode, suffix defined by pusher)

Practical Applications

  • Custom Encoders: Integrate proprietary H.264/H.265 encoders with the RTSP ecosystem.
  • Stream Simulation: Test RTSP clients with pre-recorded video files using FFMpeg.
  • Transcoding Pipelines: Use FFMpeg to transcode and push streams in real-time.

Best Practices

  • Use RTSP mode for simplicity when integrating with tools like FFMpeg.
  • Use TCP mode for custom applications requiring reliable delivery.
  • Always include the 4-byte RILF header when using TCP mode.