使用webrtc RTSP 視頻實時預覽
一、首先將海康的攝像頭 將視頻編碼設置成 h264編碼 否則瀏覽器無法播放
二、 在github 發布頁面根據需要的平臺選擇相應的包下載
https://github.com/mpromonet/webrtc-streamer/releases
三、方式1
docker run -d --restart=always -p 8000:8000 -it mpromonet/webrtc-streamer -o -s -w ../
但是此方式的弊端有兩點:
1、前端在設置訪問地址的時候 只能天localhost 或者 127.0.0.1 填本機ip會報錯
2、還會阻塞接口
四、方式2
直接下載對應包本地部署
這里下載6.0版本 最新7.0版本會報缺失GLIBC_包安裝起來還是有點蠻煩的 而且最新的包一般不穩定 所以這里推薦使用6.0版本
下載地址
https://github.com/mpromonet/webrtc-streamer/releases/download/v0.6.0/webrtc-streamer-v0.6.0-Linux-x86_64-Release.tar.gz
下載以后解壓縮
tar -zxvf webrtc-streamer-v0.6.0-Linux-x86_64-Release.tar.gz
mv webrtc-streamer-v0.6.0-Linux-x86_64-Release webrtc-streamer
啟動
root@hicourt-System-Product-Name:/home/xuguangzong/Workspace/webrtc-streamer# ./webrtc-streamer -o -s -w ../
由于這樣無法做到開機自啟和后臺運行,所以接下來配置開機自啟
################
ubuntu 開機自啟
ubuntu-18.04不能像ubuntu16.04那樣通過編輯rc.local來設置開機啟動腳本,但是如果在18.04鐵了心要通過rc.local來添加開機自啟動腳本也不是不行,方法如下:
1、建立rc-local.service文件
vim /etc/systemd/system/rc-local.service
2、將下列內容復制進rc-local.service文件
[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
3、創建文件rc.local
vim /etc/rc.local4、將下列內容復制進rc.local文件
4、將下列內容復制進rc.local文件
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution# bits. # # By default this script does nothing. /Workspace/webrtc-streamer-v0.6.0-Linux-x86_64-Release/webrtc-streamer -o -s -w ../ &
exit 0
5、給rc.local加上權限
chmod +x /etc/rc.local
6、啟用服務和檢查狀態
systemctl enable rc-local
systemctl start rc-local.service
systemctl status rc-local.service
五、注意:如果過程中 報了如下類似的錯誤
./webrtc-streamer: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by ./webrtc-streamer)
那就需要安裝GLIBC
查看當前版本
strings /lib/x86_64-linux-gnu/libm.so.6 | grep GLIBC_
到該地址下載對應的包 http://ftp.gnu.org/gnu/libc/
wget http://ftp.gnu.org/gnu/libc/glibc-2.28.tar.gz
tar -zxvf glibc-2.28.tar.gz
cd glibc-2.28
mkdir build
cd build
../configure --prefix=/usr/local/glibc
make -j8
sudo make install
cd /lib/x86_64-linux-gnu
ln -s /usr/local/glibc/lib/libm-2.28.so libm.so.6
//會報錯 ln: failed to create symbolic link ‘libm.so.6’: File exists
//此時需要強連
sudo ln -sf /usr/local/glibc/lib/libm-2.28.so libm.so.6

浙公網安備 33010602011771號