Connect to Secure WebSocket WSS Using FFmpeg
This article provides a straightforward guide on how to connect to a secure WebSocket (WSS) stream using FFmpeg. You will learn the correct command syntax, how to handle SSL requirements, and practical examples of both reading from and writing to a secure WebSocket.
Enabling SSL Support in FFmpeg
To connect to a secure WebSocket (wss://), your FFmpeg
installation must be compiled with SSL support (typically OpenSSL,
GnuTLS, or SecureTransport). If SSL is not enabled, FFmpeg will return a
“protocol not found” error when attempting to connect. You can verify
your installation’s protocol support by running:
ffmpeg -protocolsEnsure that tls and wss are listed in the
output.
Reading a Stream from a Secure WebSocket
To ingest a media stream from a secure WebSocket server, use the
wss protocol prefix in your input URL. Below is the command
to capture a live stream and save it to a local file:
ffmpeg -i wss://your-websocket-server.com/path/to/stream -c copy output.mp4If the WebSocket server requires custom HTTP headers for
authentication, connection handshakes, or origin verification, you can
pass them using the -headers option before the input:
ffmpeg -headers "Origin: https://yourdomain.com" -i wss://your-websocket-server.com/path/to/stream -c copy output.mp4Streaming to a Secure WebSocket
You can also stream media output to a secure WebSocket server. The receiving server must be configured to accept the incoming container format (such as MPEG-TS). To stream a local video file to a WSS server in real-time, use the following syntax:
ffmpeg -re -i input.mp4 -f mpegts wss://your-websocket-server.com/path/to/stream-re: Forces FFmpeg to read the input file at its native frame rate, which is required for live streaming.-f mpegts: Specifies the MPEG-TS container format, which is commonly used for streaming over WebSockets.