Configure AMF Metadata in FFmpeg RTMP Streams

This guide explains how to inject, modify, and control Action Message Format (AMF) metadata in an RTMP broadcast using FFmpeg. You will learn how to set standard stream-level metadata (the onMetaData packet) using the FLV muxer, manage RTMP connection-level AMF parameters, and suppress or customize default metadata values to ensure compatibility with your RTMP ingestion server or media player.

1. Setting Stream-Level AMF Metadata (onMetaData)

RTMP streams wrap media frames in the FLV container format. During initialization, FFmpeg automatically generates an AMF0 onMetaData packet containing parameters like width, height, videocodecid, and framerate.

You can append custom key-value pairs or overwrite standard descriptive keys using the -metadata option before specifying the output format or URL:

ffmpeg -re -i input.mp4 -c:v libx264 -c:a aac \
  -metadata title="Live Broadcast Title" \
  -metadata description="Custom Stream Description" \
  -metadata custom_key="CustomValue" \
  -f flv rtmp://live.example.com/app/stream_key

Any standard -metadata key="value" arguments will be written into the onMetaData AMF array sent at the start of the stream.

2. Modifying FLV Muxer Metadata Behavior

The FLV muxer provides specific flags to control what AMF metadata is generated:

  • Prevent metadata injection: If your ingestion server requires a raw stream without the standard onMetaData packet, pass the no_metadata flag:

    -flvflags no_metadata
  • Inject keyframe indexing: For streams meant to be recorded and scrubbed on the server side:

    -flvflags add_keyframe_index

3. Setting Connection-Level AMF Metadata (connect Command)

When establishing an RTMP session, FFmpeg sends an AMF connect command containing connection parameters. You can configure these AMF properties using FFmpeg's native RTMP protocol options:

  • -rtmp_app <string>: Sets the target application name on the server.
  • -rtmp_flashver <string>: Sets the flashVer AMF string (defaults to LNX 9,0,124,2).
  • -rtmp_tcurl <string>: Sets the target tcUrl attribute (useful behind proxies or load balancers).
  • -rtmp_pageurl <string>: Sets the referring web page URL (pageUrl).
  • -rtmp_swfurl <string>: Sets the SWF player URL (swfUrl).

Example:

ffmpeg -re -i input.mp4 -c:v copy -c:a copy \
  -rtmp_flashver "FMLE/3.0 (compatible; FMSc/1.0)" \
  -rtmp_tcurl "rtmp://live.example.com/app" \
  -f flv rtmp://live.example.com/app/stream_key

4. Passing Custom AMF Objects via URL Parameters

FFmpeg's librtmp implementation also permits passing arbitrary AMF parameters during the connection phase by appending flags to the RTMP destination URL:

  • conn=B:0: Appends a boolean.
  • conn=S:value: Appends an AMF string.
  • conn=N:123: Appends an AMF number.
  • conn=O:1: Starts an AMF object.

Example:

ffmpeg -re -i input.mp4 -c:v copy -c:a copy \
  -f flv "rtmp://live.example.com/app/stream_key conn=S:auth_token conn=N:42"

Complete Example Command

The following command sets stream descriptive metadata, custom connection properties, and encodes the stream for a live RTMP destination:

ffmpeg -re -i input.mp4 \
  -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k \
  -c:a aac -b:a 128k -ar 44100 \
  -metadata title="Event Stream" \
  -metadata copyright="2026 Company LLC" \
  -rtmp_flashver "FMLE/3.0" \
  -f flv rtmp://live.example.com/live/myStreamKey