樹莓派4B 使用Onenet 視頻能力
OneNET Video視頻能力為用戶提供物聯網行業視頻設備接入能力,方便快捷的接入使用流程,快速穩定的平臺性能,低成本的使用方式,讓物聯網企業可以更加方便對視頻業務進行開發,從而解決物聯網視頻行業的并發、分發的業務痛點,
所以這個Onenet平臺視頻能力如何在樹莓派平臺部署呢?接下來讓我們一起看看,

文章目錄
- 樹莓派4B 使用Onenet 視頻能力
- 一、硬軟平臺基本環境
- 二、搭建RPOS服務器
- 三、交叉編譯Onenet視頻推流服務
- 1. 下載樹莓派交叉編譯工具
- 2.使用交叉編譯工具編譯libssl庫
- 3.交叉編譯OneNET SDK
- 四、創建Onenet視頻服務并部署
- 1.創建Onenet視頻服務
- 2.部署到樹莓派
- 五、參考資料
一、硬軟平臺基本環境
硬體平臺:樹莓派4B
系統鏡像:2020-02-13-raspbian-buster.img
攝像頭:USB攝像頭
二、搭建RPOS服務器
基于 Node.js 的 ONVIF 攝像頭/NVT 軟體,可將 Raspberry Pi、Windows、Linux 或 Mac 計算機轉變為 ONVIF 攝像頭和 RTSP 服務器,參照其中的步驟即可完成RPOS服務器的搭建,
RPOS專案主頁
RPOS Gitee專案主頁(我克隆滴)
組態檔rposConfig.json,我使用的室USB攝像頭,所以寫的如下(注意:服務器配置了用戶名和密碼都是admin):
{
"NetworkAdapters" : ["awdl0","eth0", "wlan0", "en0"],
"IpAddress" : "127.0.1.1",
"ServicePort" : 8081,
"Username" : "admin",
"Password" : "admin",
"CameraType" : "usbcam",
"CameraDevice" : "/dev/video0",
"RTSPAddress" : "", "//":"Normally left blank. Used to set RTSP Server Address",
"RTSPPort" : 8554,
"RTSPName" : "h264",
"MulticastEnabled" : false, "MulticastEnabledComment" : "## Multicast is not supported for USB camera",
"RTSPMulticastName" : "h264m",
"MulticastAddress" : "224.0.0.1",
"MulticastPort" : "10001",
"RTSPServer" : 3, "RtspServerComment" : "## Select RTSP Server > 1:RPOS RTSP Server 2:V4L2 RTSP Server by mpromonet (auto selected if MulticastEnabled=true)",
"PTZDriver" : "none", "PTZDriverComment": "## valid values are none,tenx,pelcod,visca and pan-tilt-hat",
"PTZOutput" : "none", "PTZOutputComment": "## values are none (eg Tenx), serial and tcp",
"PTZSerialPort" : "/dev/ttyUSB0",
"PTZSerialPortSettings" : { "baudRate":2400, "dataBits":8, "parity":"none", "stopBits":1 },
"PTZOutputURL": "127.0.0.1:9999",
"PTZCameraAddress": 1,
"DeviceInformation" : {
"Manufacturer" : "Raspberry Pi",
"Model" : "4 B",
"HardwareId" : ""
},
"logLevel" : 3, "logLevelComment": "## LogLevels are > 1:Error 2:Warning 3:Info 4:Debug",
"logSoapCalls" : false
}
最后使用sudo node rpos.js運行后,會出現如下輸出,接著我們打開ONVIF Device Manger軟體,該軟體會自動搜索局域網內的IPC終端,電機Live video就可以看到局域網內實時畫面了,
pi@raspberrypi:~/Desktop/rpos $ sudo node rpos.js
Read IP address 192.168.31.196 from wlan0
Manufacturer : Raspberry Pi
Model : 4 B
HardwareId :
SerialNumber : 100000007458e142
FirmwareVersion : 2.1.0
Starting camera settings webserver on http://192.168.31.196:8081/
unknown control 'h264_profile'
Could not retrieve Controlvalue 'red_balance'
Could not retrieve Controlvalue 'blue_balance'
Could not retrieve Controlvalue 'horizontal_flip'
Could not retrieve Controlvalue 'vertical_flip'
Could not retrieve Controlvalue 'color_effects'
Could not retrieve Controlvalue 'rotate'
Could not retrieve Controlvalue 'color_effects_cbcr'
Could not retrieve Controlvalue 'video_bitrate_mode'
Could not retrieve Controlvalue 'video_bitrate'
Could not retrieve Controlvalue 'repeat_sequence_header'
Could not retrieve Controlvalue 'h264_i_frame_period'
Could not retrieve Controlvalue 'h264_level'
Could not retrieve Controlvalue 'h264_profile'
Could not retrieve Controlvalue 'auto_exposure'
Could not retrieve Controlvalue 'exposure_time_absolute'
Could not retrieve Controlvalue 'exposure_dynamic_framerate'
Could not retrieve Controlvalue 'auto_exposure_bias'
Could not retrieve Controlvalue 'white_balance_auto_preset'
Could not retrieve Controlvalue 'image_stabilization'
Could not retrieve Controlvalue 'iso_sensitivity'
Could not retrieve Controlvalue 'exposure_metering_mode'
Could not retrieve Controlvalue 'scene_mode'
Could not retrieve Controlvalue 'compression_quality'
Binding DeviceService to http://192.168.31.196:8081/onvif/device_service
Binding MediaService to http://192.168.31.196:8081/onvif/media_service
Binding PTZService to http://192.168.31.196:8081/onvif/ptz_service
Binding ImagingService to http://192.168.31.196:8081/onvif/imaging_service
discovery_service started
Starting Live555 rtsp server
media_service started
ptz_service started
device_service started
imaging_service started
rtspServer: INFO:root:StreamServer initialized
rtspServer: INFO:root:Video settings loaded from v4l2ctl.json
rtspServer: DEBUG:root:StreamServer.launch
INFO:root:USB camera ignored most of the parameters
DEBUG:root:( v4l2src device=/dev/video0 brightness=0 contrast=32 saturation=64 ! image/jpeg,width=640,height=480,framerate=25/1 ! jpegdec ! clockoverlay ! omxh264enc target-bitrate=10000000 control-rate=variable ! video/x-h264,profile=baseline ! h264parse ! rtph264pay name=pay0 pt=96 )
rtspServer: INFO:root:Starting service on port 8554 at url /h264
rtspServer: INFO:root:Running RTSP Server

