FFmpeg RTMPS Streaming with Client Certificates

To stream securely over RTMPS (RTMP over TLS/SSL) to a server that requires mutual TLS (mTLS) authentication, you must configure FFmpeg to present a client certificate and its corresponding private key. This article provides a direct guide on how to prepare your certificates and format the FFmpeg command line to establish a secure, authenticated connection.

Step 1: Prepare Your Certificates

FFmpeg requires certificates to be in the PEM format. You will need three files: 1. Client Certificate (client.crt or client.pem): The public certificate identifying your client. 2. Private Key (client.key): The private key associated with the client certificate. (For automated streaming, ensure this key is unencrypted/passwordless so FFmpeg can access it without user intervention). 3. CA Certificate (ca.crt, Optional but recommended): The Certificate Authority certificate used to verify the server’s identity.

Step 2: Configure the FFmpeg Command

FFmpeg provides specific options for the RTMP protocol to handle SSL/TLS connections. You can pass the client certificate and key using protocol-specific flags.

The standard command structure is as follows:

ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k \
  -c:a aac -b:a 128k \
  -f flv \
  -rtmp_cert "/path/to/client.crt" \
  -rtmp_key "/path/to/client.key" \
  "rtmps://your-secure-server.com:443/live/stream_key"

Step 3: Alternative URL Query Configuration

If your build of FFmpeg does not recognize the -rtmp_cert and -rtmp_key command-line flags, you can pass the TLS parameters directly inside the RTMPS destination URL as query arguments.

ffmpeg -re -i input.mp4 \
  -c:v libx264 -c:a aac \
  -f flv \
  "rtmps://your-secure-server.com:443/live/stream_key?cert_file=/path/to/client.crt&key_file=/path/to/client.key"

Important Considerations