html5_rtsp_player教程,GitHub - L1129433134/html5_rtsp_player: html5 player for rtsp stream

Overview

html5_rtsp_player.js is a Javascript library which implements RTSP client for watching live streams in your browser

that works directly on top of a standard HTML

186d30bd10a4be7e9a8a4bbed1c9eff8.png

It works by muxing RTP h.264 and MP4A-LATM payload into ISO BMFF (MP4) fragments.

html5_rtsp_player.js is written in ECMAScript6, and transpired in ECMAScript5 using Babel.

* HLS player link

* Here you can find HLS player over websocket https://github.com/SpecForge/html5_hls_player

Live test stream

Link to server running with websock_rtsp_proxy and test page http://specforge.com/html5playerstream/index.html

HTML5 Player update test page

We've added such feature which supports Local Fast Playback mode up to 2 minutes duration.

In this mode, you can view the video at a speed of x0,5 to x5.

If you want activate this mode, click on timeline.

To return to normal playback rate, press «live».

This mode is useful to see what you missed.

Browser support:

Firefox v.42+

Chrome v.23+

OSX Safari v.8+

MS Edge v.13+

Opera v.15+

Android browser v.5.0+

IE Mobile v.11+

Not supported in iOS Safari and Internet Explorer

Install

npm install git://github.com/SpecForge/html5_rtsp_player.git

Usage

Browser side

Attach HTML Video with RTSP URL

Setup player in your js:

import * as rtsp from 'rtsp_player';

rtsp.RTSP_CONFIG['websocket.url'] = "ws://websocket_proxy_address/ws"; // You should specify address of proxy described below

let player = rtsp.attach(document.getElementById('test_video'));

ES6 Modules support is required. You can use webpack with babel loader to build this script:

webpack.config.js

const PATHS = {

src: {

test: path.join(__dirname, 'test.js')

},

dist: __dirname

};

module.exports = {

entry: PATHS.src,

output: {

path: PATHS.dist,

filename: '[name].bundle.js'

},

module: {

loaders: [

{

test: /\.js$/,

loader: 'babel',

query: {

presets: ['es2015', 'stage-3', 'stage-2', 'stage-1', 'stage-0']

}

}

]

},

resolve: {

alias: {

rtsp: path.join(__dirname,'node_modules/html5_rtsp/src')

}

}

};

> npm install bp_event bp_logger bp_statemachine

> webpack --config webpack.config.js

Include compiled script into your HTML:

Server side

Install websocket proxy

For Debian-based systems (tested on Ubuntu 16.04):

wget -O - http://repo.tom.ru/deb/specforge.gpg.key | sudo apt-key add -

wget http://repo.tom.ru/deb/pool/non-free/w/ws-rtsp-repo/ws-rtsp-repo_1.3_all.deb

dpkg -i ./ws-rtsp-repo_1.3_all.deb

apt update

apt install ws-rtsp-proxy # Debian-based systems

or Fedora:

dnf install http://repo.tom.ru/rpm/websock_rtsp_repo-1-0.noarch.rpm

dnf install websock_rtsp_proxy

Note that this package depends on systemd and gcc5+ runtime so it can be installed

only on recent distribution versions.

Configure port in /etc/ws_rtsp.ini

This port should be open in your firewall. Also you can pass request to this port from your proxy. (for example: http://nginx.org/en/docs/http/websocket.html)

Run it

> service ws_rtsp start

How RTSP proxy works?

RTSP player establish connection with proxy with following protocol:

Connect to RTSP channel by connecting websocket with "rtsp" protocol specified and get connection id

c>s:

WSP 1.0 INIT\r\n

host \r\n

port \r\n\r\n

s>c:

INIT \r\n\r\n

conection_id = -1 means error

Connect to RTP channel by connecting websocket with "rtp" protocol

c>s:

WSP 1.0 INIT\r\n

RTSP \r\n\r\n

s>c:

INIT \r\n\r\n

conection_id = -1 means error

RTP channel should send interleaved data with 4 byte header ($). Separate RTP is not supported at this moment

b5e30ba579e85631e9b65e27d0de0dc4.png

Have any suggestions to improve our player?

Feel free to leave comments or ideas specforge@gmail.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在HTML5中使用FFmpeg来获取RTSP网络流,您可以使用FFmpeg.js库。FFmpeg.js是一个使用WebAssembly构建的JavaScript库,它允许您在浏览器中运行FFmpeg。 以下是使用FFmpeg.js获取RTSP网络流的基本步骤: 1. 下载FFmpeg.js库:您可以从https://github.com/ffmpegwasm/ffmpeg.wasm 获取FFmpeg.js库的最新版本。 2. 将FFmpeg.js库添加到您的HTML文件中: ```html <script type="text/javascript" src="path/to/ffmpeg.js"></script> ``` 3. 创建一个Canvas元素和一个video元素来显示视频: ```html <canvas id="canvas"></canvas> <video id="video" controls></video> ``` 4. 编写JavaScript代码来获取RTSP网络流: ```javascript const canvas = document.getElementById('canvas'); const video = document.getElementById('video'); // 初始化FFmpeg.js const ffmpeg = createFFmpeg({ log: true, corePath: 'path/to/ffmpeg-core.js', }); (async () => { // 加载FFmpeg.js await ffmpeg.load(); // 打开RTSP网络流 await ffmpeg.run('-i', 'rtsp://your_rtsp_stream_url', '-c', 'copy', '-f', 'image2pipe', '-'); // 设置Canvas尺寸 canvas.width = ffmpeg.FS('stat', '/').size; // 循环读取视频帧 while (true) { const { data, status } = ffmpeg.FS('readFile', '/'); if (status) { break; } // 将视频帧绘制到Canvas const imgData = new ImageData(new Uint8ClampedArray(data), canvas.width, canvas.height); const ctx = canvas.getContext('2d'); ctx.putImageData(imgData, 0, 0); // 将视频帧显示在video元素中 video.src = canvas.toDataURL(); // 等待一段时间再读取下一帧 await new Promise(resolve => setTimeout(resolve, 1000 / 30)); // 30帧/秒 } // 关闭FFmpeg.js ffmpeg.FS('unlink', '/'); ffmpeg.exit(); })(); ``` 上述代码中,您需要将'path/to/ffmpeg.js'替换为您下载的FFmpeg.js库的路径,'rtsp://your_rtsp_stream_url'替换为您要获取的RTSP网络流的URL。 这样,您就可以使用FFmpeg.js在HTML5中获取RTSP网络流并显示在Canvas和video元素上了。请注意,由于浏览器的安全策略限制,某些浏览器可能无法直接从RTSP获取流,您可能需要配置服务器以转发流或使用其他解决方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值