以上就完成了一個局域網內的視頻推流服務,但是目前在很多情況下局域網推流已經無法滿足我們的需求,我們就需要用到中移的Onenet平臺進行互聯網平臺的轉發作業,
三、交叉編譯Onenet視頻推流服務
Raspberry Pi本身的硬體性能不是很高,所以在pi上直接編譯源代碼,需要消耗很多的時間,因此在選擇在性能呢強大的臺式機上來配置一個交叉編譯平臺,再將編譯后的bin檔案和config.json檔案拷貝到樹莓派來執行;主要參考來自:
OneNET視頻推流------使用樹莓派交叉編譯工具
1. 下載樹莓派交叉編譯工具
選用的交叉編譯工具鏈,是Raspberry Pi 基金會官方發布的 交叉編譯工具包,也就是官方用來編譯Raspbian作業系統所用的交叉編譯工具鏈,
1).直接使用git clone命令直接獲取源代碼,其中的gcc-linaro-arm-linux-gnueabihf-raspbian-x64就是我們需要的檔案夾,
git clone git://github.com/raspberrypi/tools.git
2).接下來跳轉到檔案夾中查看下:
cd tools/arm-bcm2708/
3).正常會有如下檔案:
arm-bcm2708hardfp-linux-gnueabi arm-rpi-4.9.3-linux-gnueabihf
arm-bcm2708-linux-gnueabi gcc-linaro-arm-linux-gnueabihf-raspbian
arm-linux-gnueabihf gcc-linaro-arm-linux-gnueabihf-raspbian-x64
整體命令運行有如下結果:
xxx@virtual-machine:~$ git clone git://github.com/raspberrypi/tools.git
正克隆到 'tools'...
remote: Enumerating objects: 25407, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 25407 (delta 18), reused 12 (delta 6), pack-reused 25374
接收物件中: 100% (25407/25407), 610.89 MiB | 2.29 MiB/s, 完成.
處理 delta 中: 100% (14899/14899), 完成.
正在檢出檔案: 100% (19060/19060), 完成.
xxx@virtual-machine:~$ cd tools
xxx@virtual-machine:~/tools$ cd arm-bcm2708/
xxx@virtual-machine:~/tools/arm-bcm2708$ ls
arm-bcm2708hardfp-linux-gnueabi arm-rpi-4.9.3-linux-gnueabihf
arm-bcm2708-linux-gnueabi gcc-linaro-arm-linux-gnueabihf-raspbian
arm-linux-gnueabihf gcc-linaro-arm-linux-gnueabihf-raspbian-x64
2.使用交叉編譯工具編譯libssl庫
1).下載libssl原始碼檔案,Onenet SDK推薦使用的openssl版本為:openssl-1.0.1g,我們打開新終端,
xxx@virtual-machine:~$ wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
解壓檔案
xxx@virtual-machine:~$ tar xf openssl-1.0.1g.tar.gz
2).使用export命令宣告編譯目錄,需要注意你的編譯工具的目錄,
xxx@virtual-machine:~$ export CROSSCOMP_DIR=/home/xxx/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
3).宣告安裝目錄
xxx@virtual-machine:~$ export INSTALL_DIR=/home/xxx/libssl
4).進入libssl源檔案,針對樹莓派平臺進行交叉編譯
xxx@virtual-machine:~$ cd openssl-1.0.1g
changliu@changliu-virtual-machine:~/openssl-1.0.1g$Configure linux-generic32 \
--prefix=$INSTALL_DIR --openssldir=$INSTALL_DIR/openssl \
--cross-compile-prefix=$CROSSCOMP_DIR/arm-linux-gnueabihf-
5).交叉編譯libssl庫
xxx@virtual-machine:~/openssl-1.0.1g$ make depend
xxx@virtual-machine:~/openssl-1.0.1g$ make
xxx@virtual-machine:~/openssl-1.0.1g$ make install
編譯完成后我們可以在主目錄中看到如下檔案夾:
xxx@virtual-machine:~$cd libssl
xxx@virtual-machine:~/libssl$ ls
bin include lib openssl
6).make install可能會遇到openssl make install : *** [install_docs] 錯誤 255解決方法如下:
xxx@virtual-machine:~$ sudo nano /usr/bin/pod2man
注釋其中的71行$parser->parse_from_file (@files);
注:ctrl+c可查看當前行數,
3.交叉編譯OneNET SDK
1).打開openssl安裝地址將其lib中的內容復制到/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/lib/gcc/arm-linux-gnueabihf/4.8.3:
xxx@virtual-machine:~$ cd libssl
xxx@virtual-machine:~$ cd ~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/lib/gcc/arm-linux-gnueabihf/4.8.3
xxx@virtual-machine:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/lib/gcc/arm-linux-gnueabihf/4.8.3$ ls
crtbegin.o crtendS.o include-fixed libgcc.a libssl.a
crtbeginS.o engines install-tools libgcc_eh.a pkgconfig
crtbeginT.o finclude libcaf_single.a libgcov.a plugin
crtend.o include libcrypto.a libgfortranbegin.a
2).打開新終端獲取Onenet視頻服務SDK原始碼:
xxx@virtual-machine:~$ git clone https://github.com/cm-heclouds/video_sdk.git
xxx@virtual-machine:~$ cd video_sdk/
xxx@virtual-machine:~/video_sdk$ ls
bin gm813x linux-arm.txt sample tools
CMakeLists.txt include platforms src video-plugin
g813x-arm.txt lib README.md test
3).打開組態檔進行編譯配置:
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/home/changliu/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/")
SET(CMAKE_FIND_ROOT_PATH "${TOOLCHAIN_DIR}")
SET(CMAKE_C_COMPILER "${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-gcc-4.8.3")
SET(CMAKE_CXX_COMPILER "${TOOLCHAIN_DIR}/bin/arm-linux-gnueabihf-g++")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
4).安裝依賴庫
sudo apt-get install libssl-dev
5).修改sample/onvif/device_onvif.c檔案防止INFO: profile [0: level=1 bitrate=10000 framterate=25] 段錯誤
將所有指標未初始化為NULL的初始化為NULL
6).編譯,在/video_sdk/video_sample_build_on_arm_linux檔案夾中:
xxx@virtual-machine:~/video_sdk/video_sample_build_on_arm_linux$ make
編譯成功沒有錯誤即可,生成sample_video_s檔案,
四、創建Onenet視頻服務并部署
1.創建Onenet視頻服務
我們打開Onenet視頻服務平臺,添加產品即可:

