百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

web-demuxer

> 开发工具
开源

在浏览器中使用 WebAssembly 解封装媒体文件,专为 WebCodecs 设计

192 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

在浏览器中使用 WebAssembly 解封装媒体文件,专为 WebCodecs 设计

English | 简体中文

Web-Demuxer

Demux media files in the browser using WebAssembly, designed for WebCodecs.

Overview

WebCodecs provides decoding capabilities but lacks demuxing functionality. While mp4box.js is excellent for MP4 files, it only supports MP4 format. Web-Demuxer aims to support a wide range of multimedia formats in one package, specifically designed for seamless WebCodecs integration.

Features

  • WebCodecs-First Design - API optimized for WebCodecs development with intuitive methods
  • Multi-Format Support - Handle mov/mp4/mkv/webm/flv/m4v/wmv/avi/ts and more formats
  • Customizable Build - Configure and build demuxers for specific formats only
  • Rich Media Info - Extract detailed metadata similar to ffprobe output

Quick Start

bash
npm install web-demuxer
…

Installation

NPM

bash
npm install web-demuxer

CDN

xml

WASM File Setup

‼️ Important: Place the WASM file in your static directory (e.g., public/) for proper loading.

typescript
const demuxer = new WebDemuxer({
  // Option 1: Use CDN
  wasmFilePath: "https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm",
  
  // Option 2: Use local file
  // Copy dist/wasm-files/web-demuxer.wasm from npm package to public directory
  // You can use plugins like vite-plugin-static-copy to sync automatically
  // If JS and WASM are in the same public directory, wasmFilePath can be omitted
  // wasmFilePath: "/path/to/your/public/web-demuxer.wasm"
});

Live Examples

  • Seek Video Frame | Source Code
  • Play Video | Source Code

API

Constructor

new WebDemuxer(options?: WebDemuxerOptions)

Creates a new WebDemuxer instance.

Parameters:

  • options.wasmFilePath (optional): Custom WASM file path. Defaults to looking for web-demuxer.wasm in the script directory.

Core Methods

load(source: File | string): Promise

Loads a media file and initializes the WASM worker.

Parameters:

  • source: File object or URL string

Note: All subsequent methods require successful load() execution.

getDecoderConfig(type: MediaType): Promise

Gets WebCodecs decoder configuration.

Parameters:

  • type: 'video' or 'audio'

Returns: VideoDecoderConfig or AudioDecoderConfig

seek(type: MediaType, time: number, seekFlag?: AVSeekFlag): Promise

Seeks to specific time and returns encoded chunk.

Parameters:

  • type: 'video' or 'audio'
  • time: Time in seconds
  • seekFlag: Seek direction (default: backward)

Returns: EncodedVideoChunk or EncodedAudioChunk

read(type: MediaType, start?: number, end?: number, seekFlag?: AVSeekFlag): ReadableStream

Creates a stream of encoded chunks.

Parameters:

  • type: 'video' or 'audio'
  • start: Start time in seconds (default: 0)
  • end: End time in seconds (default: end of file)
  • seekFlag: Seek direction (default: backward)

Returns: ReadableStream of encoded chunks

Media Information

getMediaInfo(): Promise

Extracts comprehensive media metadata (similar to ffprobe output).

Returns:

Example Response (Click to expand)

…

getMediaStream(type: MediaType, streamIndex?: number): Promise

Gets information about a specific media stream.

Parameters:

  • type: 'video', 'audio' or 'subtitle'
  • streamIndex: Stream index (optional)

Low-Level Packet Access

seekMediaPacket(type: MediaType, time: number, seekFlag?: AVSeekFlag): Promise

Gets raw media packet at specific time.

Parameters:

  • type: Media type ('video', 'audio' or 'subtitle')
  • time: Time in seconds
  • seekFlag: Seek direction (default: backward seek)

readMediaPacket(type: MediaType, start?: number, end?: number, seekFlag?: AVSeekFlag): ReadableStream

Returns a ReadableStream for streaming raw media packet data.

Parameters:

  • type: Media type ('video', 'audio' or 'subtitle')
  • start: Start time in seconds (default: 0)
  • end: End time in seconds (default: 0, read till end)
  • seekFlag: Seek direction (default: backward seek)

Utility Methods

setLogLevel(level: AVLogLevel): void

Sets logging verbosity level for debugging purposes.

Parameters:

  • level: Log level (see AVLogLevel for available options)

destroy(): void

Cleans up resources and terminates worker.

Custom Demuxer

Web-Demuxer provides two pre-built versions:

Version Size (gzipped) Supported Formats
Full (web-demuxer.wasm) 1131 kB mov, mp4, avi, flv, mkv, webm, mpeg, asf, mpegts, etc.
Mini (web-demuxer-mini.wasm) 493 kB mov, mp4, mkv, webm, m4v

Building Custom Version

For specific format support, customize the build:

  1. Configure formats in Makefile:
makefile
DEMUX_ARGS = \
    --enable-demuxer=mov,mp4,m4a,3gp,3g2,mj2
  1. Start Docker environment:
bash
# For ARM64 (Apple Silicon)
npm run dev:docker:arm64

# For x86_64 (Intel/AMD)
npm run dev:docker:x86_64
  1. Build custom WASM:
bash
npm run build:wasm

License

This project is licensed under the MIT License for the main codebase.
The lib/ directory contains FFmpeg-derived code under the LGPL License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptaudiodemuxdemuxermedia

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具