Sub topic 7
Choosing a bitrate ladder
A bitrate ladder is the set of renditions (resolution and bitrate pairs) that you encode for each video. The player picks one rung at a time and moves between rungs as network conditions change. This chapter covers how to choose the rungs and how to check them.
This chapter assumes you know what a codec and a container are, how bitrate relates to file size, and what a transcoding job does. These come from the video basics and transcoding chapters. It also assumes you have seen an HLS master playlist.
What the ladder has to do
The ladder sets the limits of adaptive bitrate playback. If the rungs are too sparse, viewers jump between very different qualities. If they are too dense, you pay for encoding and storage that nobody notices. If the lowest rung is too high, viewers on poor networks stall instead of watching a blurry picture.
Three goals pull against each other:
- Quality: each rung should look good for its resolution.
- Coverage: the rungs should span the full range of viewer bandwidth, from weak mobile links to fast fibre.
- Cost: every rung adds encode time, storage and cache footprint.
Anatomy of a rung
Each rung is defined by a few parameters:
| Parameter | Meaning | Example |
|---|---|---|
| Resolution | Frame size in pixels | 1280x720 |
| Video bitrate | Average bits per second for video | 2800 kbps |
| Peak bitrate | Cap on short bursts, set with `-maxrate` and `-bufsize` | 3000 kbps |
| Codec and profile | Compression standard and feature set | H.264 Main |
| Frame rate | Frames per second | 24 or 30 |
| Audio bitrate | Bits per second for the audio track | 128 kbps |
The BANDWIDTH value in the master playlist should reflect the peak bitrate of video plus audio, not the average. Players compare it to measured throughput, so understating it causes stalls.
A starting ladder
A common starting ladder for H.264 looks like this:
| Rung | Resolution | Video bitrate | Typical use |
|---|---|---|---|
| 1 | 426x240 | 300 kbps | Very poor mobile links |
| 2 | 640x360 | 700 kbps | Weak mobile, small screens |
| 3 | 854x480 | 1200 kbps | Average mobile |
| 4 | 1280x720 | 2800 kbps | Good broadband, laptops |
| 5 | 1920x1080 | 5000 kbps | Large screens |
Treat these numbers as a first draft. Real content differs a lot, as the next sections show.
Spacing the rungs
Rungs are usually spaced by a roughly constant ratio, not a constant difference. A step of about 1.5x to 2x between adjacent bitrates works well. A smaller step produces switches that viewers cannot see. A larger step forces the player to choose between a rung that is too low and one that is too high.
The reason is perception. Going from 300 kbps to 700 kbps is a big visible change. Going from 5000 kbps to 5400 kbps is not. Equal ratios give roughly equal perceived steps.
Spacing also interacts with the player's safety margin. The selection rule in this tutorial uses a fraction of measured throughput:
def pick_rendition(renditions, throughput_bps, safety=0.8):
"""renditions: list of dicts sorted by ascending 'bandwidth' (bits per second)."""
usable = throughput_bps * safety
best = renditions[0]
for r in renditions:
if r["bandwidth"] <= usable:
best = r
return best
ladder = [
{"name": "360p", "bandwidth": 800_000},
{"name": "720p", "bandwidth": 3_000_000},
{"name": "1080p", "bandwidth": 6_000_000},
]
print(pick_rendition(ladder, 4_500_000)["name"]) # 720pWith a safety of 0.8, a 4.5 Mbps connection has 3.6 Mbps usable. That fits 720p (3.0 Mbps) but not 1080p (6.0 Mbps). The gap between 3 and 6 Mbps means that a viewer at 5.5 Mbps usable gets 720p and wastes almost half their bandwidth. Adding a rung near 4.5 Mbps would serve that viewer better.
Resolution versus bitrate
A higher resolution at too low a bitrate looks worse than a lower resolution at the same bitrate. At 1000 kbps, a 480p encode usually looks cleaner than a 720p encode, because the 720p encoder has too few bits per pixel and produces blocky artefacts.
For each resolution there is a bitrate below which the rung is not worth offering. A rule of thumb is to check bits per pixel:
bits per pixel = bitrate / (width x height x frame rate)For 1280x720 at 30 fps, 2800 kbps gives about 0.10 bits per pixel. H.264 content usually needs somewhere around 0.07 to 0.15 for acceptable quality, depending on how complex the picture is. A rung well below that range is a candidate for removal or for a lower resolution.
Per-title encoding
A fixed ladder treats every video the same. That wastes bits on simple content and starves complex content.
- A cartoon or a slide presentation looks fine at 720p with 1000 kbps.
- A football match with fast motion and grass texture may need 4000 kbps or more at the same resolution.
Per-title encoding fixes this by analysing each video and building its own ladder. The usual process is:
- Encode the video at several resolutions, each at several bitrates, as test encodes.
- Measure quality for each test encode with a metric such as VMAF.
- Plot quality against bitrate for each resolution.
- Pick the rungs that lie on the upper edge of those curves, called the convex hull. At each bitrate, this is the resolution that gives the best quality.
- Choose rungs along the hull at roughly even quality steps.
The cost is extra compute for the trial encodes, paid once per title. For a catalogue where each title is watched many times, this usually pays back in bandwidth savings. For a platform where most uploads are watched a few times, it may not. A middle option is to sort content into a few classes, such as animation, talking head and high motion, and keep one ladder per class.
Codecs and multiple ladders
Newer codecs such as HEVC, VP9 and AV1 reach the same quality at lower bitrates than H.264. AV1 can save around 30 percent or more over H.264 in many cases, at a much higher encode cost.
Offering them means one ladder per codec, and the master playlist lists all of them. The CODECS attribute lets each device choose a rung it can decode. Points to weigh:
- Device support: older devices only decode H.264, so you must keep that ladder.
- Encode cost: AV1 encoding takes many times longer than H.264, so apply it first to popular titles.
- Storage: each extra ladder adds renditions to store and cache.
A common policy is to encode every title in H.264, then add a newer codec for titles whose view count passes a threshold.
Constraints that shape the ladder
Several practical limits affect the final choice:
- Segment alignment: every rung must use the same keyframe interval and segment duration so the player can switch at segment boundaries. The earlier ffmpeg command does this with
-g 48 -keyint_min 48 -sc_threshold 0at 24 fps, giving a keyframe every 2 seconds. - Source resolution: never upscale. If the source is 720p, drop the 1080p rung.
- Device caps: small phone screens do not benefit from 1080p, and the top rung can be hidden from them to save data.
- Audio: audio is cheap compared to video, so one or two audio bitrates are enough.
- Data caps: some viewers want a limit on data use, so the player should be able to cap the maximum rung.
Checking the ladder against real data
Build the ladder from assumptions, then confirm it with playback data from the quality monitoring system. Useful signals:
- Rung distribution: if almost nobody plays the top rung, it costs storage for no benefit.
- Switch frequency: frequent switching between two rungs suggests a missing rung between them.
- Rebuffering at low throughput: stalls among viewers on slow networks suggest the lowest rung is too high.
- Throughput histogram: compare it to your bitrates and place rungs where many viewers sit.
Common mistakes
- Setting
BANDWIDTHto the average bitrate instead of the peak. - Using different keyframe intervals across rungs, which breaks clean switching.
- Offering a high resolution at a bitrate too low to look good.
- Making the lowest rung too high for mobile networks.
- Upscaling low-resolution sources to fill the ladder.
Exercise
A ladder has rungs at 800 kbps (360p), 3000 kbps (720p) and 6000 kbps (1080p). The player uses a safety factor of 0.8. A viewer has a steady 5.5 Mbps connection. Which rung do they get, what fraction of their throughput does it use, and what would you change?
Show answer
Usable throughput is 5.5 x 0.8 = 4.4 Mbps. The highest rung that fits is 720p at 3.0 Mbps, which uses about 55 percent of the 5.5 Mbps connection. 1080p at 6.0 Mbps does not fit. Add a rung between them, for example 1080p or 900p at about 4.2 Mbps, so viewers in this range get better quality. Check that the ratio between neighbouring rungs stays near 1.5x.
Exercise
A 1280x720, 30 fps rung is encoded at 600 kbps. Compute bits per pixel and say whether you would keep the rung.
Show answer
600,000 / (1280 x 720 x 30) = 600,000 / 27,648,000, which is about 0.022 bits per pixel. That is far below the 0.07 to 0.15 range for H.264, so the picture will be blocky. Remove the rung, or encode that bitrate at 480p or 360p, where the same bitrate gives more bits per pixel.