使用video.js 7在html中播放rtmp視頻流


1.背景

最近要做攝像頭視頻的展示,不想使用硬件方的專用插件,所以計划視頻推送到SRS服務器,瀏覽器再通過rtmp協議顯示,類似於直播。

經查詢,了解到可以用ckplayer(有許可條款)和video.js在html頁面中。嘗試了video.js_5.x可以正常播放,而6.x版本不能播放,可目前video.js已經更新到了7.x!

幾經折騰,發現6.x版本后需要單獨的flash插件,早期版本包含了flash,官方說明如下:

2.示例

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <title>Live Video 7.X</title>
 7     <link href="./lib/video7.3.0/video-js.min.css" rel="stylesheet">
 8     <script src="./lib/video7.3.0/video.min.js"></script>
 9     <script src="./lib/flash/videojs-flash.min.js"></script>
10 </head>
11 
12 <body>
13     <video id="liveVideo" class="video-js" controls autoplay preload="auto" width="1280"
14         height="720" data-setup="{}">
15         <source src="rtmp://192.168.3.161:1935/live/livestream" type="rtmp/flv">
16     </video>
17 </body>
18 </html>

引入了video.js、video.js和videojs-flash.js,添加video標簽,設置autoplay、width、height等屬性,data-setup屬性必須要,如果不做設置一定寫成“{}”,

設置source的src和type屬性,可以先通過ffplayer客戶端工具查看視頻流是否能夠播放。

 

3.注意事項及完整示例

不支持文件方式打開頁面,必須是http方式訪問頁面,可以通過nginx或使用編輯器的內置server,如vscode的live server;

video.js的github地址:https://github.com/videojs/video.js

videojs-flash的github地址:https://github.com/videojs/videojs-flash

完整代碼參考:https://github.com/shiyuan598/live-video

簡單記錄一下在html中使用vedio.js6以上版本播放rtmp視頻流的方法,歡迎留言交流~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM