Repository navigation
Play WebM in the video preview when FFmpeg cannot open the container - #343725
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Codec detection can reject valid WebM files, and failed non-WebM videos are unnecessarily loaded entirely into memory.
2 open issues
What changed in this PR
Adds a Media Source Extensions fallback to VS Code’s video preview so WebM files can play when the shipped FFmpeg cannot open their container, addressing issue #195758.
Changes:
- Preserves direct playback and attempts a one-time fallback for unsupported video sources.
- Detects WebM codecs and appends the fetched file to a matching MediaSource buffer.
- Updates the Content Security Policy to allow resource fetching and blob media URLs.
| File | Description |
|---|---|
src/vs/workbench/contrib/mediaPreview/browser/mediaPlayerEditorInput.ts |
Adds WebM fallback playback and the required Content Security Policy permissions. |
Review effort: Balanced
Comment on lines
+306
to
+307
| const header = Array.from(bytes.subarray(0, 65536), byte => String.fromCharCode(byte)).join(''); | ||
| const codecs = Object.keys(webmCodecs).filter(id => header.includes(id)).map(id => webmCodecs[id]); |
Comment on lines
+315
to
+316
| const bytes = new Uint8Array(await response.arrayBuffer()); | ||
| const type = getWebmType(bytes); |
…them Shipped Electron builds use an FFmpeg without the WebM/Matroska demuxer, so <video src> fails with DEMUXER_ERROR_COULD_NOT_OPEN. When a video fails with MEDIA_ERR_SRC_NOT_SUPPORTED, read the file, detect its WebM codecs, and play it through MediaSource, which parses WebM in Chromium itself. Refs #195758 Co-authored-by: Copilot <[email protected]>
Henning Dieterichs (hediet)
force-pushed
the
hediet/webm-preview-mse
branch
from
October 23, 2026 09:32
7412331 to
421ab1e
Compare
Martin Aeschlimann (aeschli)
previously approved these changes
Oct 23, 2026
Joaquín Ruales (jruales)
previously approved these changes
Oct 23, 2026
Co-authored-by: Copilot <[email protected]>
Henning Dieterichs (hediet)
dismissed stale reviews from Joaquín Ruales (jruales) and Martin Aeschlimann (aeschli)
via
October 23, 2026 14:55
0410166
Giuseppe Cianci (Giuspepe)
previously approved these changes
Oct 23, 2026
Stream the file instead of reading it at once: stop at the first bytes when it is not WebM, and give up above 200 MB. This only applies after normal playback has already failed, so videos that play natively are unaffected. Co-authored-by: Copilot <[email protected]>
Aiday Marlen Kyzy (aiday-mar)
approved these changes
Oct 23, 2026
Ross Wollman (rwoll)
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Refs #195758
Note
This is a workaround. #195758 tracks adding WebM support to the FFmpeg that VS Code ships. Once that lands, the fallback is no longer reached and should be removed; the code links to the issue.
WebM videos don't play in VS Code's video preview: opening one shows "An error occurred while loading the video file." Shipped VS Code builds use an FFmpeg built without the WebM/Matroska container, so
<video src>fails withPipelineStatus::DEMUXER_ERROR_COULD_NOT_OPEN: FFmpegDemuxer: open context failed, even though the VP8/VP9 decoders are present andcanPlayTypereports WebM as supported. This also affects WebM recordings made by Playwright'spage.screencast.This change makes the video preview fall back to Media Source Extensions when that happens. MediaSource parses WebM in Chromium itself, without FFmpeg's demuxer.
Changes
<video src>first, so MP4, and WebM on builds whose FFmpeg supports it, behave as before.MEDIA_ERR_SRC_NOT_SUPPORTED, the webview fetches the file and checks for the WebM/Matroska signature. It reads the codecs from the header (VP8, VP9, AV1, Opus, Vorbis), creates aMediaSourcewith a matchingSourceBuffer, and appends the bytes. If anything fails, it shows the existing error message.blob:for media andconnect-srcto the webview resource origin.The fallback streams the file and is bounded so it cannot make already-failing files worse: it stops after the first bytes when the file isn't WebM, and gives up above 200 MB, showing the existing error message. These limits only apply after normal playback has failed, so videos that play natively are unaffected.
Before and after
Recorded in Code OSS from this branch. To reproduce the shipped behavior, the dev build's
ffmpeg.dllwas temporarily replaced with the one from Insiders 1.143.0 (20f16aa534). Both recordings open the sameevidence-todo.webmfrom the Explorer, withmediaPreview.video.autoPlayenabled.Before: the preview shows the load error.
(video to be attached)
After: the same file plays.
(video to be attached)
How to test
page.screencast.Validation:
scripts\test.bat --grep "Media Preview": 14 passing.mediaPlayerEditorInput.ts: no problems.ffmpeg.dll:.mp4that isn't a video shows the error after 0.5 s, without reading the file.Content-Length).<video>element, then played and seeked through MediaSource.Not tested on macOS or Linux.