{"id":28468499,"url":"https://github.com/bilibili/web-demuxer","last_synced_at":"2026-04-06T03:03:47.463Z","repository":{"id":242373137,"uuid":"809412428","full_name":"bilibili/web-demuxer","owner":"bilibili","description":"Demux media files in the browser using WebAssembly, designed for WebCodecs 在浏览器中实现媒体文件的解封装，专为WebCodecs设计","archived":false,"fork":false,"pushed_at":"2025-08-18T16:19:16.000Z","size":3725,"stargazers_count":140,"open_issues_count":3,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-23T10:55:20.211Z","etag":null,"topics":["audio","demux","demuxer","media","typescript","video","webassembly","webcodecs"],"latest_commit_sha":null,"homepage":"https://foreversc.github.io/web-demuxer/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bilibili.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-02T16:06:59.000Z","updated_at":"2025-08-20T00:17:22.000Z","dependencies_parsed_at":"2025-06-25T20:41:22.823Z","dependency_job_id":null,"html_url":"https://github.com/bilibili/web-demuxer","commit_stats":null,"previous_names":["foreversc/web-demuxer"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/bilibili/web-demuxer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2Fweb-demuxer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2Fweb-demuxer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2Fweb-demuxer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2Fweb-demuxer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bilibili","download_url":"https://codeload.github.com/bilibili/web-demuxer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bilibili%2Fweb-demuxer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278802788,"owners_count":26048565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audio","demux","demuxer","media","typescript","video","webassembly","webcodecs"],"created_at":"2025-06-07T08:07:42.360Z","updated_at":"2026-04-06T03:03:47.447Z","avatar_url":"https://github.com/bilibili.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003ch4 align=\"right\"\u003e\u003cstrong\u003eEnglish\u003c/strong\u003e | \u003ca href=\"https://github.com/ForeverSc/web-demuxer/blob/main/README_CN.md\"\u003e简体中文\u003c/a\u003e\u003c/h4\u003e\n\u003ch1 align=\"center\"\u003eWeb-Demuxer\u003c/h1\u003e\n\u003cp align=\"center\"\u003eDemux media files in the browser using WebAssembly, designed for WebCodecs.\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/web-demuxer\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/web-demuxer\" alt=\"version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/web-demuxer\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/web-demuxer\" alt=\"downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.jsdelivr.com/package/npm/web-demuxer\"\u003e\u003cimg src=\"https://data.jsdelivr.com/v1/package/npm/web-demuxer/badge\" alt=\"hits\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## Overview\n\nWebCodecs 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.\n\n## Features\n\n- 🪄 **WebCodecs-First Design** - API optimized for WebCodecs development with intuitive methods\n- 📦 **Multi-Format Support** - Handle mov/mp4/mkv/webm/flv/m4v/wmv/avi/ts and more formats\n- 🧩 **Customizable Build** - Configure and build demuxers for specific formats only\n- 🔧 **Rich Media Info** - Extract detailed metadata similar to ffprobe output\n\n## Quick Start\n\n```bash\nnpm install web-demuxer\n```\n\n```typescript\nimport { WebDemuxer } from \"web-demuxer\";\n\nconst demuxer = new WebDemuxer();\n\n// Example: Get video frame at specific time\nasync function seek(file, time) {\n  // 1. Load video file\n  await demuxer.load(file);\n\n  // 2. Demux video file and generate VideoDecoderConfig and EncodedVideoChunk required by WebCodecs\n  const videoDecoderConfig = await demuxer.getDecoderConfig('video');\n  const videoEncodedChunk = await demuxer.seek('video', time);\n\n  // 3. Decode video frame through WebCodecs\n  const decoder = new VideoDecoder({\n    output: (frame) =\u003e {\n      // Render frame, e.g., using canvas drawImage\n      frame.close();\n    },\n    error: (e) =\u003e {\n      console.error('video decoder error:', e);\n    }\n  });\n\n  decoder.configure(videoDecoderConfig);\n  decoder.decode(videoEncodedChunk);\n  decoder.flush();\n}\n```\n\n## Installation\n\n### NPM\n```bash\nnpm install web-demuxer\n```\n\n### CDN\n```html\n\u003cscript type=\"module\"\u003e\n  import { WebDemuxer } from 'https://cdn.jsdelivr.net/npm/web-demuxer/+esm';\n\u003c/script\u003e\n```\n\n### WASM File Setup\n\n**‼️ Important:** Place the WASM file in your static directory (e.g., `public/`) for proper loading.\n\n```typescript\nconst demuxer = new WebDemuxer({\n  // Option 1: Use CDN\n  wasmFilePath: \"https://cdn.jsdelivr.net/npm/web-demuxer@latest/dist/wasm-files/web-demuxer.wasm\",\n  \n  // Option 2: Use local file\n  // Copy dist/wasm-files/web-demuxer.wasm from npm package to public directory\n  // You can use plugins like vite-plugin-static-copy to sync automatically\n  // If JS and WASM are in the same public directory, wasmFilePath can be omitted\n  // wasmFilePath: \"/path/to/your/public/web-demuxer.wasm\"\n});\n```\n\n## Live Examples\n- [Seek Video Frame](https://bilibili.github.io/web-demuxer/#example-seek) | [Source Code](https://github.com/bilibili/web-demuxer/blob/main/index.html#L131-L157)\n- [Play Video](https://bilibili.github.io/web-demuxer/#example-play) | [Source Code](https://github.com/bilibili/web-demuxer/blob/main/index.html#L159-L197)\n\n## API\n\n### Constructor\n\n#### `new WebDemuxer(options?: WebDemuxerOptions)`\n\nCreates a new WebDemuxer instance.\n\n**Parameters:**\n- `options.wasmFilePath` (optional): Custom WASM file path. Defaults to looking for `web-demuxer.wasm` in the script directory.\n\n### Core Methods\n\n#### `load(source: File | string): Promise\u003cvoid\u003e`\n\nLoads a media file and initializes the WASM worker.\n\n**Parameters:**\n- `source`: File object or URL string\n\n**Note:** All subsequent methods require successful `load()` execution.\n\n#### `getDecoderConfig(type: MediaType): Promise\u003cVideoDecoderConfig | AudioDecoderConfig\u003e`\n\nGets WebCodecs decoder configuration.\n\n**Parameters:**\n- `type`: `'video'` or `'audio'`\n\n**Returns:** `VideoDecoderConfig` or `AudioDecoderConfig`\n\n#### `seek(type: MediaType, time: number, seekFlag?: AVSeekFlag): Promise\u003cEncodedVideoChunk | EncodedAudioChunk\u003e`\n\nSeeks to specific time and returns encoded chunk.\n\n**Parameters:**\n- `type`: `'video'` or `'audio'`\n- `time`: Time in seconds\n- `seekFlag`: Seek direction (default: backward)\n\n**Returns:** `EncodedVideoChunk` or `EncodedAudioChunk`\n\n#### `read(type: MediaType, start?: number, end?: number, seekFlag?: AVSeekFlag): ReadableStream\u003cEncodedVideoChunk | EncodedAudioChunk\u003e`\n\nCreates a stream of encoded chunks.\n\n**Parameters:**\n- `type`: `'video'` or `'audio'`\n- `start`: Start time in seconds (default: 0)\n- `end`: End time in seconds (default: end of file)\n- `seekFlag`: Seek direction (default: backward)\n\n**Returns:** `ReadableStream` of encoded chunks\n\n### Media Information\n\n#### `getMediaInfo(): Promise\u003cWebMediaInfo\u003e`\n\nExtracts comprehensive media metadata (similar to ffprobe output).\n\n**Returns:**\n\n\u003cdetails\u003e\n\u003csummary\u003e📋 Example Response (Click to expand)\u003c/summary\u003e\n\n```json\n{\n    \"format_name\": \"mov,mp4,m4a,3gp,3g2,mj2\",\n    \"duration\": 263.383946,\n    \"bit_rate\": \"6515500\",\n    \"start_time\": 0,\n    \"nb_streams\": 2,\n    \"streams\": [\n        {\n            \"id\": 1,\n            \"index\": 0,\n            \"codec_type\": 0,\n            \"codec_type_string\": \"video\",\n            \"codec_name\": \"h264\",\n            \"codec_string\": \"avc1.640032\",\n            \"color_primaries\": \"bt2020\",\n            \"color_range\": \"tv\",\n            \"color_space\": \"bt2020nc\",\n            \"color_transfer\": \"arib-std-b67\",\n            \"profile\": \"High\",\n            \"pix_fmt\": \"yuv420p\",\n            \"level\": 50,\n            \"width\": 1080,\n            \"height\": 2336,\n            \"channels\": 0,\n            \"sample_rate\": 0,\n            \"sample_fmt\": \"u8\",\n            \"bit_rate\": \"6385079\",\n            \"extradata_size\": 36,\n            \"extradata\": \"Uint8Array\",\n            \"r_frame_rate\": \"30/1\",\n            \"avg_frame_rate\": \"30/1\",\n            \"sample_aspect_ratio\": \"N/A\",\n            \"display_aspect_ratio\": \"N/A\",\n            \"start_time\": 0,\n            \"duration\": 263.33333333333337,\n            \"rotation\": 0,\n            \"nb_frames\": \"7900\",\n            \"tags\": {\n                \"creation_time\": \"2023-12-10T15:50:56.000000Z\",\n                \"language\": \"und\",\n                \"handler_name\": \"VideoHandler\",\n                \"vendor_id\": \"[0][0][0][0]\"\n            }\n        },\n        {\n            \"id\": 2,\n            \"index\": 1,\n            \"codec_type\": 1,\n            \"codec_type_string\": \"audio\",\n            \"codec_name\": \"aac\",\n            \"codec_string\": \"mp4a.40.2\",\n            \"profile\": \"\",\n            \"pix_fmt\": \"\",\n            \"level\": -99,\n            \"width\": 0,\n            \"height\": 0,\n            \"channels\": 2,\n            \"sample_rate\": 44100,\n            \"sample_fmt\": \"\",\n            \"bit_rate\": \"124878\",\n            \"extradata_size\": 2,\n            \"extradata\": \"Uint8Array\",\n            \"r_frame_rate\": \"0/0\",\n            \"avg_frame_rate\": \"0/0\",\n            \"sample_aspect_ratio\": \"N/A\",\n            \"display_aspect_ratio\": \"N/A\",\n            \"start_time\": 0,\n            \"duration\": 263.3839455782313,\n            \"rotation\": 0,\n            \"nb_frames\": \"11343\",\n            \"tags\": {\n                \"creation_time\": \"2023-12-10T15:50:56.000000Z\",\n                \"language\": \"und\",\n                \"handler_name\": \"SoundHandler\",\n                \"vendor_id\": \"[0][0][0][0]\"\n            }\n        }\n    ]\n}\n```\n\u003c/details\u003e\n\n#### `getMediaStream(type: MediaType, streamIndex?: number): Promise\u003cWebAVStream\u003e`\n\nGets information about a specific media stream.\n\n**Parameters:**\n- `type`: `'video'`, `'audio'` or `'subtitle'`\n- `streamIndex`: Stream index (optional)\n\n### Low-Level Packet Access\n\n#### `seekMediaPacket(type: MediaType, time: number, seekFlag?: AVSeekFlag): Promise\u003cWebAVPacket\u003e`\n\nGets raw media packet at specific time.\n\n**Parameters:**\n- `type`: Media type (`'video'`, `'audio'` or `'subtitle'`)\n- `time`: Time in seconds\n- `seekFlag`: Seek direction (default: backward seek)\n\n#### `readMediaPacket(type: MediaType, start?: number, end?: number, seekFlag?: AVSeekFlag): ReadableStream\u003cWebAVPacket\u003e`\n\nReturns a `ReadableStream` for streaming raw media packet data.\n\n**Parameters:**\n- `type`: Media type (`'video'`, `'audio'` or `'subtitle'`)\n- `start`: Start time in seconds (default: 0)\n- `end`: End time in seconds (default: 0, read till end)\n- `seekFlag`: Seek direction (default: backward seek)\n\n### Utility Methods\n\n#### `setLogLevel(level: AVLogLevel): void`\n\nSets logging verbosity level for debugging purposes.\n\n**Parameters:**\n- `level`: Log level (see `AVLogLevel` for available options)\n\n#### `destroy(): void`\n\nCleans up resources and terminates worker.\n\n## Custom Demuxer\n\nWeb-Demuxer provides two pre-built versions:\n\n| Version | Size (gzipped) | Supported Formats |\n|---------|----------------|-------------------|\n| **Full** (`web-demuxer.wasm`) | 1131 kB | mov, mp4, avi, flv, mkv, webm, mpeg, asf, mpegts, etc. |\n| **Mini** (`web-demuxer-mini.wasm`) | 493 kB | mov, mp4, mkv, webm, m4v |\n\n\n### Building Custom Version\n\nFor specific format support, customize the build:\n\n1. **Configure formats** in `Makefile`:\n```makefile\nDEMUX_ARGS = \\\n    --enable-demuxer=mov,mp4,m4a,3gp,3g2,mj2\n```\n\n2. **Start Docker environment**:\n```bash\n# For ARM64 (Apple Silicon)\nnpm run dev:docker:arm64\n\n# For x86_64 (Intel/AMD)\nnpm run dev:docker:x86_64\n```\n\n3. **Build custom WASM**:\n```bash\nnpm run build:wasm\n```\n\n## License\n\nThis project is licensed under the MIT License for the main codebase.  \nThe `lib/` directory contains FFmpeg-derived code under the LGPL License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilibili%2Fweb-demuxer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbilibili%2Fweb-demuxer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbilibili%2Fweb-demuxer/lists"}