Skip to content

Audio Transcoding Plugin

The Transcode plugin provides FFmpeg-based audio/video transcoding capabilities, supporting both rule-based automatic triggering (regex matching on stream publish) and HTTP API manual control for managing transcoding tasks.

Cargo.toml
features = ["ffmpeg_transcode"]
transcode:
enable: true
ffmpeg_path: "ffmpeg" # FFmpeg binary path
mode: "auto" # Mode: auto / process
local_rtmp: "rtmp://127.0.0.1/live" # Local RTMP address (used as FFmpeg input source)
onpub: # Auto-transcoding rules (triggered on publish)
"^live/(.+)$": # Regex matching stream path
outputs:
- target: "rtmp://cdn.example.com/live/$1" # Target address (supports regex substitution)
options:
video_codec: "libx264"
audio_codec: "aac"
video_bitrate: 2000
audio_bitrate: 128
resolution: "1280x720"
frame_rate: 30
FieldTypeDefaultDescription
enableboolfalseWhether to enable the plugin
modestringautoFFmpeg backend mode
ffmpeg_pathstringffmpegFFmpeg binary path
local_rtmpstringrtmp://127.0.0.1/liveLocal RTMP input address
onpubmap{}Auto-transcoding rules
FieldTypeDescription
video_codecstringVideo encoder (e.g., libx264, libx265, copy)
audio_codecstringAudio encoder (e.g., aac, libopus, copy)
video_bitrateintVideo bitrate (kbps)
audio_bitrateintAudio bitrate (kbps)
resolutionstringResolution (e.g., 1280x720)
frame_ratefloatFrame rate

When a new stream is published, the Transcode plugin listens for StreamEvent::Created events and matches the stream path against regex rules in onpub. On a successful match, it automatically launches an FFmpeg transcoding process for each outputs entry.

When the source stream is destroyed (StreamEvent::Disposed), the plugin automatically terminates all transcoding tasks associated with that stream.

WebRTC streams use Opus audio encoding, but RTMP typically requires AAC. Transcoding rules automatically handle the audio format conversion:

onpub:
"^webrtc/(.+)$":
outputs:
- target: "rtmp://127.0.0.1/live/$1"
options:
video_codec: "copy" # Pass through video without re-encoding
audio_codec: "aac" # Opus → AAC
audio_bitrate: 128

Transcode a single RTMP stream into multiple bitrate variants:

onpub:
"^live/(.+)$":
outputs:
- target: "rtmp://127.0.0.1/live/$1_720p"
options:
video_codec: "libx264"
resolution: "1280x720"
video_bitrate: 2000
audio_codec: "copy"
- target: "rtmp://127.0.0.1/live/$1_480p"
options:
video_codec: "libx264"
resolution: "854x480"
video_bitrate: 1000
audio_codec: "copy"

Relay local streams to an external CDN:

onpub:
"^live/(.+)$":
outputs:
- target: "rtmp://cdn-push.example.com/live/$1"
options:
video_codec: "copy"
audio_codec: "copy"

All endpoints are mounted under the /transcode/api/ route prefix.

GET /transcode/api/list

Returns all currently active transcoding tasks.

Response example:

{
"code": 0,
"message": "success",
"data": {
"count": 2,
"jobs": [
{
"id": 1,
"source_path": "live/camera01",
"input_url": "rtmp://127.0.0.1/live/camera01",
"target": "rtmp://cdn.example.com/live/camera01"
}
]
}
}
POST /transcode/api/launch
Content-Type: application/json
{
"source_path": "live/camera01",
"target": "rtmp://cdn.example.com/live/camera01",
"options": {
"video_codec": "libx264",
"audio_codec": "aac",
"video_bitrate": 2000,
"resolution": "1280x720"
}
}

Response example:

{
"code": 0,
"message": "launched",
"data": { "id": 1 }
}
POST /transcode/api/close
Content-Type: application/json
{
"id": 1
}

You can also stop all associated tasks by source stream path:

{
"source_path": "live/camera01"
}
GET /transcode/api/exist?target=rtmp://cdn.example.com/live/camera01
GET /transcode/api/config
  1. FFmpeg process management: Each transcoding task corresponds to an independent FFmpeg subprocess; the plugin handles process creation and cleanup
  2. Resource consumption: Video transcoding (non-copy mode) is CPU-intensive; plan the number of transcoding tasks accordingly
  3. local_rtmp configuration: Ensure the engine’s RTMP plugin is enabled and the address matches the local_rtmp setting
  4. Target deduplication: Duplicate transcoding tasks will not be created for the same target URL