Streaming and DRM
Widevine in Chromium, FairPlay in WebKit tabs beside it, and which streaming services play where.
var configuration = CefRuntime.Configuration.chrome
configuration.services.protectedMedia = .automatic // Chromium fetches Widevine (L3)
Netflix-class services need FairPlay, H.264 or AAC, which Chromium in
CefSwift does not have. Show them in a WKWebView tab, as the Browser
example does. Browser example: Features/WebKitTabs opens streaming sites in WebKit windows (FairPlay), on Sources/SystemEngine.
There is no Gallery demo; the Browser’s browser://playground/ has Widevine
and FairPlay test streams.
Playing streaming services
Streaming services protect their video with DRM, which browsers expose
through Encrypted Media Extensions (EME). Chromium in CefSwift has Widevine;
the system’s WebKit, which an app can show beside it in a WKWebView, has
FairPlay:
Chromium (CefPage) |
WebKit (WKWebView) |
|
|---|---|---|
| DRM | Widevine, downloaded from Google at run time; Clear Key | FairPlay Streaming; Clear Key |
| Widevine level | Software (L3), host not verified (no VMP) | — |
| Video codecs | VP8, VP9, AV1; clear H.264 and HEVC only with the experimental system media decoders | H.264, HEVC, VP9, AV1 |
| Audio codecs | Opus, MP3 and other open formats; clear AAC only with the system media decoders | AAC and the open formats |
| Needs | Nothing for test streams and services that accept L3 | Nothing: no entitlement, licence or signing |
| Plays Netflix-class services | No: they require VMP | Yes, as Safari does (see Services) |
The short version: services that play in Safari play in a WKWebView,
and Chromium plays Widevine content that does not require a verified host.
An app that needs both shows streaming sites in WebKit and everything else
in Chromium, as the Browser example does (WebKit and
FairPlay).
Widevine in Chromium
CEF does not ship Google’s Widevine content decryption module (CDM).
Chromium’s component updater downloads it from Google into the profile
directory, <rootCacheDirectory>/WidevineCdm/, on the user’s Mac.
configuration.services.protectedMedia decides whether it does:
services.protectedMedia |
Effect |
|---|---|
.automatic |
The component updater runs and fetches Widevine, whatever services.componentUpdates says. The default, and the .chrome preset’s. |
.disabled |
CefSwift does not ask for the CDM. With services.componentUpdates = .disabled, as in the .embedded preset, Chromium registers no component, neither downloads the CDM nor loads one already on disk, and refuses com.widevine.alpha. With component updates on, Chromium registers Widevine with its other components, and its updater has no way to leave one out: it downloads the CDM at its first check, about a minute after start-up, and pages can use it from then on. |
.preinstalled(widevineDirectory:) |
As .automatic, and copies a CDM your app carries into the profile before Chromium starts, so protected media works on first launch and offline. Only for apps licensed by Google to distribute the CDM. |
With the updater on, CefSwift asks for Widevine as soon as the app creates
its first page (Chromium’s update service fetches nothing before that),
and the download takes from a few seconds to tens of seconds; left to
itself the updater would wait a minute. Clear Key (org.w3.clearkey) is built in and works in every mode.
var configuration = CefRuntime.Configuration.embedded
configuration.services.protectedMedia = .automatic
// Later, for example before showing a player:
switch try await CefRuntime.shared.installWidevine() {
case .installed(let version): print("Widevine \(version)")
case .failed: print("Could not fetch Widevine; offline?")
default: break
}
CefRuntime.shared.widevine reports .unavailable, .notInstalled,
.installing, .installed(version:) or .failed at any time. Pages that
asked for com.widevine.alpha before it arrived ask again when reloaded.
What Chromium in CefSwift plays with Widevine is content that accepts a
software CDM on an unverified host, in VP9 or AV1 video with Opus audio:
Google’s and Shaka Player’s test streams, browser://playground/ in the
Browser example, and services that do not require a verified host.
Codecs. CEF’s official builds leave out H.264, HEVC and AAC: they are
patent-licensed, and Chromium includes them only in Google Chrome. Content
that offers only those codecs does not play in Chromium here, protected or
not. Enabling them takes a CEF built with proprietary_codecs=true ffmpeg_branding=Chrome, which CefSwift does not use. The experimental
system media decoders play clear AAC, H.264 and
HEVC with macOS’s decoders, at a cost for video; encrypted media in those
codecs still does not play.
Verified Media Path. Widevine on desktop has a second requirement that
the major services enforce: the browser binary that hosts the CDM must carry
a Verified Media Path (VMP) signature from Widevine. The CDM reports to the
licence server whether its host is verified, and services such as Netflix
refuse licences to an unverified one (Netflix reports error M7121-1331).
Chrome has it (Google Chrome Framework.sig); CEF builds do not, and
CEF 156 passes the CDM no host binary to verify at all: with
--vmodule=cdm_host_files=1, the CDM process logs InitVerification: Calling VerifyCdmHost_0() with 1 files, the CDM itself, where Chrome passes
its framework too. So no signing step on your side makes a stock CEF app
verified.
The routes to a verified host are a build of CEF patched to register its
framework’s .sig, plus either castLabs’ commercial VMP certification for
custom Chromium builds (castLabs’ free EVS signing service covers its own
Electron builds only) or a licence agreement with Widevine
(widevine.com). Both are outside what CefSwift
can do for you.
Licensing. The CDM is Google’s proprietary software. Its LICENSE
reads: “You may not use, modify, sell, or otherwise distribute the Software
without a separate license agreement with Google.” Copying it out of Google
Chrome, or bundling it, is distribution; letting Chromium’s component
updater fetch it from Google on the user’s Mac is the route that needs no
agreement. Pointing an app at the copy inside an installed Chrome gains
nothing either: it is the same CDM the component updater downloads (Chrome
157 and CEF 156 both use 4.10.3112.0), and the host is still unverified.
.preinstalled(widevineDirectory:) exists for apps that hold a Widevine
licence covering distribution.
Signing. The CDM runs in <App> Helper.app and is signed by Google’s
team. Under the hardened runtime, library validation lets a process load
libraries from its own team only, so a team-signed helper refuses the CDM.
Add the protectedMedia capability to cefapp.json; it gives that helper
com.apple.security.cs.disable-library-validation. Ad hoc builds without
the hardened runtime need nothing. CefRuntime.shared.capabilities.canLoadWidevine
and cef doctor report the state. Chromium’s sandbox, the mock keychain and
ad hoc signing do not affect Widevine.
WebKit and FairPlay
FairPlay Streaming exists only in Apple’s WebKit, the engine Safari uses.
CefSwift does not wrap it, but an app can show the pages that need it in a
WKWebView beside its Chromium pages: FairPlay in a WKWebView needs no
entitlement, licence or signing, and a page that identifies as Safari
(applicationNameForUserAgent ending Version/<Safari's version> Safari/605.1.15) gets the service’s Safari player. The same goes for
content in H.264 or AAC, which Chromium in CefSwift cannot decode.
The Browser example does this. Its SystemEngine target
(Examples/Sources/SystemEngine) is a
small WKWebView wrapper written against CefKit’s public API:
SystemPage.prefersSystemEngine(for:)names the streaming hosts to hand over; the example’spage(_:decidePolicyFor:)cancels such a navigation and opens the URL in a WebKit tab instead.- Each
CefProfilemaps to a WebKit data store of its own (the default store for.default, an in-memory one whenisIncognito, a persistent one derived from the profile’sidotherwise), so WebKit keeps cookies and storage apart from Chromium’s. importCookies(from:for:)copies the cookiesCefProfile.cookies(for:)returns for one site into the WebKit store, carrying a sign-in over.evaluateJavaScriptruns classic scripts and awaits promises, asCefPage’s does, andCefUserScripts becomeWKUserScripts.
The Browser example opens streaming services in WebKit tabs by itself (Settings: “Play streaming services with WebKit”), marks them with a WebKit badge in the address field, hands a tab back to Chromium when you follow a link off the service, and has View › Open in WebKit for any page.
Services
Status as of 2026-11-12, macOS 27.2.1. “Verified here” means tested on this Mac without an account; signed-in playback could not be tested.
| Service or content | Chromium with Widevine | WebKit with FairPlay |
|---|---|---|
| Google’s Widevine test stream (Shaka “Angel One”, VP9) | Plays, licence granted (verified here) | — |
| Axinom’s FairPlay test stream (H.264) | — | Plays, licence granted (verified here) |
| H.264 or AAC-only content, protected or not | Does not play: no codecs (verified here) | Plays (verified here) |
| Netflix | Refuses playback without VMP (verified by castLabs’ and users’ reports) | Player starts and is granted com.apple.fps.3_0 (verified here); signed-in playback expected, unverified. Netflix lists Safari for up to 4K. |
| Hulu, Disney+, Max | Expected to refuse without VMP (reported, unverified here) | Expected to play as in Safari, unverified |
| Prime Video | Reported to fall back to SD without VMP, unverified here | Expected to play as in Safari, unverified |
| Apple TV (tv.apple.com) | Unverified | Expected to play as in Safari, unverified |
| Spotify web player | Expected to play, unverified | Expected to play, unverified |
macOS screenshots leave protected video out, so a captured frame of a playing DRM video shows black or the page behind it.
Other DRM. FairPlay exists only in Apple’s WebKit; Chromium on macOS has no FairPlay. PlayReady exists only in Microsoft Edge and Chrome on Windows. Firefox uses the same Widevine CDM, downloaded from Google under Mozilla’s own agreement; there is no other DRM a third-party macOS browser can adopt.
System media decoders
services.systemMediaDecoders = .audio plays audio in codecs CEF’s builds
leave out, with the decoders macOS ships: AAC (LC, HE-AAC, HE-AAC v2,
xHE-AAC), Apple Lossless, AC-3 and E-AC-3; .video adds clear H.264 and
HEVC (Video, below). It is experimental, off by default and app-wide. Decoding happens in CefSwift’s media service, an XPC
service in the App Sandbox, which the systemMediaDecoders capability puts
in the bundle; without it the option does nothing and pages see what they
would without it (CefRuntime.shared.capabilities.hasSystemMediaService).
var configuration = CefRuntime.Configuration.chrome
configuration.services.systemMediaDecoders = .audio
{ "capabilities": ["systemMediaDecoders"] }
What plays. Measured with CEF 158.0.6 on macOS 27.2.1, an Apple M2,
with local media made by AVFoundation and afconvert, in the Compat
example (-features systemaudio) and SelfTest’s systemMedia group:
| Content | Plays | Notes |
|---|---|---|
MSE audio/mp4 with mp4a.40.2 (AAC-LC), mp4a.40.5 (HE-AAC) |
Yes | Each 1-second fragment becomes one native append: one updatestart, update, updateend; buffered is one range. |
MSE mp4a.40.29, mp4a.40.42, mp4a.67, alac, ac-3, ec-3 |
Supported | isTypeSupported is true. HE-AAC v2 and ALAC play as files (below); macOS has no AC-3, E-AC-3 or xHE-AAC encoder to make test media with, so those were not played. |
<audio>/<video> with a same-origin .m4a, .mp4 (audio only) or .aac (ADTS) |
Yes | AAC-LC, HE-AAC, HE-AAC v2, 16- and 24-bit ALAC (lossless at its depth). src and currentSrc keep the page’s address. Seeking lands where asked. play() called right after src, and new Audio(url) never put in the document, play once the shim has taken over. |
| 5.1 AAC | Yes | Each channel in its place, as FLAC orders them (L R C LFE Ls Rs); AAC stores 5.1 centre first. |
playbackRate 0.5 and 2 |
Yes | The element’s clock runs at the rate asked (0.4998 and 2.004 measured). |
The same, cross-origin with crossorigin and a CORS response |
Yes | |
| Cross-origin media without CORS | No | Refused before any fetch, so nothing becomes readable that was not; the page gets Chromium’s error. |
H.264 or HEVC video, and MSE types that mix avc1 with AAC |
Only with .video |
Without it, isTypeSupported and canPlayType stay false and "". With it, see Video below. |
| Encrypted media (EME) | Untouched | Clear Key and Widevine behave as without the option. |
MediaSource in a worker (MediaSourceHandle) |
No | Only documents’ main worlds get the shim. |
How it works. A renderer demuxes what the page appends, or the file
an element could not play, and sends the packets with their times to the
browser process, which relays the bytes to the media service without
reading them. The service decodes them with AudioToolbox and returns FLAC
(verbatim, 16-bit, or 24-bit for deeper lossless sources) in fragmented
MP4, which the renderer appends to a native audio/mp4; codecs="flac"
SourceBuffer of the page’s own MediaSource. The media element, its
clock, buffered, seeking, playbackRate, full screen and picture in
picture are Chromium’s own. FLAC takes about twelve times AAC’s bytes, so
the option raises Chromium’s audio SourceBuffer limit to 96 MB
(--mse-audio-buffer-size-limit-mb), about 8 minutes of 48 kHz stereo. Playing a 30-second AAC file took 1.0 s of CPU every 15 s across the
app’s processes and the service (median of three), against 0.99 s for the
same audio as a native FLAC file: within the noise of a shared machine.
Architecture has the details.
Why a service. Chromium’s sandbox keeps AudioToolbox’s decoders out of
renderers (AudioConverterNew returns 'fmt?'), and the browser process
runs outside any sandbox. So the page’s audio is parsed and decoded in
<App> Media.xpc, signed with com.apple.security.app-sandbox and no
other entitlement: no network, no files outside its container, no devices.
One service process decodes for every page of the app; a crash in it fails
the appends waiting on it (the page sees a decode error) and the next
append starts it again.
Video. .video plays clear H.264 and HEVC. Chromium decodes
neither, so the media service decodes them with VideoToolbox, in
hardware, and the page gets the frames one of two ways:
- Direct, for a
<video>without native controls: the decoded frames go to the element through aMediaStreamTrackGenerator, and a clock element of the shim’s plays the sound and keeps the time; the page’s element answers for it (currentTime,paused,buffered,play(), the media events). - VP9, for an element with
controls(a MediaStream’s controls are a live stream’s), and for a MediaSource page that asked about VP8, VP9 or AV1 first: the renderer encodes each frame again as VP9 with Chromium’s encoder and appends that to a nativevp09SourceBuffer, so the element, its clock, controls, full screen and picture in picture are Chromium’s own.CEFSWIFT_DIRECT_VIDEO=0in the app’s environment sends all video this way.
Either way page content above the video stays above it.
var configuration = CefRuntime.Configuration.chrome
configuration.services.systemMediaDecoders = [.audio, .video]
| Content | Plays | Notes |
|---|---|---|
<video> with an .mp4, .m4v or .mov of H.264 (avc1, avc3) or HEVC (hvc1, hev1), with or without AAC |
Yes | Under the origin rule above. Each frame shows the frame its clock is at; seeking lands on the frame asked for. Every track must be one the shim plays: a file whose sound is Opus, say, stays Chromium’s and fails. |
MSE video/mp4 with H.264 or HEVC, one buffer each for video and audio (as YouTube’s and DASH players do) |
Yes | One native append per page append, as for audio. |
MSE video/mp4; codecs="avc1…, mp4a…", video and AAC in one buffer (as hls.js does for muxed fragmented MP4) |
Yes | The native buffer is vp09 and flac in one; the page sees one buffer. |
A video codec with an audio codec Chromium plays in one type (avc1, opus) |
No | Stays Chromium’s. |
| Encrypted H.264 or HEVC (EME), FairPlay | No | FairPlay video stays in WebKit (WebKit and FairPlay). |
What video costs. Playing 1080p at 30 frames a second on an Apple
M2, with no frames dropped and, in most runs, every frame within 20 ms
of the sound,
took about 1.15 times the instructions of WebKit’s processes and twice
their memory by the direct route, and about seven times their CPU and
three and a half times its memory by the VP9 route, whose picture is also
lossy a second time (0.1 bit a pixel a frame, 6 Mb/s at 1080p30); design
notes have the numbers. For long or high-resolution viewing, or on battery,
WebKit is the better engine for such a page (the Browser example’s
WebKit tabs); .video is for pages that must stay in Chromium.
What a page can observe of video. MediaSource.isTypeSupported and
canPlayType answer yes for H.264 and HEVC; the SourceBuffer is
Chromium’s own of type VP9 (its videoTracks and error messages say VP9);
by the direct route the media events are untrusted, captureStream() has
no audio track, and picture in picture’s buttons act on the picture alone;
MediaCapabilities.decodingInfo reports such a configuration as not power
efficient; the first frame comes later than natively (0.2 to 0.3 s by the direct route, 0.5 to 0.8 s by VP9, with
the service running) and appends of video take as long as their encode.
What a page can observe. The replaced functions are native functions
that call the shim, so Function.prototype.toString prints function appendBuffer() { [native code] } for them as for Chromium’s, name and
length are the originals’, and what they throw is what Chromium throws
(TypeError: Illegal invocation, InvalidStateError, with Chromium’s
messages). The shim leaves no global. What still tells:
- The replaced members (
MediaSource.isTypeSupported,MediaSource.prototype.addSourceBufferandendOfStream,SourceBuffer.prototype.appendBuffer,remove,abort,changeTypeand theupdating,timestampOffset,appendWindowStartandmodeaccessors,HTMLMediaElement.prototype.canPlayType,playand thesrcandcurrentSrcaccessors,MediaCapabilities.prototype.decodingInfo, andwindow.Audio, so that anAudioelement out of the document is watched from its creation) have an ownprototypeproperty and can be called withnew, as CEF’s native functions can; Chromium’s cannot.Audio()withoutnewreturns an element instead of throwing. CEF 158 offers no way to make a native function that is not a constructor. canPlayTypeandisTypeSupportedanswer yes for the system codecs, as Chrome does and CEF does not.- A system-codec
SourceBufferis Chromium’s own, of type FLAC: itsaudioTracksand an error’s message name FLAC. - Appends complete later than native ones (the first, which starts the service, took 4.6 s on a loaded machine; later one-second fragments took 16 to 19 ms each on average), and the buffer holds the decoded audio’s size.
- A media element whose file the shim plays fires no
errorfor the native player’s failure, plays from aMediaSourceof the shim’s, and anabortthe shim fires for an append it cancels hasisTrustedfalse.
FairPlay in Chromium pages
CefProtectedMedia’s CefFairPlay plays FairPlay Streaming audio in
Chromium pages of the origins an app lists, with AVFoundation, in
CefSwift’s FairPlay service. It is experimental, off until installed, and
audio only; Spotify’s web player is the first site. Add the
CefProtectedMedia product, list the fairPlay capability in
cefapp.json, and install it in the profiles whose pages may use it:
import CefProtectedMedia
let fairPlay = CefFairPlay(origins: CefFairPlay.spotify)
fairPlay.install(in: .default)
fairPlay.origins.insert("https://music.example") // reaches open pages at once
{ "capabilities": ["fairPlay"] }
How it works. For the listed origins, in top-level documents only, a
page script offers com.apple.fps.1_0 (and com.apple.fps,
com.apple.fps.3_0) from requestMediaKeySystemAccess, keeps the
certificate the player gives its MediaKeys, and catches the HLS media
playlist the player gives the element, as a data: or https address.
The app checks the call and the playlist and hands both to
<App> FairPlay.xpc, which plays the stream with AVPlayer, serving the
playlist from memory, and an AVContentKeySession. Each key request
(SPC) reaches the page as its session’s message event, the page’s
license server answers, and the license (CKC) goes back through
update. The element then mirrors the service’s player: currentTime,
duration, paused, ended, readyState and their events, and play,
pause, seeking, volume, muted and playbackRate go to the service.
Keys and decrypted audio never leave AVFoundation. The tab’s mute
(CefPage.isAudioMuted) mutes the service’s player, and
page(_:didChangePlaying:) on the delegate drives a playing indicator.
What is checked. The bridge exists only in documents of the listed
origins, and each call is checked again against the frame and origin the
browser process establishes from the frame’s address: only the main frame
of a listed https origin, while isEnabled, may call. A playlist passes
CefFairPlayPlaylist only as a media playlist (no variants, which would
make AVFoundation load playlists the app has not seen) of at most 2 MB
whose segments and initialization map are https addresses with a host,
and whose keys are skd:// or https. Certificates are limited to
64 KB, licenses to 256 KB. Anything refused gives the element a media
error (code 3) and calls fairPlay(_:page:didFail:), so the app can show
the page in WebKit instead; the Browser example does
(WebKit and FairPlay).
Setting changes. origins and isEnabled reach pages already open on
a listed origin at once: turned off, a page’s next
requestMediaKeySystemAccess gets Chromium’s own answer and playing
sessions stop. The page script itself reaches documents that load after an
origin is added.
Measured. With CEF 158.0.6 on macOS 27.2.1, an Apple M2, in the Compat
example (-features fairplay, the page’s own origin listed), online: the
audio of Axinom’s public FairPlay test vector
(protected_hls_1080p_h264_singlekey, SAMPLE-AES), handed to the element
as a data: playlist as Spotify’s player does, went loadstart,
encrypted, a 6304-byte SPC from AVFoundation in the session’s message,
Axinom’s license server answering 200 with an 844-byte CKC,
loadedmetadata, canplay (duration 734.21), play, waiting,
playing, and currentTime advanced 2.0 s in 2 s; the delegate heard it
play. A playlist with a file: segment got media error 3 and the delegate
refused("a segment that is not https: file:///etc/hosts"). A page of an
origin without the module gets NotSupportedError and no bridge.
SelfTest’s fairPlay group checks the same against
https://cefswift.test. Spotify needs an account, so playing a Spotify
track is unverified.
What a page can observe. On a listed origin: the cefswiftFairPlay
global (in same-origin subframes too, whose calls are refused), the replaced EME and media element members (JavaScript functions
there, not native ones), MediaKeys and sessions that are not Chromium’s
objects, events the script dispatches (isTrusted false), and an element
whose own player stays empty. Other origins see none of it.
System media decoders: a sandboxed service, FLAC and native functions
services.systemMediaDecoders = .audio
(guide) decodes pages’ AAC, ALAC, AC-3
and E-AC-3 with AudioToolbox. Measured with CEF 158.0.6 on macOS 27.2.1,
an Apple M2, in the Compat example, on a machine shared with other builds
(load average 10 to 105), so the times are upper bounds.
Where decoding runs.
| Place | Result |
|---|---|
| The renderer | Closed: Chromium’s sandbox refuses the decoder, AudioConverterNew returns 'fmt?'. |
| The browser process (#28) | Works, but the page’s audio is parsed in the one process with no sandbox at all. |
An XPC service in the App Sandbox (<App> Media.xpc), chosen |
Works with no entitlement besides com.apple.security.app-sandbox. The first append, which starts the service, took 4.6 s here; later one-second fragments took 16 to 19 ms each, the service’s decode and the two copies included. Playing a 30-second AAC file used 0.93, 1.00 and 1.44 s of CPU per 15 s across every process of the app and the service; the same audio as a native FLAC file 0.52, 0.99 and 1.29 s; the idle page 0.22 to 1.06 s. |
What Chromium gets. The service writes FLAC in fragmented MP4 itself,
in Swift, rather than handing PCM to the renderer for JavaScript to wrap as
#28 did: the decoder writes planar big-endian samples, which are FLAC’s
verbatim subframes byte for byte, so the FLAC is one copy of the decoded
audio, and the renderer appends the service’s answer in one native
appendBuffer. A page’s append then fires one updatestart, update and
updateend, as natively, which a wrapper SourceBuffer (#28’s) could
only imitate; addSourceBuffer returns Chromium’s own buffer, so
sourceBuffers, instanceof and identity checks hold.
How the replacements look. CEF’s cef_v8_value_create_function makes a
native function whose toString is function name() { [native code] };
calling the JavaScript implementation with set_rethrow_exceptions passes
its exceptions to the caller untouched (TypeError: Illegal invocation,
Chromium’s InvalidStateError messages). Measured: the 14 replaced
functions print as native code with the originals’ name and length.
They differ in two ways CEF cannot change: they have an own, non-configurable
prototype (delete returns false) and they can be called with new.
The alternatives were worse: a Proxy of the original prints
function () { [native code] }, without the name, and patching
Function.prototype.toString is itself a replaced native.
Lossless at any depth. AAC and Dolby decode to 16-bit FLAC; ALAC keeps 24 bits when its source had more than 16. A 16-bit ALAC file decodes to exactly its input samples (unit test), and 5.1 AAC plays each channel in FLAC’s place: 498, 750, 1002, 64, 1248 and 1500 Hz heard for 500, 750, 1000, 62.5, 1250 and 1500 Hz written (the analyser’s bins are 5.9 Hz wide).
System video decoders: the routes measured
CEF’s official builds cannot decode H.264 or HEVC, and unlike AAC
(System media decoders) there is no
lossless, cheap format Chromium does decode that a decoded video frame can
be rewritten into. These are the routes measured with CEF 158.0.6 on
macOS 27.2.1, an Apple M2, by pages run in the Compat example
(-printValue). services.systemMediaDecoders = .video builds the
second, re-encoding (below); SelfTest’s
videoRoutes group checks the facts the table rests on against each CEF
update.
| Route | What it keeps | Result |
|---|---|---|
WebCodecs VideoDecoder with avc1 or hvc1 |
Everything: the page decodes in Chromium’s sandboxed GPU process | Closed: isConfigSupported is false for avc1.640028, avc1.42E01E, hvc1.1.6.L120.90 and hev1.1.6.L93.B0; true for vp09.00.10.08 and av01.0.04M.08. CEF’s build leaves H.264 and HEVC out (proprietary_codecs), WebCodecs’ decoders included. (WebCodecs encodes avc1.640028 through VideoToolbox; that does not help a page that must decode.) |
Decode in the media service (VideoToolbox), re-encode to VP9 or AV1 in the renderer (WebCodecs, libvpx/libaom in software), append that to a native SourceBuffer |
Everything the element does: clock, buffered, seeking, full screen, picture in picture, drawImage, requestVideoFrameCallback; page content above the video stays above it |
Built, as .video: WebCodecs in real-time mode at 4 Mb/s encoded 1280×720 at 239–256 frames a second (VP9), 200–259 (VP8), 225 (AV1), and 1920×1080 at 170–187 (VP9), 55–111 (VP8), on synthetic frames, with the machine idle (load average 3); with its load at 30–45 the same runs gave 2 to 31. A 30 fps 1080p stream would spend about a sixth of the encoder’s real-time capacity, every frame crosses two processes uncompressed (1080p NV12 is 3.1 MB, 93 MB/s at 30 fps), and the picture is lossy a second time at the bitrate the shim picks. See The re-encoding route, built. |
MediaStream (srcObject) from decoded frames, or WebRTC’s H.264 decoder |
The element’s picture | Closed, as #28 found: a MediaStream replaces the element’s clock, buffered, duration and seeking with a live stream’s, which hls.js, Shaka and dash.js rely on; CEF lists no H.264 in RTCRtpSender.getCapabilities, and Blink refuses an encoded frame whose payloadType changed (0 of 300 frames decoded). |
Native layer over the element: decode in the media service, present in an AVSampleBufferDisplayLayer the app positions over the element’s rectangle, timed by the element’s clock; a black VP9 track of the same timeline in the element keeps its clock, buffered and size |
The element’s clock and events, and hardware decoding at about the cost of native playback | Not built. It shows the video, but over the page: whatever the page draws above the video — the player’s controls, subtitles, an ad overlay — is hidden under the layer, the element itself shows black in full screen, picture in picture, drawImage and requestVideoFrameCallback, and clipping (overflow, border-radius, transforms, clip-path) is the page’s to know and the app’s to mimic. Chromium has no hole-punching for an embedder (its VideoHoleFrame is for Android and Cast), and a transparent video track still leaves the player’s own background above a layer underneath. |
What the overlay route would need, measured as far as it goes:
- A placeholder track. WebCodecs encodes one black 1920×1080 VP9 key
frame in 965 bytes, and MSE accepts
video/mp4; codecs="vp09.00.10.08"; one such sample a GOP would give the element a real video track with the source’s size and timeline at one decode a second. - The clock.
currentTimeread at each animation frame against the page’s clock is what the layer’s timebase would follow; the app would get it in a process message, a 0.13 ms round trip floor (Service calls), and set the timebase rate fromplaybackRate. - Decoding outside the app. The media service would decode with
VTDecompressionSessionand hand frames to the app asIOSurfaces (IOSurfaceCreateXPCObject) without a copy; the app would only display them. Not measured: whether VideoToolbox’s hardware decoder opens in the App Sandbox service as AudioToolbox does.
The re-encoding route, built
services.systemMediaDecoders = .video
(guide) hands Chromium VP9 in place of
H.264 and HEVC where the direct route
cannot apply: elements with native controls, and MediaSource pages that
asked about VP8, VP9 or AV1. Measured on 2026-11-29 with CEF 158.0.6, macOS 27.2.1, an
Apple M2 with 8 GB, on a machine shared with other builds (load average 3
to 6).
renderer (MediaShim) demux MP4 (avcC/hvcC, samples) wire payload
│ cefswift.media.decodeVideo, ≤ 24 MB of frames a request
browser relays the packets; copies each IOSurface once shared memory to the renderer
│ decodeVideo(…) → [IOSurface] XPC, no copy
<App> Media.xpc VTDecompressionSession, hardware, NV12 video range App Sandbox
renderer VideoFrame (transfer) → VideoEncoder vp09 realtime → fMP4 → native appendBuffer
Which codec to hand Chromium. VideoToolbox on this Mac encodes H.264,
HEVC and ProRes in hardware and nothing Chromium decodes
(VTCopyVideoEncoderList), and decodes neither VP9 nor AV1 in hardware,
so the second encode is Chromium’s, in software. Encoding 300 frames of
1920×1080 at a paced 30 a second with WebCodecs in real-time mode (a
scrolling texture, harder than the clips below) took, in the renderer:
| Codec | CPU for 10 s | Bitrate it made |
|---|---|---|
| VP9, 6 Mb/s asked, chosen | 10.1 s | 5.8 Mb/s |
| VP9, 3 Mb/s | 8.8 s | 3.9 Mb/s |
| VP9, 12 Mb/s | 14.1 s | 9.0 Mb/s |
AV1 (av01.0.08M.08), 6 Mb/s |
9.6 s | 3.6 Mb/s |
| VP8, 6 Mb/s | 32.1 s | 6.0 Mb/s |
AV1 encodes for about VP9’s cost, but decoding it costs more: the same
clip as native AV1 (dav1d) took 4.2 s of renderer CPU per 16 s of playback,
as native VP9 1.3 to 1.4 s. VP9 at 0.1 bit a pixel a frame (6 Mb/s at
1080p30, clamped to 1.5–40 Mb/s) is what .video uses.
Where the time goes. Per process over 16 s of the H.264 clip below: renderer 10.6 to 11.6 s (the VP9 encode, Chromium’s VP9 decode, the shim), browser process 0.8 to 1.4 s (one copy of each frame, 93 MB/s at 1080p30), GPU process 0.7 to 1.3 s, media service 0.10 to 0.13 s: the decode is in hardware, also in the sandboxed service. The same clip as native VP9 without the shim: renderer 1.3 s, browser process 0.8 to 1.1 s, GPU process 1.1 to 1.6 s.
Against WebKit. A 30-second 1920×1080 clip at 30 fps (a scrolling
texture, a gradient, a moving square; H.264 High at 8 Mb/s or HEVC Main at
5 Mb/s, with AAC; made with AVFoundation), played by <video src> from a
local HTTP server for 25 s after its first frame, in the Compat example
(windowed) and in a WKWebView, three alternating runs each, median and
range. CPU is every process of the engine (the app, its helpers or WebKit’s
WebContent, GPU and Networking processes, and the media service) from 6 s
to about 24 s after launch; energy impact is top’s POWER column summed
over those processes (powermetrics needs root, which this machine’s
account does not have); memory is footprint’s phys_footprint summed.
Chromium, .video, H.264 |
WebKit, H.264 | Chromium, .video, HEVC |
WebKit, HEVC | |
|---|---|---|---|---|
| CPU, % of one core | 82 (81–101) | 11 (11–12) | 82 (79–89) | 15 (10–15) |
| Energy impact | 77 (70–91) | 9.7 (4.8–10.4) | 87 (74–103) | 12.8 (6.3–13.9) |
| Memory | 559 MB (547–582) | 152 MB | 537 MB (537–564) | 151 MB |
First frame after src |
577 ms (577–696) | 254 ms (229–304) | 596 ms (571–642) | 266 ms (221–275) |
| Frames dropped | 0 of 729 | 0 of 721 | 0 of 713 | 0 of 716 |
| Frame shown against the clock | −2.6 ms (−13 to +12) | 0.0 ms (±1) | −4.3 ms (−7 to +7) | −0.1 ms (±1) |
| Frame number read back | the clock’s frame | the clock’s frame | within one frame | the clock’s frame |
Native VP9 of the same clip in Chromium, for scale: 12 to 25 % CPU, 265 MB,
first frame in 290 to 310 ms. “Frame shown against the clock” is the
frame’s mediaTime less the element’s clock at its expectedDisplayTime
(requestVideoFrameCallback); both engines drive the clock from the
audio, so it is the picture’s offset from the sound. The frame number is
read from the picture (a row of blocks) every 15 frames.
So the route works and keeps up, at about seven times WebKit’s CPU and three and a half times its memory. Most of the memory is the renderer (300 MB against 100 MB for native VP9): libvpx’s encoder at 1080p and the frames in flight. Two things the numbers decided:
- Frames leave a request in presentation order but are encoded after every sample that shows earlier has been decoded. With B-frames a request of eight frames can end before a frame that shows inside it; a first version encoded each request on its own and lost one frame in eight at batch boundaries (609 of 729 frames). Holding a frame until no sample left to decode shows before it made it 729 of 729.
- The service keeps the last four replies’ surfaces out of the decoder’s pool. With two, the browser process’s copy took 9.9 s of CPU per 16 s instead of 1.0 s.
The renderer frees each frame’s 3 MB as soon as the encoder has it
(VideoFrame’s transfer, then ArrayBuffer.prototype.transfer(0)),
which took the renderer from 414 to 300 MB.
Seeking and start. A file’s first chunk is half a second, so the first frame waits for one hardware decode and one encode of fifteen frames; later chunks are two seconds, kept up to eight seconds ahead and ten behind. A seek outside what is buffered starts at the key frame before the target. Not measured: quality against the source (the second encode is lossy, at the bitrate above); 4K, where 0.1 bit a pixel is 25 Mb/s and the encoder has four times the pixels; MSE players under adaptive switching, where each new initialization segment starts a new decoder and encoder.
The direct route, measured
Since 2026-11-29 .video does not encode again where it can avoid it. An
element without native controls shows the service’s frames itself: the
renderer wraps each in a VideoFrame and writes it to a
MediaStreamTrackGenerator, the element’s srcObject. A clock element of
the shim’s, never in the document, plays the media: the AAC as FLAC, and in
place of the video a placeholder VP9 track of 64×64 black key frames at the
source’s times, so its clock, buffered, seeking and events are
Chromium’s. The page’s element answers for the clock element (time,
duration, paused, buffered, readyState, play(), pause(), the
media events, Web Audio’s createMediaElementSource), and at each
animation frame the frame the clock will be at when it reaches the screen
is written. The lead is corrected from requestVideoFrameCallback’s
display times (60 ms to start with); since, a worker writes the frames
(Frames as IOSurfaces, measured,
“Timing”). Frames are decoded half a second ahead; compressed samples are kept by time and decoded from the key frame
before a seek.
Measured as the table above, three alternating runs on a quieter machine (load average 1.6 to 3.5), median and range:
| Direct, H.264 | WebKit, H.264 | Direct, HEVC | WebKit, HEVC | |
|---|---|---|---|---|
| CPU, % of one core | 37 (37–38) | 16 (16–17) | 39 (37–39) | 16 (16) |
| Energy impact | 34.5 (32–35) | 14.0 (13–15) | 34.2 (32–35) | 14.1 (13.5–15) |
| Memory | 325 MB (315–326) | 148 MB | 323 MB (304–326) | 145 MB |
First frame after src |
269 ms (266–301) | 152 ms (151–216) | 278 ms (220–294) | 190 ms (181–196) |
| Frames dropped | 0 of 747 | 0 of 721 | 0 of 747 | 0 of 717 |
| Picture against the clock, 5th to 95th percentile | −8 to +29 ms | −0.9 to +0.7 ms | −24 to +31 ms | −0.9 to +0.7 ms |
| Frames within ±20 ms | 76–96 % | 100 % | 71–97 % | 100 % |
Against the VP9 route (82 % of a core, 550 MB, first frame in 0.6 s) it takes less than half the CPU and 60 % of the memory, with no second lossy encode. Against WebKit it takes 2.3 to 2.4 times the CPU and energy and 2.2 times the memory: the frames still cross three processes uncompressed (the service’s IOSurface, the browser process’s copy into shared memory, the renderer’s ArrayBuffer, then the upload to the GPU), 93 MB/s at 1080p30, where WebKit shows the decoder’s IOSurface as it is (the browser process’s copy is gone since: Frames as IOSurfaces, measured). Per 16 s: renderer 2.3 to 3.0 s, browser process 1.3 to 1.8 s, GPU process 0.9 to 1.3 s, the media service 0.1 s. The mean offset is under a millisecond; the spread is the display’s: 30 frames a second on a 60 Hz display, timed from animation frames, put some frames a refresh early or late, where WebKit presents each frame at its time.
Two things did not work:
- An ArrayBuffer over the message’s shared memory, to save the renderer’s
copy:
cef_v8_value_create_array_bufferalways returns null with V8’s sandbox, which CEF 158 has on. - On a loaded machine (another build running, 2 GB of swap in use), 5 of 11 launches ran in a second mode: browser process 10 to 11 s and renderer 8 s per 16 s, GPU process half its usual, with the same work done (113 decode requests, 900 frames written). Not explained then; it did not happen in the runs of the table. The instructions each process retires do not change between the modes (see Frames as IOSurfaces, measured): it is the same work at a lower clock or on the efficiency cores.
What a page can tell, beyond the VP9 route’s list: the forwarded media
events have isTrusted false; captureStream() on the element has no
audio track; picture in picture’s own play and pause act on the element’s
stream, not the clock (not tested); full screen was not tested. A
MediaSource takes the direct route only if the page has not asked
isTypeSupported or decodingInfo about VP8, VP9 or AV1 first (such a
page may well choose them, and they stay native); otherwise, and for
elements with native controls, video takes the VP9 route.
CEFSWIFT_DIRECT_VIDEO=0 in the app’s environment sends all of it there.
The other routes looked at for this:
- WebCodecs’ hardware encoders.
VideoEncoder.isConfigSupportedwithhardwareAcceleration: 'prefer-hardware'says yes foravc1.640028(VideoToolbox) and no for HEVC, VP9 and AV1; an H.264 re-encode is no use, since Chromium decodes noavc1(MediaSource.isTypeSupportedandVideoDecoder.isConfigSupportedare false). Dropped. - A cheaper VP9. WebCodecs exposes no speed setting (
cpu-used); real time is already libvpx’s fastest. Halving the bitrate saved 13 % of the encode (the table in “Which codec”); key frames already follow the source’s; dropping frames would drop frames. Not pursued: the direct route costs less than half.
Frames as IOSurfaces, measured
Since 2026-11-29 the browser process copies no pixels, the renderer
copies each frame once, when it shows it, and a worker writes the frames
at their refresh. Measured on 2026-11-29 with CEF 158.0.6 on macOS
27.2.1, an Apple M2 with 8 GB, with Chromium’s message loop (the default
since then), on a machine shared with other builds and benchmarks (load
average 1.2 to 24): the 1080p30 clips of the tables above, played by
bench.html for 22 s after the first frame, each process’s counters
from 6 s to 22 s after launch, footprint at 14 s. “Before” is the direct
route as first built (the table above’s code). Medians of sixteen
runs after, seven before, four of WebKit, interleaved; HEVC one each.
Instructions, not CPU time. On this machine the CPU time of a run
moved by up to half from one launch to the next with the same work done
(14 to 47 % of a core for the same build): a run on the efficiency
cores, or at a lower clock, takes longer for the same instructions. That
is the “second mode” above. The instructions each process retires
(proc_pid_rusage, ri_instructions) stayed within about a tenth from
run to run, so they are the measure here, in millions a second.
| H.264 | Before | After | WebKit |
|---|---|---|---|
| Instructions, millions a second, all processes | 660 (618–746) | 415 (367–458, one run at load 24: 629) | 370 (358–372) |
| browser process (WebKit: the app) | 186 | 81 | 29 |
| renderer | 333 | 221 | |
| GPU process | 103 | 75 | |
| network, audio and media service | 37 | 37 | |
| WebKit’s WebContent, GPU and Networking | 341 | ||
| Memory | 342 MB (323–358) | 320 MB (306–356) | 149 MB |
| of it the renderer’s | 109 MB | 79 MB | |
First frame after src |
383 ms (288–1152) | 134 ms (116–382) | 252 ms (157–379) |
| Frames dropped | 0 | 0 | 0 |
| Frame number read back | the clock’s frame | the clock’s frame | the clock’s frame |
| Frames within ±20 ms of the clock, each run | 69, 77, 80, 88, 90, 91, 96 % | 100 % in 14 runs; 81 and 96 % | 100 % |
| Picture against the clock, each run’s mean | 0 ms | −14 to +7 ms | 0 ms |
HEVC: 660, 374 and 362 million instructions a second, 346, 343 and
143 MB, first frame in 349, 160 and 256 ms, 90, 100 and 100 % of frames
within ±20 ms. The VP9 route (CEFSWIFT_DIRECT_VIDEO=0, measured before
the worker) changed little, its renderer’s encode being most of it:
6,448 and 6,295 million instructions a second (95 and 94 % of a core),
559 and 567 MB. An idle page, before Chromium’s loop was the default:
63 to 140 million instructions a second in this app (most of it CEF’s
external pump in the browser process), 18 in WebKit; 165 to 183 MB
against 68 to 71.
Chrome for Testing 158.0.8127.88, which decodes H.264 itself (in its GPU process), was to be the scale for Chrome’s own builds; launched from this harness its pages did not play (its child processes could not reach its Mach port rendezvous), so it has no row.
Timing. Before, each animation frame wrote the frame the clock would
be at when it reached the screen, by a lead steered from the frames’
error. Two things put a frame a refresh early or late, in 4 to 31 % of
frames a run. The lead cannot change the error but by a whole refresh,
so steering it walked the frames’ phase onto a refresh boundary; and a
frame written on the page’s main thread missed its refresh whenever the
page kept that thread busy (bench.html reads a frame back into a
canvas every fifteen). Now the renderer copies each frame into a
VideoFrame 150 ms ahead and hands it to a worker of the shim’s, which
holds the generator’s stream. The worker writes each frame halfway
between two refreshes (from the animation frames’ times, which the main
thread sends it), at the time the clock reaches the frame less the
latency to the screen it measures, and each frame’s slot follows the
last one’s by the frames’ spacing, so that the clock’s jitter cannot
split neighbours across a refresh; a drift of more than three quarters
of a refresh moves the slots. Each run’s picture then sits at a steady
offset from the sound within a refresh (−14 to +7 ms in these runs,
the picture late by at most 14 ms), where WebKit’s is 0. Two runs of
sixteen still had frames a refresh off (19 and 4 % of them), not
explained. Writing at the
refresh nearest the frame’s time from the main thread (no worker) gave
85 to 98 %; also steering the slots by the offset the page’s element
reports, 71 to 100 %.
What changed.
- The frame port. XPC hands the browser process the decoder’s IOSurfaces without a copy; the browser process used to copy each into the CEF message’s shared memory (93 MB/s at 1080p30), and the renderer to copy it again into an ArrayBuffer. Now the surfaces go on to the renderer as Mach ports (architecture, “The frame port”), and the browser process does no more work than for an idle page.
- Frames stay in the service until shown. The renderer holds a
decoded frame as its surface, marked in use so that the decoder’s pool
does not hand it out again, and copies it when the clock reaches it:
the half second decoded ahead no longer sits in the renderer’s heap.
The copy goes into one ArrayBuffer kept for the purpose, from which the
VideoFramecopies in turn; a new ArrayBuffer a frame,transferred to theVideoFrame, took about 20 million more instructions a second in the renderer (its memory mapped and faulted in each time). The surfaces stay mapped between frames, as the pool hands out the same few again; looking each up afresh took about 20 million more. - One placeholder frame a group of pictures, for files. The clock
element’s placeholder track had one tiny VP9 frame a video frame, and
each cost the GPU process too (27 million instructions a second at 30
fps). For a file, whose MediaSource is the shim’s and never the page’s,
it now has one a group of pictures, as long as the group. A page’s
MediaSource keeps one a frame: its
bufferedafter aremovethat ends inside a group must stay what it was. - The first frame. The first frame waited for the service’s launch,
VideoToolbox’s first session in it (about 70 ms) and, on the service’s
one queue, the decode of the file’s first ten seconds of audio. Now the
shim asks for the service when a page sets a media file as a
srcor asks about a type it plays (cefswift.media.prepare), which starts it and opens a session; audio and video decode on a queue each; the first chunk of a file with video is half a second; and the first request after a start or seek is the key frame alone.
Where it goes now. The browser process’s 81 million instructions a
second are about what it spends on an idle page (with CEF’s external
pump, before Chromium’s loop was the default, 51 to 112 million; WebKit’s
idle page: 18 million for all its processes). Writing no frame at all to the element (decoding,
the clock element and the sound only) took the renderer 78 million and
the GPU process 39; copying the frames but not writing them, the renderer
180 (before the changes above). The rest is Chromium’s own way with a
MediaStreamTrackGenerator’s frames: the renderer copies each into a
GpuMemoryBuffer on its worker threads, the GPU process composites it,
and the browser process draws the window’s layer. A page’s JavaScript has
no way to hand Chromium a frame already on the GPU, and CEF’s API none to
hand it an IOSurface.
What did not work, or was not used.
- IOSurfaces looked up by a global identifier (
kIOSurfaceIsGlobal,IOSurfaceLookup): the renderer’s sandbox allows it and it saved as much as the frame port, but any process could then read a page’s frames. - Animation frames only when a frame is due, a timer in between: no change in any process. Writing half a refresh after each animation frame, from the main thread: no better.
- An
<audio>element as the clock, which decodes no video at all: no better than one placeholder frame a group of pictures. - Starting the service with the runtime: the first frame would no longer wait for its launch, but every app with the option would run it from launch; not done.