2.部署到樹莓派
首先我們先啟動RPOS服務,可以看到服務啟動在http://192.168.31.196:8081/onvif/device_service
pi@raspberrypi:~/Desktop/rpos $ sudo node rpos.js
Read IP address 192.168.31.196 from wlan0
Manufacturer : Raspberry Pi
Model : 4 B
HardwareId :
SerialNumber : 100000007458e142
FirmwareVersion : 2.1.0
Starting camera settings webserver on http://192.168.31.196:8081/
unknown control 'h264_profile'
Could not retrieve Controlvalue 'red_balance'
Could not retrieve Controlvalue 'blue_balance'
Could not retrieve Controlvalue 'horizontal_flip'
Could not retrieve Controlvalue 'vertical_flip'
Could not retrieve Controlvalue 'color_effects'
Could not retrieve Controlvalue 'rotate'
Could not retrieve Controlvalue 'color_effects_cbcr'
Could not retrieve Controlvalue 'video_bitrate_mode'
Could not retrieve Controlvalue 'video_bitrate'
Could not retrieve Controlvalue 'repeat_sequence_header'
Could not retrieve Controlvalue 'h264_i_frame_period'
Could not retrieve Controlvalue 'h264_level'
Could not retrieve Controlvalue 'h264_profile'
Could not retrieve Controlvalue 'auto_exposure'
Could not retrieve Controlvalue 'exposure_time_absolute'
Could not retrieve Controlvalue 'exposure_dynamic_framerate'
Could not retrieve Controlvalue 'auto_exposure_bias'
Could not retrieve Controlvalue 'white_balance_auto_preset'
Could not retrieve Controlvalue 'image_stabilization'
Could not retrieve Controlvalue 'iso_sensitivity'
Could not retrieve Controlvalue 'exposure_metering_mode'
Could not retrieve Controlvalue 'scene_mode'
Could not retrieve Controlvalue 'compression_quality'
Binding DeviceService to http://192.168.31.196:8081/onvif/device_service
Binding MediaService to http://192.168.31.196:8081/onvif/media_service
Binding PTZService to http://192.168.31.196:8081/onvif/ptz_service
Binding ImagingService to http://192.168.31.196:8081/onvif/imaging_service
discovery_service started
Starting Live555 rtsp server
media_service started
ptz_service started
device_service started
imaging_service started
rtspServer: INFO:root:StreamServer initialized
rtspServer: INFO:root:Video settings loaded from v4l2ctl.json
rtspServer: DEBUG:root:StreamServer.launch
INFO:root:USB camera ignored most of the parameters
DEBUG:root:( v4l2src device=/dev/video0 brightness=0 contrast=32 saturation=64 ! image/jpeg,width=640,height=480,framerate=25/1 ! jpegdec ! clockoverlay ! omxh264enc target-bitrate=10000000 control-rate=variable ! video/x-h264,profile=baseline ! h264parse ! rtph264pay name=pay0 pt=96 )
rtspServer: INFO:root:Starting service on port 8554 at url /h264
rtspServer: INFO:root:Running RTSP Server
接著我們配置Onenet服務:打開Onenet_sdk,進入bin檔案,進行如下配置:
{
"profile":{
"productid":45xx26, # 產品ID 需洗掉注釋
"deviceid":xx, # 設備ID,未用 需洗掉注釋
"pass":"VUHPxxxxjt1k", # "設備注冊碼" 需洗掉注釋
"id":"xxx" # "設備標識" 需洗掉注釋
},
"onvif":
[
{
"title":"Channl1",
"channel_id":1,
"url": "http://192.168.31.196:8081/onvif/device_service",
"user": "admin",
"passwd": "admin",
"desc":"Machine 1",
"defaultlevel": 1
}
],
"rvod":
[
{
"channel_id":1,
"location":"./test1.mp4",
"beginTime":"2010-12-08 00:00:00",
"endTime":"2010-12-08 00:22:59",
"videoTitle":"title1"
}
]
}
先給檔案加可執行權限,然后啟動Onenet服務:
pi@raspberrypi:~/Desktop/video_sdk/bin $ sudo chmod +x sample_video_s
pi@raspberrypi:~/Desktop/video_sdk/bin $ ./sample_video_s
INFO: [info]:url=http://192.168.31.196:8081/onvif/device_service has profiles-------------------------------------------------------:
INFO: profile [0: level=1 bitrate=10000 framterate=25]
no this level 4
no this level 3
no this level 2
8554INFO: ip 47.106.46.251 port 9201 token
INFO: 3c 82 11 8b f2 c7 39 7a 90 64 6a 76 04 c4 20 81
INFO: 70 9d a4 3a 17 a6 7d ff 82 a7 d9 01 e3 3f 73 8d
INFO: get dev id 769789491
最后在Onenet視頻服務界面中播放實時視頻即可:

五、參考資料
OneNET檔案中心
Ubuntu下視頻接入到onenet
OneNET視頻能力體驗------使用樹莓派攝像頭推流
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/321431.html
標籤:其他
上一篇:21. 合并兩個有序鏈表
下一篇:linux驅動之I2C子系統
