Configure FFmpeg to Trust Custom SSL CA Certificate
When streaming media over HTTPS, FFmpeg must validate the SSL/TLS certificate of the hosting server. If your stream is hosted behind a private or custom Certificate Authority (CA), FFmpeg will reject the connection with a handshake error unless it is configured to trust that specific CA. This article demonstrates how to configure FFmpeg to recognize custom SSL certificates using both command-line parameters and system environment variables.
Method 1: Use FFmpeg Command-Line Options
The most direct way to trust a custom CA is by passing the certificate file directly into the FFmpeg command. FFmpeg’s TLS protocol handler supports arguments to define verification behavior and point to a specific certificate file.
To stream using a custom CA, use the -ca_file option and
enable verification with -tls_verify 1 before your input
URL:
ffmpeg -tls_verify 1 -ca_file /path/to/custom-ca.pem -i https://your-secure-stream-url/playlist.m3u8 -c copy output.mp4-tls_verify 1: Forces FFmpeg to verify the peer’s certificate.-ca_file: Specifies the path to your custom CA certificate in PEM format.
Method 2: Configure Environment Variables
FFmpeg typically relies on underlying SSL libraries like OpenSSL or GnuTLS. You can instruct these libraries to load your custom certificate by setting global environment variables before running your FFmpeg command.
On Linux and macOS
Set the SSL_CERT_FILE variable to point to your
certificate:
export SSL_CERT_FILE="/path/to/custom-ca.pem"
ffmpeg -i https://your-secure-stream-url/playlist.m3u8 -c copy output.mp4Alternatively, if you have a directory containing multiple trusted
certificates, you can use SSL_CERT_DIR:
export SSL_CERT_DIR="/path/to/certs/directory/"
ffmpeg -i https://your-secure-stream-url/playlist.m3u8 -c copy output.mp4On Windows (Command Prompt)
set SSL_CERT_FILE="C:\path\to\custom-ca.pem"
ffmpeg -i https://your-secure-stream-url/playlist.m3u8 -c copy output.mp4On Windows (PowerShell)
$env:SSL_CERT_FILE="C:\path\to\custom-ca.pem"
ffmpeg -i https://your-secure-stream-url/playlist.m3u8 -c copy output.mp4Method 3: Import the CA into the Operating System Trust Store
If you do not want to specify the certificate path every time you run FFmpeg, you can install the custom CA directly into your operating system’s root store. FFmpeg will automatically trust any certificates validated by the system.
- Ubuntu/Debian: Copy the
.crtfile to/usr/local/share/ca-certificates/and runsudo update-ca-certificates. - CentOS/RHEL: Copy the
.crtfile to/etc/pki/ca-trust/source/anchors/and runsudo update-ca-trust. - macOS: Double-click the
.crtfile, add it to the Keychain, and set its Trust settings to “Always Trust”. - Windows: Import the certificate into the “Trusted
Root Certification Authorities” store using
certmgr.msc.