How to Stream Video Over RTMPT Using FFmpeg

Streaming video over RTMPT (Real-Time Messaging Protocol Tunneled) allows you to bypass strict firewalls and proxies by wrapping RTMP media data inside standard HTTP requests. This article provides a quick and direct guide on how to configure and execute an FFmpeg command to stream live video using the RTMPT protocol.

Prerequisites

To stream over RTMPT, your FFmpeg build must be compiled with librtmp support, as FFmpeg’s native RTMP implementation does not natively support tunneling. You can verify this by running ffmpeg -protocols in your terminal and ensuring rtmpt is listed under the supported output protocols.

The FFmpeg RTMPT Command

To stream a video file to an RTMPT server, use the following command structure:

ffmpeg -re -i input.mp4 -c:v libx264 -preset veryfast -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 128k -f flv rtmpt://your-server-ip:80/live/stream_key

Command Breakdown

  • -re: Tells FFmpeg to read the input file at its native frame rate. This is required for simulating a live stream from a pre-recorded file.
  • -i input.mp4: Specifies the path to your source video file.
  • -c:v libx264: Encodes the video to H.264, which is the standard codec for RTMP/RTMPT streaming.
  • -preset veryfast: Balances CPU usage and encoding quality.
  • -g 50: Sets the Group of Pictures (GOP) size to force a keyframe every 2 seconds (assuming a 25 fps source), ensuring stream stability.
  • -c:a aac -b:a 128k: Encodes the audio to AAC at a bitrate of 128 kbps.
  • -f flv: Forces the output format to FLV (Flash Video), the container format required for RTMP/RTMPT.
  • rtmpt://your-server-ip:80/live/stream_key: The destination URL. Note the rtmpt:// prefix and the use of port 80 (or 8080), which are standard HTTP ports used to tunnel the traffic through firewalls.