Open beta Leyla is free until December 31, 2026. Preorder at founders’ prices

Download

TrueHD and DTS in the browser, without converting on the server

Browsers play AAC, Opus, FLAC and, in some, Dolby Digital. They do not play TrueHD or DTS, the soundtracks on most Blu-ray remuxes. A media server usually answers by converting the audio on the server for every viewer. Leyla's web app decodes it in the page instead, so the server copies the file as it is.

Why browsers cannot play TrueHD or DTS

A film ripped from a Blu-ray usually carries a Dolby TrueHD or DTS-HD Master Audio track. Open it in a browser and the browser refuses the audio: neither codec is among those Media Source Extensions accept. The common fix is to convert the soundtrack to AAC on the server, which costs the server a core for as long as the film plays, multiplies with each viewer, and throws away the lossless track on the way.

A home server is often a NAS or a small PC, and the computer doing the watching is usually stronger than it. So Leyla moves the work to the viewer.

How it works

  1. The server copies, never converts

    The server packages the film as HLS with fragmented MP4 segments and copies the audio into them exactly as it is on disk. The web app's capability report says it can take TrueHD and DTS, so the planner chooses a copy rather than a conversion.

  2. A Worker decodes in WebAssembly

    Each segment passes through a Web Worker before the browser sees it. For DTS and TrueHD the Worker loads FFmpeg's own dca, truehd and mlp decoders compiled to WebAssembly: 954 KB, 422 KB compressed, fetched only the first time a film needs it. No package decoded TrueHD, so we build this one, and it also reports each channel's position, which neither codec states in its MP4 sample entry.

  3. FLAC, written fast

    The decoded samples are mixed to the channels the device has and encoded as FLAC by a small encoder written for this path: fixed predictors and Rice coding, no searching, so a frame encodes in a fraction of its own duration on a slow laptop.

  4. The segment is rewritten in place

    The audio track's sample entry becomes fLaC, each fragment gets new sample sizes, a rebuilt mdat and fresh data offsets. The video samples and every timestamp are carried over byte for byte: the tfdt of each fragment never changes, and each run of FLAC frames covers exactly the time the source samples did. TrueHD's access units last 1/1200 of a second, too short for FLAC, so they are grouped, each group as long as its units together.

Keeping it in sync

Sound and picture stay together because nothing that places them in time is touched. Where a remux rounded a duration (a DTS frame in Matroska is stored as 10 or 11 ms, never the 10.67 ms it decodes to), a short queue between decoder and encoder lets each frame take its true length instead of being cut or padded. A frame the decoder rejects becomes silence of the same length, never a gap, so the video beside it cannot drift.

When the device is too slow

On a fast PC the decoder needs a few percent of one core. A tablet or old phone can need five to ten times as much. The page times the Worker over the first half minute, and when it is busy for more than a third of one core, it asks the server for AAC instead, the same switch it makes if the Worker fails. Nobody has to choose anything.

Questions

Can Chrome play DTS or TrueHD?

Not on its own. Chrome, Firefox, Safari and Edge do not decode Dolby TrueHD or DTS through Media Source Extensions, which is why media servers usually transcode those tracks to AAC for a browser.

Why does my media server transcode audio in the browser?

The file's soundtrack is TrueHD or DTS, which the browser refuses. Leyla's web app decodes both itself, so the server copies the audio instead.

Is Dolby Atmos kept?

The channels are. Atmos height objects in a TrueHD track are metadata for an Atmos receiver; decoding in the browser keeps the channel bed (up to 7.1, mixed to what the device has) and not the objects.

Is the sound still lossless?

Yes. TrueHD and DTS-HD Master Audio decode to the exact samples, and FLAC is lossless, so nothing is lost between the disc and the speakers, apart from mixing down to fewer channels when the device has them.

The source

The decoder is LGPL-2.1-or-later, built from FFmpeg n7.1.5 with Emscripten 4.0.15, and the same inputs give the same bytes. Its source, build script and the glue that exposes the channel layout are at tropicalthink/leyla-audio-decode.

What plays directly on each kind of screen is on What plays where.

Something wrong or out of date here? Tell us.