Skip to main content
Back to Blog

Automate Captions, Audio Tracks and A/V Sync Checks

A synthetic multilingual episode exposes silent Hindi audio, an 80 ms sound lead, and a forced-caption declaration with an out-of-window cue. Build the file-level lab, then test actual selection and readability in the shipped player.

Shashank Rawlani

Engineering Leader | Builder | Problem Solver | AI Engineer

Published Nov 27, 20268 min read
View AI-ready Markdown
Four stacked lanes crossed by dashed guides: green flash bars and a ringed node on top, green wave bursts on their guides with one orange burst early, a flat orange line struck by a crossed circle, green pills and a dashed orange pill.
Quick answer: Test the published track declarations, cue time ranges, decoded audio, and measured flash/beep offset separately. A valid FORCED=YES tag does not prove the shipped player displayed a cue. Finish with a player and human accessibility review.

A bilingual episode can start and switch renditions successfully while the Hindi dub is silent. The English forced subtitle can exist on disk while its default selection changes. A third failure sits in the encoded media: the English beep arrives 80 ms before its matching flash. A startup test sees none of these. Part 1 of this series separates session contracts; part 2 covers general manifest validation. This article builds an accessibility and sync check around a deliberately broken multilingual episode.

Three claims, three kinds of evidence

RFC 8216 defines DEFAULT as the client's choice when the user has given no other preference, while AUTOSELECT permits environment-based selection. A default rendition must also be autoselectable. FORCED is allowed only on subtitles and marks content considered essential. These attributes are instructions to a client, not a screenshot of the result. A player may apply its own selection policy, and its policy can change by version or platform.

WebVTT requires a cue end after its start. The media window adds another product rule: an episode that ends at 6 seconds should not ship a cue ending at 6.5. This timing check catches an edit mismatch, but a cue inside the window can still describe the wrong dialogue. WCAG 2.2 SC 1.2.2 requires captions for prerecorded audio in synchronized media; SC 1.2.4 covers live audio at Level AA. A track called "CC" is not proof that it describes speech, speakers, and important non-speech sounds.

The file lab below inspects a small declaration fixture. It is intentionally not a playable HLS multivariant stream: there is no EXT-X-STREAM-INF or segment playlist. This is useful for isolating declaration checks, but it cannot support claims about automatic selection. To test that, load the production playlist in the exact player and device family you ship.

A complete six-second synthetic lab

Run this with Bash, Python 3 and ffmpeg 9.0.1. It creates three 25 fps black videos with white frames at 1, 3 and 5 seconds. Each has English and Hindi AAC files with 100 ms tones at those times. The early build advances both tones by 80 ms; the silent build makes the Hindi channel silent. No programme media or private data enters the fixture. Save the following as run.sh in an empty directory and run bash run.sh. It writes only to that directory.

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
for variant in good early silent; do
  offset=0
  [[ "$variant" == early ]] && offset=-0.08
  ffmpeg -hide_banner -loglevel error -y -f lavfi -i "color=c=black:s=320x180:r=25:d=6,drawbox=c=white:t=fill:enable='between(mod(t,2),1,1.02)'" -c:v libx264 -pix_fmt yuv420p -an "$variant-video.mp4"
  for lang in en hi; do
    freq=440; [[ "$lang" == hi ]] && freq=660
    expr="if(lt(mod(t-${offset}+2,2),1.0),0,if(lt(mod(t-${offset}+2,2),1.1),0.5*sin(2*PI*${freq}*t),0))"
    if [[ "$variant" == silent && "$lang" == hi ]]; then expr='0'; fi
    ffmpeg -hide_banner -loglevel error -y -f lavfi -i "aevalsrc='${expr}':s=48000:d=6" -c:a aac "$variant-$lang.m4a"
  done
done
cat > good.vtt <<'VTT'
WEBVTT

f1
00:00:01.000 --> 00:00:02.000
Station entrance
VTT
cat > bad.vtt <<'VTT'
WEBVTT

