mpegts.js npm

日本語

mpegts.js 是在 HTML5 上直接播放 MPEG2-TS 流的播放器,针对低延迟直播优化,可用于 DVB/ISDB 数字电视流或监控摄像头等的低延迟回放。

mpegts.js 基于 flv.js 改造而来。

Overview

mpegts.js 通过在 JavaScript 中渐进化解析 MPEG2-TS 流并实时转封装为 ISO BMFF (Fragmented MP4),然后通过 Media Source Extensions 把音视频数据喂入 HTML5 <video> 元素。

Demo

http://xqq.github.io/mpegts.js/demo/

Features

CORS

若在与页面不同的独立的服务器串流,必须设置 CORS 的 Access-Control-Allow-Origin 头。

参阅 cors.md

Installation

npm install --save mpegts.js

Build

npm install                 # install dev-dependences
npm install -g webpack-cli  # install build tool
npm run build               # packaged & minimized js will be emitted in dist folder

若在中国大陆可尝试 cnpm 镜像。

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>

可使用 Simple Realtime Server 来测试 mpegts.js。

TODO

Limitations

Features inherited from flv.js

FLV playback limitations

FLV Multipart playback

多段播放需要在 MediaDataSource 中提供文件列表。参阅 multipart.md

Livestream playback

参阅 livestream.md

API and Configuration

参阅 api.md

Debug

npm install                 # install dev-dependences
npm install -g webpack-cli  # install build tool
npm run build:debug         # packaged & minimized js will be emitted in dist folder

Design

参阅 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.