跨域拉流需在视频服务器正确配置 Access-Control-Allow-Origin 头;不支持 mpeg2video 编码;iOS 17.0 及更早版本不可用,需 17.1+ 的 ManagedMediaSource。
npm install --save mpegts.jsREADME 未说明显存或 GPU 型号要求;运行在浏览器中,由浏览器做硬件加速,支持 Chrome、FireFox、Safari、Edge 等 Chromium 系浏览器。
浏览器端 MPEG2-TS/FLV 播放器,把直播流低延迟送进 video 标签
基于 MSE 的 HTML5 播放器,能在浏览器里直接播放 MPEG2-TS 和 FLV 格式的直播流,省去转封装或插件依赖。
核心能力
- 将 MPEG2-TS 转封装为 fMP4 后经 MSE 播放
- 支持 HTTP(S) 与 WebSocket 传输的 TS/FLV 流
- 支持 H.264/H.265、AAC 及 AV1、Opus、FLAC 等编码
- 自动追帧调整播放速率以压低直播延迟
- 可回调 PES 私有数据与 Timed ID3 元数据
容易踩的坑
- v1.8.2最新正式版2026-08-14 · 2026-08-14 06:18 UTC
Bugfix
- Fixed WebWorker feature (
enableWorker/enableWorkerForMSE) which was broken in shipped v1.8.1 due to webpack 4 -> 5 migration
Full Changelog: https://github.com/xqq/mpegts.js/compare/v1.8.1...v1.8.2
- Fixed WebWorker feature (
- v1.8.12026-08-06 · 2026-08-06 05:38 UTC
查看更新说明
New features and enhancements
- Migrated to Webpack 5 + TypeScript 5.9.3
- Support PGS (HDMV Subtitle) in MPEG-TS by @monyone in https://github.com/xqq/mpegts.js/pull/231
- Support PCM Audio in FLV (Legacy) by @monyone in https://github.com/xqq/mpegts.js/pull/235
- Add SEI_ARRIVED event by @duiniuluantanqin in https://github.com/xqq/mpegts.js/pull/286
Bugfix and improvements
- Moved xqq/webworkify-webpack GitHub dependency into built-in shim, which could cause a freeze during npm install
- Fixed iOS 26 MediaSource / ManagedMediaSource detection by @renoanzhou in https://github.com/xqq/mpegts.js/pull/252 @ahjsrhj in https://github.com/xqq/mpegts.js/pull/278
- Fixed playback stuck issue that occurred on iOS 26 Safari / macOS 26.5 Safari, where disabling silent AAC insertion for Safari caused the audio timeline to accumulate and shorten, resulting in playback getting stuck on Safari 26.5 and later by @tsukumijima in https://github.com/xqq/mpegts.js/pull/293
New Contributors
- @duiniuluantanqin made their first contribution in https://github.com/xqq/mpegts.js/pull/286
- @renoanzhou made their first contribution in https://github.com/xqq/mpegts.js/pull/252
Full Changelog: https://github.com/xqq/mpegts.js/compare/v1.8.0...v1.8.1
- v1.8.02024-12-24 · 2024-12-24 14:45 UTC
查看更新说明
New version after a long period with many changes
New features and enhancements
- Support working on iOS Safari with iOS 17.1+ through Apple's ManagedMediaSource API by @monyone in https://github.com/xqq/mpegts.js/pull/137
- Great performance improvements by supporting MSE in Workers on Chrome, Safari 18 (includes iOS) by @xqq in https://github.com/xqq/mpegts.js/pull/140
- You need to turn on the
config.enableWorkerForMSEto betruemanually
- You need to turn on the
- Support playback for AV1 over MPEG-TS by @monyone in https://github.com/xqq/mpegts.js/pull/138
- Support playback for AV1 over HTTP-FLV defined in Enhanced RTMP by @monyone in https://github.com/xqq/mpegts.js/pull/101
- Support chasing live latency more smoothly by changing playback rate by @FredZeng in https://github.com/xqq/mpegts.js/pull/54
- You need to turn on the
config.liveSyncto betrueand adjust other related parameters manually
- You need to turn on the
- Support ATSC EAC-3 audio codec in MPEG-TS by @monyone in https://github.com/xqq/mpegts.js/pull/103
- Support Opus audio codec over HTTP-FLV (Enhanced RTMP) by @monyone in https://github.com/xqq/mpegts.js/pull/193
- Support FLAC audio codec over HTTP-FLV (Enhanced RTMP) by @monyone in https://github.com/xqq/mpegts.js/pull/196
Bugfix and improvements
- Support handling timestamp wraparound in MPEG-TS by @wakabayashik in https://github.com/xqq/mpegts.js/pull/175
- Support "ManagedMediaSource in Worker" which is supported from iOS 18 by @tsukumijima in https://github.com/xqq/mpegts.js/pull/211
- Allow hevc config version to be 0 or 1 by @dexbol in https://github.com/xqq/mpegts.js/pull/153
- Fix: vui_hrd_parameters by @monyone in https://github.com/xqq/mpegts.js/pull/106
- Fix: HEVC hrd_parameters_present by @monyone in https://github.com/xqq/mpegts.js/pull/110
- Fix: correct hevc nalutype for FLV by @monyone in https://github.com/xqq/mpegts.js/pull/160
- Fix: Little Endian to Big Endian conversion for Opus (eFLV) by @monyone in https://github.com/xqq/mpegts.js/pull/195
- fixed: busy loop caused by invalid frame_size_code in AC-3 data by @wakabayashik in https://github.com/xqq/mpegts.js/pull/179
- fixed: stall when unbuffered seek to position 0 with audio codec mp3 by @wakabayashik in https://github.com/xqq/mpegts.js/pull/182
- fix safari cannot play ts file problem. by @suzp1984 in https://github.com/xqq/mpegts.js/pull/188
- fix removal of startstreaming event listener when using MME by @dbussert in https://github.com/xqq/mpegts.js/pull/210
Misc
- feat: code cleanup by @FredZeng in https://github.com/xqq/mpegts.js/pull/120
- Add and fire player destroying events by @evoactivity in https://github.com/xqq/mpegts.js/pull/124
- Feat: Support sync/async KLV metadata in MPEG-TS by @monyone in https://github.com/xqq/mpegts.js/pull/131
- feat: support 'liveBufferChasingOnPaused' config by @FredZeng in https://github.com/xqq/mpegts.js/pull/144
- swap audioTrack/videoTrack position in BaseDemuxer.nDataAvailable by @suzp1984 in https://github.com/xqq/mpegts.js/pull/187
- v1.7.32023-04-07 · 2023-04-07 13:01 UTC
查看更新说明
- Support Enhanced RTMP / HEVC for FLV.
- Support Opus and ATSC AC-3 audio codec for MPEG-TS.
- Support LOAS AAC for MPEG-TS.
- Some HEVC-related bug fixes.
by @monyone
- v1.7.22023-01-01 · 2023-01-01 07:30 UTC
查看更新说明
- Support MP3 audio codec over MPEG-TS
- Fix keyframe detection for Open-GOP HEVC Stream in MPEG-TS
by @monyone
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
mpegts.js 
HTML5 MPEG2-TS stream player written in TypeScript & JavaScript.
mpegts.js is optimized for low-latency live stream playback, such as DVB/ISDB television or surveillance cameras.
This project is based on flv.js.
Overview
mpegts.js works by transmuxing MPEG2-TS stream into ISO BMFF (Fragmented MP4) segments, followed by feeding mp4 segments into an HTML5 <video> element through Media Source Extensions API.
News
-
v1.8.0
Support working on iOS Safari with iOS 17.1+ through Apple's ManagedMediaSource API
Great performance improvements by supporting MSE in Workers on Chrome, Safari 18 (includes iOS)
Introduced support for AV1 over MPEG-TS
Introduced support for AV1 over HTTP-FLV defined in Enhanced RTMP
Support chasing live latency more smoothly by changing playback rate
Introduced ATSC EAC-3 audio codec in MPEG-TS
Support Opus and FLAC audio codec over HTTP-FLV (Enhanced RTMP)
-
v1.7.3
Introduced Enhanced RTMP with HEVC support for FLV.
Introduced Opus and ATSC AC-3 audio codec support for MPEG-TS.
Introduced LOAS AAC support for MPEG-TS.
-
v1.7.0
Introduced H.265/HEVC over MPEG-TS/FLV support.
Demo
http://xqq.github.io/mpegts.js/demo/
Features
- Playback for MPEG2-TS stream with H.264/H.265 + AAC codec transported in http(s) or WebSocket
- Playback for FLV stream with H.264/H.265 + AAC codec transported in http(s) or WebSocket
- Extremely low latency of less than 1 second in the best case
- Playback for
.m2tsfile like BDAV/BDMV with 192 bytes TS packet, or 204 bytes TS packet - Support handling dynamic codec parameters change (e.g. video resolution change)
- Support Chrome, FireFox, Safari, Edge (Old or Chromium) or any Chromium-based browsers
- Support chasing latency automatically for internal buffer of HTMLMediaElement
- Low CPU overhead and low memory usage (JS heap takes about 10MiB for each instance)
- Support extracting PES private data (stream_type=0x06) like ARIB B24 subtitles (with aribb24.js)
- Support Timed ID3 Metadata (stream_type=0x15) callback (TIMED_ID3_METADATA_ARRIVED)
CORS
If you use standalone video server for MPEG2-TS stream, Access-Control-Allow-Origin header must be configured correctly on video server for cross-origin resource fetching.
See cors.md for more details.
Installation
npm install --save mpegts.js
Build
npm install # install dev-dependencies
npm install -g webpack-cli # install build tool
npm run build # packaged & minimized js will be emitted in dist folder
cnpm mirror is recommended if you are in Mainland China.
Getting Started
<script src="mpegts.js"></script>
<video id="videoElement"></video>
<script>
if (mpegts.getFeatureList().mseLivePlayback) {
var videoElement = document.getElementById('videoElement');
var player = mpegts.createPlayer({
type: 'mse', // could also be mpegts, m2ts, flv
isLive: true,
url: 'http://example.com/live/livestream.ts'
});
player.attachMediaElement(videoElement);
player.load();
player.play();
}
</script>
mpegts.js could be tested with Simple Realtime Server.
TODO
- MPEG2-TS static file playback (seeking is not supported now)
Limitations
- mpeg2video is not supported
- HTTP MPEG2-TS live stream could not work on old browsers like IE11
- mpegts.js is not usable on iOS version 17.0 or older caused by the banning of Media Source Extensions (available on iPadOS), iOS 17.1 works through Managed Media Source API
Features inherited from flv.js
- FLV container with H.264 + AAC / MP3 codec playback
- Multipart segmented video playback
- HTTP FLV low latency live stream playback
- FLV over WebSocket live stream playback
- Compatible with Chrome, FireFox, Safari 10, IE11 and Edge
- Extremely low overhead, and hardware accelerated by your browser!
FLV playback limitations
- MP3 audio codec is currently not working on IE11 / Edge
- HTTP FLV live stream is not currently working on all browsers, see livestream.md
FLV Multipart playback
You only have to provide a playlist for MediaDataSource. See multipart.md
Livestream playback
See livestream.md
API and Configuration
See api.md
Debug
npm install # install dev-dependencies
npm install -g webpack-cli # install build tool
npm run build:debug # packaged & minimized js will be emitted in dist folder
Design
See design.md
License
Copyright (C) 2021 magicxqq. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.