f1
00:00:05.000 --> 00:00:06.500
Station entrance
VTT
cat > good.m3u8 <<'M3U'
#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="English",LANGUAGE="en",DEFAULT=YES,AUTOSELECT=YES,URI="good-en.m4a"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="Hindi",LANGUAGE="hi",DEFAULT=NO,AUTOSELECT=YES,URI="good-hi.m4a"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English forced",LANGUAGE="en",DEFAULT=YES,AUTOSELECT=YES,FORCED=YES,URI="good.vtt"
M3U
sed 's/DEFAULT=YES,AUTOSELECT=YES,FORCED=YES/DEFAULT=NO,AUTOSELECT=YES,FORCED=YES/' good.m3u8 > bad.m3u8
python3 - <<'PY'
import re, subprocess
from pathlib import Path
for name in ('good','early','silent'):
    print('==',name)
    for lang in ('en','hi'):
        p=subprocess.run(['ffmpeg','-hide_banner','-i',f'{name}-{lang}.m4a','-af','volumedetect','-f','null','-'],capture_output=True,text=True)
        peak=re.search(r'max_volume: (\S+) dB',p.stderr).group(1)
        print(f'audio {lang}: peak {peak} dB')
    v=subprocess.run(['ffmpeg','-hide_banner','-i',f'{name}-video.mp4','-vf','blackdetect=d=0.5','-f','null','-'],capture_output=True,text=True).stderr
    a=subprocess.run(['ffmpeg','-hide_banner','-i',f'{name}-en.m4a','-af','silencedetect=n=-30dB:d=0.5','-f','null','-'],capture_output=True,text=True).stderr
    flashes=[float(x) for x in re.findall(r'black_end:([\d.]+)',v)][:3]
    beeps=[float(x) for x in re.findall(r'silence_end: ([\d.]+)',a)][:3]
    print('flash:',flashes,'beep:',beeps)
    print('sound lead ms:',[round((f-b)*1000) for f,b in zip(flashes,beeps)])
for m in ('good','bad'):
    text=Path(m+'.m3u8').read_text()
    forced=next(x for x in text.splitlines() if 'FORCED=YES' in x)
    cue=Path(m+'.vtt').read_text()
    end=re.search(r'--> (\d\d):(\d\d):(\d\d\.\d+)',cue).groups()
    end_seconds=int(end[0])*3600+int(end[1])*60+float(end[2])
    print(f'{m} metadata: forced default={"DEFAULT=YES" in forced}, cue end={end_seconds}s, inside 6s={end_seconds<=6}')
PY

The lab printed this output on macOS arm64 with ffmpeg 9.0.1. The reported onset is quantised by the 25 fps video frame boundary and affected by AAC encoding. The decoded measurement is the evidence; the requested shift is only the stimulus.

== good
audio en: peak -5.7 dB
audio hi: peak -5.9 dB
flash: [1.0, 3.0, 5.0] beep: [1.000042, 3.000042, 5.000042]
sound lead ms: [0, 0, 0]
== early
audio en: peak -5.4 dB
audio hi: peak -5.5 dB
flash: [1.0, 3.0, 5.0] beep: [0.919958, 2.919958, 4.919958]
sound lead ms: [80, 80, 80]
== silent
audio en: peak -5.7 dB
audio hi: peak -91.0 dB
flash: [1.0, 3.0, 5.0] beep: [1.000042, 3.000042, 5.000042]
sound lead ms: [0, 0, 0]
good metadata: forced default=True, cue end=2.0s, inside 6s=True
bad metadata: forced default=False, cue end=6.5s, inside 6s=False

The silent row still has a good English offset because that row measured English. Its Hindi peak near −91 dB is the separate failure. This distinction matters: a single selected-audio check can hide a broken alternate language. The fixture's 80 ms lead is readily measured; a release threshold must be set for the end-to-end path and validated on the target device. ITU-R BT.1359 addresses relative sound and vision timing in broadcasting, but a file measurement excludes decoder, display, soundbar, and Bluetooth delay.

Turn file readings into release contracts

Start with the multivariant playlist. For each audio group, require a unique NAME, a language tag that matches the actual dub, and a documented default. RFC 8216 says NAME must be distinct within a group; for autoselectable renditions, distinguish the combinations of language, associated language, forced flag and characteristics. The lab's tiny fixture shows a broken forced declaration: the forced English line remains present but loses DEFAULT=YES. A manifest assertion should fail that policy. Whether a player still chooses it requires an actual playback assertion.

