How to Set FFmpeg HTTP Streaming Headers and MIME-Type

This article explains how to configure custom HTTP headers and MIME-types when streaming audio or video using FFmpeg. You will learn the correct command-line syntax for the -headers and -mime_type options, how to format multiple headers, and see practical examples for common streaming setups.

Using the -headers Option

To send custom HTTP headers during an HTTP POST or PUT stream, use the -headers option. This option is a protocol-level parameter for the HTTP protocol in FFmpeg.

When defining headers, each header must be formatted with a carriage return and line feed (\r\n). In most command-line shells, you can write this as a single string.

ffmpeg -i input.mp4 -headers "Content-Type: video/mp4" -f mp4 http://yourserver.com/stream

If you need to send multiple headers, such as an authorization token along with the content type, separate them using \r\n inside the quotes:

ffmpeg -i input.mp4 -headers "Authorization: Bearer token123xyz"$'\r\n'"Content-Type: video/mp4"$'\r\n' -f mp4 http://yourserver.com/stream

(Note: The $'\r\n' syntax is commonly used in Bash to ensure carriage returns are interpreted correctly.)

Using the -mime_type Option

Some FFmpeg muxers and streaming protocols have a dedicated -mime_type option to define the format of the output stream. This is particularly useful when broadcasting to legacy HTTP stream servers or custom ingest endpoints.

To set the MIME-type directly:

ffmpeg -i input.wav -f mp3 -mime_type audio/mpeg http://yourserver.com/live

Configuring Headers for HLS and DASH

When streaming via HTTP Live Streaming (HLS) or Dynamic Adaptive Streaming over HTTP (DASH), you often need to push segments to a remote server using HTTP POST or PUT. You can pass the HTTP options directly to the output.

For HLS publishing with custom headers:

ffmpeg -i input.mp4 -f hls -hls_time 4 -hls_list_size 5 -method PUT -headers "Authorization: Bearer token123" http://yourserver.com/live/stream.m3u8

Key Considerations