H.264, H.265 and AV1 ladder
Encode one SRT input into renditions in three video codecs, plus AAC and Opus audio, and publish them all to your Vindral Live channel over MoQ:
| Rendition | Codec | Size | Bit rate |
|---|---|---|---|
h264-720p | H.264 | 1280×720 | 2.5 Mbit/s |
h264-360p | H.264 | 640×360 | 600 kbit/s |
hevc-720p | H.265 | 1280×720 | 1.6 Mbit/s |
av1-720p | AV1 | 1280×720 | 1.2 Mbit/s |
av1-360p | AV1 | 640×360 | 400 kbit/s |
H.265 and AV1 reach the same picture quality as H.264 at a lower bit rate. The H.264 renditions keep the channel playable on devices that cannot decode the newer codecs. The player chooses a rendition from the viewer's network conditions and device capabilities; see Transcoding. Tune the sizes and bit rates to your content.
Run it
Set url and channel_id in the sink to your channel's MoQ publish URL and channel ID, save
the download as config.toml and select your release image as in
Usage:
docker run --rm --name packager-multi-codec \
-p 127.0.0.1:4040:4040 -p 9000:9000/udp \
-v "$(pwd)/config.toml:/etc/packager/config.toml:ro" \
"${PACKAGER_IMAGE:?Set PACKAGER_IMAGE to your release image}" start
The source listens for SRT on UDP 9000. To test with a file, send it from another host as caller:
ffmpeg -re -stream_loop -1 -i input.mp4 -c copy -f mpegts \
'srt://PACKAGER_HOST:9000?mode=caller&latency=120000'
Encoder load
The example encodes on the CPU with libx264, libx265 and libsvtav1. libx264 and
libx265 need an image variant that includes them; see
Build requirements. H.265 and AV1
take several times the CPU of H.264 at the same size, so measure on your host before adding
renditions. Performance lists the speed settings the Packager
applies to each encoder.
On an NVIDIA GPU, set device = "nvidia" on the transcoder and use h264_nvenc,
hevc_nvenc and av1_nvenc as encoder_name. AV1 needs a GPU with a hardware AV1 encoder.
A NETINT Quadra card also encodes all three codecs; see
NETINT ladder.
Complete configuration
Download multi-codec-ladder.toml.
# Vindral Bridge Packager example
# Encode one SRT input into H.264, H.265 and AV1 renditions and publish them to Vindral Live over MoQ.
version = "3"
# Receive the contribution feed. The encoder calls this listener.
[[sources]]
id = "contribution"
source_type = "srt"
protocol_options = { url = "srt://0.0.0.0:9000?mode=listener&latency=120000" }
[[transcoders]]
id = "encode"
source_ids = ["contribution"]
device = "cpu"
[[transcoders.tracks]]
id = "video"
type = "video"
track_selector = { type = "track-kind", kind = "video", is_required = true }
# H.264 for every player.
[[transcoders.tracks.renditions]]
id = "h264-720p"
codec = "h264"
encoder_name = "libx264"
bit_rate = 2_500_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 1280, height = 720 }
[[transcoders.tracks.renditions]]
id = "h264-360p"
codec = "h264"
encoder_name = "libx264"
bit_rate = 600_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 640, height = 360 }
# H.265 at a lower bit rate for the same picture quality.
[[transcoders.tracks.renditions]]
id = "hevc-720p"
codec = "hevc"
encoder_name = "libx265"
bit_rate = 1_600_000
gop_size_ms = 1000
max_b_frames = 0
format = "yuv420p"
size = { width = 1280, height = 720 }
# AV1 at a lower bit rate still.
[[transcoders.tracks.renditions]]
id = "av1-720p"
codec = "av1"
encoder_name = "libsvtav1"
bit_rate = 1_200_000
gop_size_ms = 1000
format = "yuv420p"
size = { width = 1280, height = 720 }
[[transcoders.tracks.renditions]]
id = "av1-360p"
codec = "av1"
encoder_name = "libsvtav1"
bit_rate = 400_000
gop_size_ms = 1000
format = "yuv420p"
size = { width = 640, height = 360 }
[[transcoders.tracks]]
id = "audio"
type = "audio"
track_selector = { type = "track-kind", kind = "audio", is_required = true }
[[transcoders.tracks.renditions]]
id = "aac"
codec = "aac"
sample_rate = 48_000
channels = 2
bit_rate = 128_000
[[transcoders.tracks.renditions]]
id = "opus"
codec = "opus"
sample_rate = 48_000
channels = 2
bit_rate = 96_000
# Publish every rendition to your Vindral Live channel over MoQ.
[[sinks]]
id = "vindral"
sink_type = "moq"
source_ids = ["encode"]
[sinks.protocol_options]
url = "https://lb.cdn.vindral.com/api/edge/moq-publish-url/YOUR_STREAM_KEY"
channel_id = "YOUR_CHANNEL_ID"
transport_mode = "lookup"