關於直播的技術整理2


為了減小延時

webrtc+rtsp?

之前用的是srs+http-flv/rtmp+flv.js/jwplayer,延時大概2~3秒
為了進一步減小延時,客戶端選擇直接用webrtc,那么服務器呢?
因為現在網絡攝像頭大都是rtsp協議,那么有沒有webrtc+rtsp做直播的呢?(同道中人:https://stackoverflow.com/questions/23461914/use-an-ip-camera-with-webrtc)
google了好久,終於找到了一個叫Kurento的東西。

Kurento

http://www.kurento.org/
http://doc-kurento.readthedocs.io/en/stable/what_is_kurento.html

Kurento is a WebRTC media server and a set of client APIs simplifying the development of advanced video applications for web and smartphone platforms. Kurento features include group communications, transcoding, recording, mixing, broadcasting and routing of audiovisual flows.

一個demon

https://github.com/lulop-k/kurento-rtsp2webrtc
這個demon依賴Kurento

搭好環境后測試(網頁直接播放網絡攝像頭視頻),效果不理想,延時還是2秒左右。
但是這個的優化可能性比之前的要大,還要研究下。

經過一番努力終於找到解決辦法:
https://github.com/Kurento/kms-elements/pull/3
https://github.com/Kurento/bugtracker/issues/22
修改index.js

pipeline.create("PlayerEndpoint", {networkCache: 0, uri: address.value}, function(error, player){...

原來kurento客戶端提供了接口,延時變為0.2秒,簡直太他媽爽了。

Jsmpeg

官網:http://jsmpeg.com/
Github:https://github.com/phoboslab/jsmpeg

Kurento確實牛逼,但是要把它移植到ARM上簡直是找虐,我甚至沒有成功移植到我的物理機(kali linux)上,在Ubuntu12上測試成功!
即便是能成功移植,但是體積估計超過我們的預期容量。在這點上Jsmpeg體現了優勢,僅僅需要NodeJS環境,即便不能把NodeJS移植進去,用C寫一個WebSocket服務應該不難。
Github有詳細的安裝教程,我不詳述,簡單記下測試步驟:
1、獲取攝像頭rtsp視頻流發送到websocket服務器(jsmpeg/websocket-relay.js)

ffmpeg -i rtsp://192.168.2.61 -f mpegts -codec:v mpeg1video -s 960x540 -b:v 1500k -r 30 -bf 0 -codec:a mp2 -ar 44100 -ac 1 -b:a 128k http://localhost:8081/supersecret
ffmpeg -i rtsp://192.168.2.32  -s 860x640 -f mpegts -vcodec mpeg1video -b 800k -r 30  http://192.168.2.250:8081/supersecret

2、訪問:http://127.0.0.1:8080/view-stream.html (jsmpeg/view-stream.html)就能看到攝像頭的畫面,延時很低具體沒測,實時性滿足要求。

top數據:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND  
 3815 root      20   0  565184  74264  10972 S  54.2  1.9   1:06.32 ffmpeg                                                                            
 1970 root      20   0 2716632 475728 138652 S  28.2 12.1  13:12.39 Web Content                                                                       
 1879 root      20   0 2613608 383752 127160 S  13.3  9.7   6:37.71 firefox-esr 


免責聲明!

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



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