How to Set RTSP User-Agent and Auth in FFmpeg

Configuring custom user-agent headers and authentication credentials in FFmpeg allows you to connect to secure RTSP streams that require specific client identifiers or access controls. This guide explains how to embed credentials directly into an RTSP stream URL and how to pass a custom user-agent string using FFmpeg's command-line options.

Passing Authorization Credentials

FFmpeg supports standard basic and digest authentication for RTSP streams. The most direct and reliable method to supply credentials is by including them directly within the RTSP URL schema:

rtsp://<username>:<password>@<host>:<port>/<stream_path>

Example with Authentication:

ffmpeg -i "rtsp://admin:P@ssword123@192.168.1.50:554/live/ch0" -c copy output.mp4

If your username or password contains special characters (such as @, :, or /), you must percent-encode (URL-encode) them. For example, @ becomes %40, and : becomes %3A.

Setting a Custom User-Agent

Many IP cameras, media servers, and firewalls restrict access based on the connecting client's User-Agent string. In FFmpeg, you configure this using the -user_agent flag.

Because FFmpeg processes flags sequentially, this option must appear before the input flag (-i) so the RTSP demuxer applies it during the initial connection handshake.

Example with Custom User-Agent:

ffmpeg -user_agent "CustomClient/1.0" -i "rtsp://192.168.1.50:554/live/ch0" -c copy output.mp4

Complete Example: User-Agent and Authentication Combined

To combine both settings, specify the -user_agent parameter before the input flag and embed the credentials into the RTSP URL:

ffmpeg -user_agent "SecurityMonitor/2.5" -rtsp_transport tcp -i "rtsp://admin:SecretPass123@192.168.1.50:554/h264Preview_01_main" -c copy output.mkv

In this command:

  • -user_agent "SecurityMonitor/2.5" sets the custom client identifier.
  • -rtsp_transport tcp forces TCP transport for more reliable packet delivery, preventing frame dropping common with UDP.
  • admin:SecretPass123@ authenticates the request to the RTSP server.
  • -c copy records the stream without re-encoding, preserving quality and minimizing CPU usage.