Measure Video Startup Time With Percentiles, Not a Mean
A player release can lower mean startup time while viewers on slow links wait almost twice as long. Start the clock at intent, stop it at the first presented frame, record milestones on one clock, run cold starts per device and network segment, and gate on p95 per segment.

performance.now()) and stop it at the first requestVideoFrameCallback that fires while the video is not paused, using that callback's presentationTime. Record each step in between as a milestone on that clock, not as a duration. Run cold starts in a fresh browser context, at least 20 per device and network segment so the nearest-rank p95 is not the slowest run itself. Gate on p95 per segment, weight segments by audience share for the headline, and never gate on the mean: a release can lower it while the slowest tenth of viewers wait almost twice as long.A player release ships with a startup win on the dashboard. Mean time to first frame falls from 533 ms to 472 ms. The same release takes viewers on a constrained connection from 1.2 seconds to 2.1 seconds before they see a picture, and the mean hides it. Both releases come from the lab below, built so the regression is known in advance and the measurement has to find it.
This is part 3 of an eight-part series on streaming and CTV quality. Part 1 split a viewing session into separate contracts and named startup as one of them; part 2 checked what manifests prove before a player opens them. This part measures the startup contract so that a regression in one segment survives the summary. Bitrate switching and the inside of a DRM licence exchange belong to later parts; here the licence request is one more milestone.
testsrc2 and sine sources and served from http://localhost. The lab opens no external network connection. Network.emulateNetworkConditions is marked deprecated in the tip-of-tree DevTools Protocol as of that date; it still worked in this Chromium build.Where the startup clock starts and stops
The start is the intent, not the page load. Take performance.now() inside the handler for the click, remote-control key or autoplay decision that commits to playback. Starting at navigation folds page rendering into startup; starting at hls.loadSource() drops the entitlement or session call that often comes first. Use performance.now(), never Date.now(): the High Resolution Time specification defines a monotonic clock that is not subject to system clock adjustment, while Date.now() can move backwards between two reads.
The end is a presented frame, not an event that implies one. The HTML standard fires playing when readyState reaches HAVE_FUTURE_DATA while the element is not paused, and notes that the element may still not be potentially playing when it fires. loadeddata means the first frame can be rendered, and it can fire while the video is paused. Neither says a frame reached the screen. video.requestVideoFrameCallback() does: the callback runs when a frame is sent to the compositor, and its metadata carries presentationTime, when the frame was submitted for composition, and expectedDisplayTime, when the browser expects it to be visible. The specification is a WICG Draft Community Group Report, so check support on each target platform and fall back to playing where it is missing, labelled as a fallback in the data.
play.addEventListener("click", async () => {
const t0 = performance.now(); // intent: the click that commits to playback
const at = {};
const ms = (t) => Math.round(t - t0);
const done = () => at.playing !== undefined && at.firstFrame !== undefined && finish();
video.addEventListener("playing", () => { at.playing = ms(performance.now()); done(); }, { once: true });
// One-shot: each registration fires for the next presented frame only.
const onFrame = (now, meta) => {
if (!video.paused) { at.firstFrame = ms(meta.presentationTime); return done(); }
video.requestVideoFrameCallback(onFrame); // a paused first frame is not startup
};
video.requestVideoFrameCallback(onFrame);
// ... entitlement, loadSource, attachMedia, play()
});
The callback re-registers until it sees a frame while playing. A player that renders the first frame paused, then waits for a licence before calling play(), would otherwise report a startup it had not finished.
Record milestones from one clock, not durations
A total tells you that startup got slower; milestones tell you which step did. Record entitlement, multivariant and media playlists, the licence response for encrypted streams, the first segment received and appended, and the first frame, each as milliseconds after intent on the same performance.now() timeline. Milestones beat durations because players overlap steps. If the app requests entitlement and the manifest at the same time, "entitlement 250 ms + manifest 47 ms" adds up to a number that never happened. "Manifest received at 47 ms, entitlement at 252 ms, first frame at 287 ms" shows the critical path directly: whichever milestone sits just before the frame is the one to work on.
Resource Timing gives the network milestones without touching the player. Every fetch and XHR becomes a PerformanceResourceTiming entry whose responseEnd is on the same timeline as performance.now(). hls.js 1.7.4 loads segments with XHR, so its entries carry initiatorType "xmlhttprequest". The player's own events add what the network cannot see: hls.js fires FRAG_BUFFERED when a fragment's data has been appended to the SourceBuffer.
hls.once(Hls.Events.FRAG_BUFFERED, (_, d) => { at.appended = ms(performance.now()); at.segment = d.frag.relurl; });
function finish() {
const rt = performance.getEntriesByType("resource");
const end = (re) => { const e = rt.find((x) => re.test(x.name)); return e ? ms(e.responseEnd) : null; };
window.__startup = {
entitlement: end(/\/api\/entitlement$/),
manifest: end(/\/master\.m3u8$/),
mediaPlaylist: end(/\/r\d\.m3u8$/),
firstSegment: end(/_000\.m4s$/),
...at,
initiator: rt.find((x) => /_000\.m4s$/.test(x.name))?.initiatorType,
};
}
The resource timing buffer is finite: the specification recommends an initial limit of at least 250 entries. Startup will not reach it, but a long session with short segments will, so call performance.setResourceTimingBufferSize() if you extend the harness past startup.
A cold-start harness with CDP throttling
Each sample needs an empty HTTP cache and no warm connections, or the distribution fills with starts no new viewer gets. A new Playwright browser context per sample gives that, and Network.setCacheDisabled makes it explicit. Playwright's newCDPSession() works only on Chromium-based browsers, so this harness is Chromium-only.
const PROFILES = {
wifi: { n: 30, latency: 40, downloadThroughput: 5_000_000, uploadThroughput: 1_000_000 }, // ~40 Mbit/s
constrained: { n: 30, latency: 150, downloadThroughput: 375_000, uploadThroughput: 125_000 }, // ~3 Mbit/s
};
async function coldStart(release, cfg) {
const context = await browser.newContext(); // fresh cache and connections: a cold start
const page = await context.newPage();
const cdp = await context.newCDPSession(page);
await cdp.send("Network.enable");
await cdp.send("Network.setCacheDisabled", { cacheDisabled: true });
const { n: _, ...conditions } = cfg;
await cdp.send("Network.emulateNetworkConditions", { offline: false, ...conditions });
await page.goto(`${base}?release=${release}`);
await page.click("#play");
const s = await page.waitForFunction(() => window.__startup, null, { timeout: 30_000 })
.then((h) => h.jsonValue());
await context.close();
return s;
}
Three details of Network.emulateNetworkConditions decide what a profile means. Throughput is in bytes per second, so 3 Mbit/s is 375,000, not 3,000,000. latency is defined as the minimum time from request sent to response headers received, which is a floor rather than an added delay: in the lab, an entitlement endpoint that takes 250 ms on the server answered at 252 to 259 ms under both 40 ms and 150 ms of emulated latency. And the protocol's packetLoss parameter applies to WebRTC only, so these profiles have no loss at all. The tip-of-tree protocol marks the command deprecated in favour of emulateNetworkConditionsByRule plus overrideNetworkState, so pin the browser version.
Alternate releases inside the loop (A, B, A, B). Anything that drifts during the run, such as thermal throttling, then lands on both releases instead of looking like a difference between them.
Two releases built to disagree
The media is a two-rendition HLS ladder in fragmented MP4 with 2-second segments: 640×360 at 600 kbit/s and 1280×720 at 2,400 kbit/s. The noise filter stops the synthetic picture compressing to almost nothing; the first segments came out at 161,490 and 599,335 bytes.
ffmpeg -hide_banner -loglevel error \
-f lavfi -i "testsrc2=size=1280x720:rate=30:duration=20" \
-f lavfi -i "sine=frequency=440:sample_rate=48000:duration=20" \
-filter_complex "[0:v]noise=alls=40:allf=t,split=2[a][b];[a]scale=640:360[v0];[b]copy[v1]" \
-map "[v0]" -map 1:a -map "[v1]" -map 1:a \
-c:v libx264 -preset veryfast -profile:v main -g 60 -keyint_min 60 -sc_threshold 0 \
-b:v:0 600k -maxrate:v:0 600k -bufsize:v:0 600k \
-b:v:1 2400k -maxrate:v:1 2400k -bufsize:v:1 2400k \
-c:a aac -b:a 96k -ac 2 \
-f hls -hls_time 2 -hls_playlist_type vod -hls_segment_type fmp4 \
-master_pl_name master.m3u8 -var_stream_map "v:0,a:0 v:1,a:1" \
-hls_segment_filename "media/r%v_%03d.m4s" -hls_fmp4_init_filename "init_%v.mp4" \
media/r%v.m3u8
A local Node server serves the files and an entitlement endpoint that answers after 250 ms. Release A waits for entitlement, then loads the stream, starting on the 360p rendition. Release B requests entitlement and the manifest in parallel, which helps everyone, and pins hls.js startLevel to the 720p rendition for a sharper first picture, which costs about 438 KB more before the first frame: cheap on a fast link, expensive on a slow one.
The report: a faster mean and a slower tail
The run did one discarded warm-up session and 120 measured cold starts, 30 per release per profile, in 4 minutes 31 seconds. The audience mix of 90% Wi-Fi and 10% constrained is an input, standing in for what field data would supply. This is the output as printed:
warm-up session (discarded): firstFrame=567 ms
wrote 120 cold starts to runs.json
time to first frame after intent (ms); audience mix {"wifi":0.9,"constrained":0.1}
segment release n mean p50 p90 p95
wifi A 30 458 459 464 464
wifi B 30 288 287 292 295
constrained A 30 1209 1212 1220 1223
constrained B 30 2128 2129 2139 2145
all, weighted A 60 533 460 465 1212
all, weighted B 60 472 288 298 2129
milestones, p50 / p95 (ms after intent)
segment release entitlement manifest mediaPlaylist firstSegment appended firstFrame playing
wifi A 254 / 256 302 / 306 352 / 356 436 / 439 457 / 462 459 / 464 463 / 483
wifi B 252 / 253 47 / 48 92 / 96 260 / 265 279 / 286 287 / 295 296 / 317
constrained A 256 / 259 416 / 422 577 / 585 1176 / 1185 1210 / 1218 1212 / 1223 1217 / 1225
constrained B 256 / 258 160 / 163 320 / 326 2087 / 2095 2117 / 2133 2129 / 2145 2153 / 2166
'playing' dispatched after the first frame was presented: 120/120 sessions, max gap 41 ms
first segment initiatorType: xmlhttprequest
Read the weighted rows first. B's mean is 61 ms better, its p50 is 172 ms better, and even its p90 is better. Its p95 is 917 ms worse. A dashboard showing the mean, or the median, approves this release.
The milestone table says why. On Wi-Fi, B's manifest arrives at 47 ms instead of 302 ms because it no longer waits for entitlement, and the larger first segment costs little. On the constrained profile the manifest also arrives earlier, but the first segment now lands at 2,087 ms instead of 1,176 ms. Entitlement moved off the critical path and the first segment moved onto it. That finding has an owner; a single total does not.
Lab distributions are much tighter than field ones: emulated throughput is exact and the server is local, so the Wi-Fi p50 and p95 sit within 10 ms of each other. Real networks spread each segment far wider.
Weight segments by audience share, not by run count
The lab ran 30 starts on each profile because each segment needs enough samples on its own. Pooling those 60 runs as if they were the audience would claim half of all viewers are on a constrained link. The report instead gives each run a weight of its segment's audience share divided by that segment's run count, and computes a weighted nearest-rank percentile: sort by value, accumulate weights, return the first value whose cumulative weight reaches the target. The CI reliability article covers the unweighted nearest-rank method and why to keep one method throughout.
const pct = (xs, p) => {
const s = [...xs].sort((a, b) => a.v - b.v);
const total = s.reduce((t, x) => t + x.w, 0);
let cum = 0;
for (const x of s) if ((cum += x.w) >= (p / 100) * total - 1e-9) return x.v;
};
const mine = rows.filter((r) => r.release === release);
const xs = mine.map((r) => ({
v: r.firstFrame,
w: SHARE[r.profile] / mine.filter((m) => m.profile === r.profile).length,
}));
Weighting also exposes a blind spot of any aggregate percentile: a segment can only put its own times into the aggregate p95 if it holds more than 5% of sessions. Here the constrained share is exactly 10%, so p95 lands inside it while p90 lands on the slowest Wi-Fi start, which is why p90 improved and p95 did not. At a 4% share, the aggregate p95 would have improved too. Gate per segment, and use the aggregate only for the headline.
How many cold starts each segment needs
Nearest-rank p95 is the value at rank ⌈0.95 × n⌉. For any n up to 19 that rank is n itself, so the "p95" of 19 samples is the single slowest run, and a release gate built on it fails whenever one sample hiccups. At n = 20 it becomes the second slowest, and at n = 30 still the second slowest. For p99 the same arithmetic requires 100 samples before the figure stops being the maximum.
Multiply that floor by the grid you care about. Three device classes on three network profiles at 30 cold starts each is 270 runs per release, or 540 to compare two releases. At the lab's rate of about 2.2 seconds per run, averaged over a fast and a slow profile, that is about 20 minutes on one machine, before any device that cannot run Playwright at all. Choose the grid from where real viewers are, not from every combination the emulator allows.
Four ways a startup number lies
A warm cache counted as a cold start
Reusing a page or context between samples lets the second run read the manifest and segments from the HTTP cache. Check it in the data: Resource Timing's transferSize is 0 for a response served from the local cache and exactly 300 for one revalidated with the server, so any first-segment entry with a transferSize of 0 is not a cold start.
Treating playing as the first frame
In all 120 lab sessions the playing handler ran after the first frame's presentationTime, by up to 41 ms. The specification has the browser queue a task to fire playing, so the handler's timestamp includes whatever else the main thread was doing. On a busy CTV main thread the gap can be larger. If you must fall back to playing, store which boundary each sample used and never mix the two in one percentile.
Zeros from a cross-origin CDN
Without a Timing-Allow-Origin header that passes the timing allow check, segment entries from a CDN on another origin are opaque: requestStart and responseStart read zero, while responseEnd survives. The milestone still works, but a dashboard computing time to first byte as responseStart - startTime reports a negative value for every segment, and the mean includes them. Filter on responseStart > 0 and count the rows you dropped.
The first session in a fresh browser
The warm-up session in the lab took 567 ms to its first frame, against a Wi-Fi p95 of 464 ms for the same release afterwards. The first start in a new browser process pays one-off costs. Launch the browser once, discard one session, and keep a fresh context per sample.
What a laptop lab cannot tell you about a CTV
The case that motivates most startup work is a low-end CTV on congested Wi-Fi, and this harness reaches only part of it. CDP's Emulation.setCPUThrottlingRate slows the CPU by a factor; it does not model a television's hardware decoder or media pipeline, so decode and append times from a laptop say little about the device. Emulated throughput is also smooth, with no jitter and no loss.
Use the lab to compare two builds under identical, repeatable conditions before release. Take absolute numbers from field telemetry on the devices, with the same boundaries and milestone names, so a lab regression and a field regression read the same way.
Questions about startup measurement
Where does the clock start for autoplay, with no click?
At the app's decision to play: the line of code that commits to playback after the page or screen is ready. Record it with performance.now() as you would a click, and label autoplay sessions separately, because they often start before the page has settled.
What happens to sessions that never reach a first frame?
Keep them out of the latency percentiles and report them as a separate startup failure rate. A release that turns slow starts into failed ones improves its p95 by losing its worst samples, so read the two numbers together.
Should the gate use p99 instead of p95?
Only where each segment collects at least 100 starts per release, which usually means field data. Below that, nearest-rank p99 is the maximum, and a gate on the maximum fails on noise.
Specifications and docs behind the startup numbers
- WHATWG HTML Living Standard, media elements. The conditions for
playingandloadeddata, thereadyStatevalues, and the note thatplayingcan fire before the element is potentially playing. - HTMLVideoElement.requestVideoFrameCallback(). The callback firing when a frame is sent to the compositor, one registration per callback, the meaning of
presentationTimeandexpectedDisplayTime, and the document's Draft Community Group Report status. - W3C Resource Timing.
responseEndandinitiatorTypevalues, the recommended 250-entry buffer andsetResourceTimingBufferSize(), attributes zeroed for opaque cross-origin entries, andtransferSizeof 0 for local cache and 300 for revalidation. - W3C High Resolution Time. A monotonic clock not subject to system clock adjustment, coarsening to 100 microseconds (5 when cross-origin isolated) or coarser, and why
Date.now()is unsuitable for durations. - Chrome DevTools Protocol definition, browser_protocol.json.
Network.emulateNetworkConditionsparameters in bytes per second, latency as a minimum to response headers,packetLosslimited to WebRTC, the deprecation in favour ofemulateNetworkConditionsByRule,Network.setCacheDisabledandEmulation.setCPUThrottlingRate. - Playwright BrowserContext API.
newCDPSession()and its restriction to Chromium-based browsers. - hls.js 1.7.4 API documentation.
startLevel,FRAG_BUFFEREDfiring after data is appended to theSourceBuffer, and loader stats that hls.js compares againstperformance.now().
Apply this now, before the next player release
- Find where your player's startup clock starts today. If it is page load,
loadSource()orDate.now(), move it toperformance.now()in the intent handler. - Add a
requestVideoFrameCallbackend boundary that ignores paused frames, and log which boundary each session used. - Log milestones, not durations: entitlement, manifest, licence where it applies, first segment received, first append and first frame, all as milliseconds after intent.
- Pick the two or three device and network segments that hold most of your viewers and the one that holds your worst sessions. Run 30 cold starts per segment for the current release and keep the table as a baseline.
- Add a gate on p95 per segment, not on the aggregate mean, and record the audience shares you used to weight the headline number.