![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
goldvideo-player
Advanced tools
随着视频编码技术的发展,相比H.264, H.265同等画质体积仅为一半、带宽占用省一半、画质更细腻等诸多优势。 但Web浏览器还不支持H.265的解码播放,因此基于Web Assembly(封装FFmpeg)、JS解封装、Canvas投影以及AudioContext实现Web端的H265播放。
支持主要浏览器及其版本如下:
Chrome(>57)
Safari (>11)
Firefox (>52)
本项目是一个公开的基础可用版本,并不含有具体的业务代码。业务可基于此项目进行具体业务实现。
* mkdir goldvideo
* cd goldvideo
* git clone https://github.com/goldvideo/demuxer.git
* cd demuxer
* npm install
* npm run production
* cd ..
* git clone https://github.com/goldvideo/h265player.git
* cd h265player
* npm install
# install demuxer module from local
* npm install ../demuxer
# or install demuxer module from online
* npm i demuxer
* 以下命令根据需要四选一
* npm run dev # 运行开发环境
* npm run test # 运行测试环境
* npm run build # 打包正式环境
* rollup -c # 打包csj与esm版本
├─goldvideo
│ ├─demuxer
│ ├─h265player
│ ├─decoder_wasm
│ ├─example
server {
listen 8000;
location / {
root <path of goldvideo>/h265player;
index index.html index.htm;
autoindex on;
}
}
http://localhost:8000/demo/demo.html
播放器主要分为UI、Loader、数据处理、数据渲染四个部分和3个线程。一个是主线程,包括界面控制、下载控制、数据流控制、音视频控制等功能;数据加载线程,完成元数据和数据片段的请求;数据处理线程,完成数据解封装和解码。
播放器主要流程如下图所示:
具体流程如下:
通过demuxer.js实现媒体数据的解封装,从而获取到独立的视频(H265)数据和音频(AAC)数据。详细信息请参考demuxer.js
通过ffmpeg实现H265数据的软解码,如果要在浏览器中调用ffmpeg,需要把ffmpeg编译成wasm进行调用,具体ffmpeg编译成wasm过程,可参考decoder_wasm
通过yuv-canvas实现YUV数据渲染,ImagePlayer中会有一个队列存储YUV数据,并计算当前yuv数据的时间长度,大于等于readybufferLength的值时,会触发ImagePlayerReady事件。当音视频播放器都处于ready状态时,H265播放器触发dataReady事件,开始调用play方法进行视频播放。
Audio Player的实现基于Web Audio API, 包括AAC音频流的解码与PCM数据的播放。
Audio Context的部分音频节点提供了playbackRate属性以实现倍速播放的功能,但是音频在倍速播放的同时,音频的音调(pitch)也同步地升高/降低。
为实现变速不变调,项目中,我们使用了一个音频数据处理库SoundTouchJS,将处理过的变速不变调的音频数据提供给ScriptProcessorNode。
在head标签中添加如下代码
<link rel="stylesheet" href="../dist/goldplay-h265.css">
<script src="../dist/goldplay-h265-sdk.js"></script>
<style>
.play-container{
width: 800px;
height: 500px;
}
</style>
创建一个div,作为播放器的容器
<div class="play-container"></div>
新建一个GoldPlay实例对象,传入相应参数,就可以实现视频的播放
//播放器容器
let el = doc.querySelector('.play-container')
//播放器参数
let options = {
//视频播放地址
sourceURL: 'http://localhost:9011/gitwork/h265player/data/video2/playlist.m3u8',
type: 'HLS'
//wasm库地址
libPath: 'http://localhost:9011/gitwork/h265player/dist/lib',
}
let player = new GoldPlay(el, options}
如何扩展UI组件请参考文档
https://goldvideo.github.io/h265player/API/index.html
* github: https://github.com/goldvideo/h265player
FAQs
goldplay-h265player
The npm package goldvideo-player receives a total of 1 weekly downloads. As such, goldvideo-player popularity was classified as not popular.
We found that goldvideo-player demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.