mpegts.js

xqqApache-2.0活跃维护

基于 MSE 的 HTML5 播放器,能在浏览器里直接播放 MPEG2-TS 和 FLV 格式的直播流,省去转封装或插件依赖。

HTML5 MPEG2-TS / FLV Stream Player

v1.8.2发布于 2026-08-14 06:18 UTC2,297star300fork同步于 2026-11-07 07:33 UTC

怎么上手

由 README 提炼,执行前请确认
npm install --save mpegts.js
硬件要求按 README 说明

README 未说明显存或 GPU 型号要求;运行在浏览器中,由浏览器做硬件加速,支持 Chrome、FireFox、Safari、Edge 等 Chromium 系浏览器。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

浏览器端 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 元数据

容易踩的坑

跨域拉流需在视频服务器正确配置 Access-Control-Allow-Origin 头;不支持 mpeg2video 编码;iOS 17.0 及更早版本不可用,需 17.1+ 的 ManagedMediaSource。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.8.2
  1. 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

  2. v1.8.12026-08-06 · 2026-08-06 05:38 UTC
    查看更新说明

    New features and enhancements

    Bugfix and improvements

    New Contributors

    Full Changelog: https://github.com/xqq/mpegts.js/compare/v1.8.0...v1.8.1

  3. v1.8.02024-12-24 · 2024-12-24 14:45 UTC
    查看更新说明

    New version after a long period with many changes

    New features and enhancements

    Bugfix and improvements

    Misc

  4. 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

  5. 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

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    mpegts.js npm

    日本語 中文说明

    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/

    demo with aribb24.js

    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 .m2ts file 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.