Skip to main content

Multi audio and subtitle tracks

This example reads an MPEG-TS file with one video track, two audio tracks and two subtitle tracks, and publishes them over MoQ. It picks the audio and subtitle tracks by their PID and labels each with its language, Chinese and English. It publishes:

  • the source video unchanged, plus 720p and 540p H.264 renditions and 720p JPEG thumbnails
  • each audio track as both Opus and AAC
  • each subtitle track as WebVTT. The subtitle tracks are optional, so the stream also starts without them.

The video track sets gop_alignment = "match_incoming", so the 720p and 540p renditions get a keyframe wherever the source video has one. The renditions and the unchanged source then switch cleanly. The renditions' gop_size_ms is ignored, so encode the file with a keyframe every one or two seconds so that playback starts quickly.

Mount your MPEG-TS file at /media/YOUR_INPUT_FILE, replace that filename and the configured track IDs, and set YOUR_MOQ_PUBLISH_URL to the MoQ publish/lookup URL supplied for your channel. The lookup transport mode selects the transport from the resolved URL. Set YOUR_CHANNEL_ID to the channel identifier supplied with that endpoint.

Download multi-audio-subs.toml.

toml
# Vindral Bridge Packager example
# A file with two audio tracks and two subtitle tracks, sent to Vindral Live over MoQ.

version = "3"

# Read the MPEG-TS file at its own pace.
[[sources]]
id = "input"
source_type = "file"
description = "Pre-recorded video file"
realtime_pacing = true

[sources.protocol_options.url]
type = "string"
value = "/media/YOUR_INPUT_FILE"

[[transcoders]]
id = "encode"
description = "Video ladder, two audio tracks and two subtitle tracks"
source_ids = ["input"]

# Video track with multiple renditions
[[transcoders.tracks]]
id = "video"
type = "video"
passthrough = true
# Force a keyframe in every rendition wherever the source has one, so the
# renditions switch cleanly with the unchanged source video.
processing = { gop_alignment = "match_incoming" }

[transcoders.tracks.track_selector]
type = "track-kind"
kind = "video"

# 720p rendition
[[transcoders.tracks.renditions]]
id = "720p"
codec = "h264"
bit_rate = 2_000_000

[transcoders.tracks.renditions.size]
width = 1280
height = 720

# 540p rendition
[[transcoders.tracks.renditions]]
id = "540p"
codec = "h264"
bit_rate = 500_000

[transcoders.tracks.renditions.size]
width = 960
height = 540

# 720p jpeg rendition
[[transcoders.tracks.renditions]]
id = "720p-jpeg"
codec = "mjpeg"
bit_rate = 1280
frame_skipping = "frame_every_5_seconds"

[transcoders.tracks.renditions.size]
width = 1280

# Audio tracks

# First audio track, selected by PID.
[[transcoders.tracks]]
id = "audio-1"
type = "audio"

[transcoders.tracks.track_selector]
type = "track-id"
id = 0x101

[transcoders.tracks.track_selector.decoration]
language = "zho"

[[transcoders.tracks.renditions]]
id = "opus-1"
codec = "opus"
bit_rate = 128_000
sample_rate = 48_000

[[transcoders.tracks.renditions]]
id = "aac-1"
codec = "aac"
bit_rate = 128_000
sample_rate = 48_000

# Second audio track, selected by PID.
[[transcoders.tracks]]
id = "audio-2"
type = "audio"

[transcoders.tracks.track_selector]
type = "track-id"
id = 0x102

[transcoders.tracks.track_selector.decoration]
language = "eng"

[[transcoders.tracks.renditions]]
id = "opus-2"
codec = "opus"
bit_rate = 128_000
sample_rate = 48_000

[[transcoders.tracks.renditions]]
id = "aac-2"
codec = "aac"
bit_rate = 128_000
sample_rate = 48_000

# Subtitle tracks, converted to WebVTT.
[[transcoders.tracks]]
id = "subtitles-1"
type = "subtitle"

[transcoders.tracks.decoder]
name = "ttml"

[transcoders.tracks.track_selector]
type = "track-id"
id = 0x105

[transcoders.tracks.track_selector.decoration]
language = "zho"
metadata = { label = "Chinese" }

[[transcoders.tracks.renditions]]
id = "subs-1"
codec = "webvtt"

[[transcoders.tracks]]
id = "subtitles-2"
type = "subtitle"

[transcoders.tracks.decoder]
name = "ttml"

[transcoders.tracks.track_selector]
type = "track-id"
id = 0x106

[transcoders.tracks.track_selector.decoration]
language = "eng"
metadata = { label = "English" }

[[transcoders.tracks.renditions]]
id = "subs-2"
codec = "webvtt"

# Publish to Vindral Live over MoQ.
[[sinks]]
id = "moq"
sink_type = "moq"
description = "Primary broadcast stream"
source_ids = ["encode"]

[sinks.protocol_options.transport_mode]
type = "string"
value = "lookup"

[sinks.protocol_options.url]
type = "string"
value = "YOUR_MOQ_PUBLISH_URL"

[sinks.protocol_options.channel_id]
type = "string"
value = "YOUR_CHANNEL_ID"