Stream Video Over RTMPT Using FFmpeg
This article provides a direct guide on how to stream live or pre-recorded video using RTMPT (Real-Time Messaging Protocol Tunneled) through FFmpeg. RTMPT encapsulates standard RTMP audio and video packets within HTTP requests, allowing streams to bypass strict firewalls and proxy servers that block standard RTMP ports like 1935. You will learn the command-line syntax required to encode, format, and push a video stream to an RTMPT-compatible media server.
Understanding RTMPT in FFmpeg
RTMPT wraps standard RTMP data inside HTTP requests, typically transmitting over port 80. While it introduces additional latency compared to standard RTMP due to HTTP header overhead, it ensures connectivity in restricted network environments.
FFmpeg supports RTMPT natively using the rtmpt:// URL
scheme, provided your FFmpeg build includes RTMP/RTMPT network protocol
support (either through the native FFmpeg implementation or linked
against librtmp).
Basic Command Syntax
To stream an existing video file to an RTMPT server, use the following command template:
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 -ar 44100 -f flv rtmpt://your_server_ip:80/live/stream_keyParameter Breakdown
-re: Reads the input at its native frame rate. This is required when streaming from a pre-recorded file to simulate a live broadcast. Omit this flag if capturing from a live device like a webcam.-i input.mp4: Specifies the source video file or input capture device.-c:v libx264: Encodes the video stream to H.264, which is the standard codec required for the FLV container used by RTMP/RTMPT.-preset veryfast: Balances encoding speed and CPU utilization for live streaming.-maxrateand-bufsize: Controls bitrate variability to ensure stream stability over HTTP tunneling.-pix_fmt yuv420p: Ensures broad compatibility with video players and media servers.-g 50: Sets the Group of Pictures (GOP) size or keyframe interval (typically set to 2 seconds; for a 25 fps stream, use 50).-c:a aac -b:a 128k -ar 44100: Encodes the audio stream using AAC at 128 kbps and a 44.1 kHz sample rate.-f flv: Forces the output format into an FLV container, which is mandatory for RTMP/RTMPT streaming.rtmpt://your_server_ip:80/live/stream_key: The target endpoint. Ensure the protocol is explicitly defined asrtmpt://and the port matches the HTTP/RTMPT port configured on the destination media server (usually port 80).
Streaming from a Live Input Device
To stream a live webcam or capture card on Linux using Video4Linux2 (v4l2):
ffmpeg -f v4l2 -i /dev/video0 -f alsa -i default -c:v libx264 -preset ultrafast -tune zerolatency -c:a aac -f flv rtmpt://your_server_ip:80/live/stream_keyOn Windows using DirectShow:
ffmpeg -f dshow -i video="Integrated Camera":audio="Microphone" -c:v libx264 -preset ultrafast -tune zerolatency -c:a aac -f flv rtmpt://your_server_ip:80/live/stream_keyTroubleshooting and Verification
- Protocol Support: Verify your FFmpeg installation
supports the protocol by running
ffmpeg -protocols. Look forrtmptunder the "Output" section. - Firewalls: Confirm that the target server is listening for RTMPT traffic on the specified port and that outgoing traffic on that port is permitted by your local network.
- Latency: RTMPT generates significant polling
overhead. If latency is high, configure
-tune zerolatencyin your x264 parameters, but note that RTMPT will inherently be slower than standard RTMP.