Then parse every cue, including cue settings and valid timestamp forms, with a WebVTT parser used by your pipeline. The short Python check in the fixture demonstrates the media-window comparison only; it does not claim full WebVTT conformance. Also fail an end that does not follow its start, starts that run backward, a missing expected cue, or a cue for a different cut. The last two need an editorial or synchronized reference, because timestamps alone cannot identify speech.

Finally decode each audio rendition. The volumedetect peak is a coarse silence guard, not a loudness or language check. A short transient can produce a high peak in an otherwise empty track. Sample more than one scene, check speech-bearing windows, and keep an audio fingerprint or human listening sample where the cost is justified. The flash/beep pair gives a concrete offset: positive values in this lab mean sound leads picture. Repeat markers through a long programme to expose drift; a single median can hide a late-title failure.

The player boundary is a separate test

In the shipped HLS player, begin without a saved subtitle preference. Record the selected audio rendition, selected subtitle rendition, video.textTracks labels and modes, and the active cues after seeking to a known forced line. Then select Hindi audio and repeat. An AudioTrackList in the HTML standard does not guarantee that every browser exposes HLS rendition choices there; use the player's own track API when it owns selection.

// Run in the player page after it has loaded the production HLS asset.
// Adapt player.audioTracks/player.subtitleTracks to the shipped player API.
const selected = {
  audio: player.audioTracks[player.audioTrack]?.name ?? null,
  subtitle: player.subtitleTrack < 0
    ? null : player.subtitleTracks[player.subtitleTrack]?.name,
  showing: [...video.textTracks]
    .filter(track => track.mode === 'showing')
    .flatMap(track => [...(track.activeCues ?? [])].map(cue => cue.text)),
};
if (selected.audio !== 'English' ||
    selected.subtitle !== 'English forced' ||
    !selected.showing.includes('Station entrance')) {
  throw new Error(JSON.stringify(selected));
}

This is a player integration assertion, not output from the six-second file lab. It needs a playable stream and the real application player. Seek inside the cue, wait for track loading and a cuechange event, and capture the selected track plus active cue text on failure. After switching audio, assert the subtitle policy for that language explicitly; the HLS manifest alone cannot decide whether an English forced cue remains useful to a Hindi listener. A hidden text track can keep active cues without drawing them, while a disabled one does not. For visible-caption claims, require showing and inspect the rendered result.

What the checks leave for a person

Review a sample for each language and each forced track on the devices that matter. A fluent reviewer must verify translation and names, a captions reviewer must confirm speaker identification and meaningful non-speech sounds, and a viewer must inspect readability against the picture. A camera and microphone in front of a television can assess the final sound-picture path; the ffmpeg result cannot. Keep the human observations beside the automated report, with the exact asset and player build.

Failure diagnosis stays narrow. A missing cue can be a stale subtitle asset, a selection-policy change, or a player rendering defect. Compare the playlist declaration, the fetched VTT bytes, the track mode and the active cue in that order. Silence on one dub points to an audio encode or mapping error even when the player reports a successful switch. A constant offset points to a muxing or encoder delay; an offset growing across the title suggests clock drift.

Questions that change the test

Does FORCED=YES guarantee the subtitle appears?

No. RFC 8216 describes the rendition and client selection guidance. Your player, saved preference and device determine whether it is displayed. Assert a known active cue in the shipped player.

Can a successful audio switch prove the dub is healthy?

No. The synthetic silent Hindi file is decodable. Switching proves the player selected a rendition; decoded samples and a listening review establish the sound.

Is an 80 ms lead always a release failure?

Do not promote a fixture number into a universal threshold. Measure the full device path, choose a budget for your service, and record its sign convention and measurement uncertainty.

Primary references

  • RFC 8216 defines HLS rendition attributes and selection guidance.
  • W3C WebVTT defines cue timing; it is a Candidate Recommendation Draft.
  • WHATWG HTML media defines text track modes and active cues.
  • WCAG 2.2 defines caption success criteria and the caption/subtitle distinction.
  • FFmpeg filters documents the three measurement filters used in the lab.
  • ITU-R BT.1359-1 covers relative timing of sound and vision for broadcasting.

Apply this now

Put one multilingual test asset through the production packaging path. Save the resulting playlist, every cue file, a peak and onset report for each audio rendition, and the player's selected-track and active-cue state. Fail only on conditions your checks actually observe. Assign a reviewer to the translation, caption content, readability and device sync sample before release.