webcodecs-h265-stream-player
v1.0.10
Published
h265 stream player
Downloads
9
Maintainers
Readme
h265-player
🚀 h265 stream player 🌈. 在浏览器上播放 H265 视频流,调用 WebCodecs API 对 H265 视频流进行解码,并通过 canvas 绘制。
安装
npm i webcodecs-h265-stream-player
使用
import H265Player from "webcodecs-h265-stream-player";
new H265Player(HTMLCanvasElement);
api
HTMLCanvasElement
canvas dom,用来绘制解码出来的图像
方法
| 方法 | 说明 | 参数 |
| ---------- | --------------------------- | ------------------------------------------------------------------------------------------------ |
| feed | 喂给播放器 一帧 h265 视频流 | (arraybuffer,timestamp),arraybuffer 是 ArrayBuffer 类型,timestamp 是 number 类型的时间戳(秒) |
| pause | 暂停播放 | |
| play | 开始播放 | |
| fullscreen | 视频全屏 | |
| destroy | 销毁播放器 | |
| on | 监听事件 | 参照下面监听事件
|
| off | 取消监听事件 | |
监听事件
| 事件 | 说明 | 回调值 | | ----- | ----------------------------------------------------- | -------------- | | ready | 播放器已准备好,可以开始调用 start 方法和 feed 方法了 | | | size | 解码出来的视频的分辨率 | {width,height} | | play | 视频正在播放 | | | pause | 视频暂停 | | | error | 视频播放出错 | |
简单代码
import H265Player from "h265-player";
const canvas = document.getElementById("canvas");
var player = new H265Player(canvas);
player.on("ready", () => {
console.log("ready");
player.start();
});
player.on("size", function (e) {
console.log("size", e.width, e.height, e.mode);
});
player.on("play", () => {
console.log("play");
});
player.on("pause", () => {
console.log("pause");
});
player.on("error", (e) => {
console.log("player error", e);
});
function feed(arraybuffer, timestamp) {
if (player) {
player.feed(arraybuffer, timestamp);
}
}
Thank you for your star