IP Camera等设备的视频流接入EdgeX Foundry

使用edgex-device-rtsp这个device service管理IPC设备,实现接入视频流,存储,转发。
当前版本是开发测试功能,主要支持以下功能:

本地摄像头,本地文件推流(提供独立的rtmp协议服务)
管理远程IPC设备
接入远程IPC设备视频流,存储,推流转发(支持http client接入)

未来支持:

导出视频存储文件
通过rtsp控制IPC设备
自动扫描,注册IPC设备到EdgeX

开始使用

1.启动edgex-device-rtsp

(1)直接docker 启动

注:- -network参数的值要看自己环境的值是多少,edgexfoundry compose文件中定义的是edgex-network,但是如果用docker compose命令启动的话,或默认添加当前目录名称前缀。
必须要加入到edgex-network中,否则无法注册到edgexfoundry。

 docker pull badboyqiao/edgex-device-rtsp:0.1.0-dev
 docker run -it -d \
  -p 8089:8089 -p 49983:49983 -p 1935:1935 \
  --name edgex-device-rtsp \
  --hostname edgex-device-rtsp \
  --network root_edgex-network \
  badboyqiao/edgex-device-rtsp:0.1.0-dev

(2)通过docker-compose
在edgexfoundry官方的docker-compose文件中device service段添加如下code:

 device-rtsp:
    image:badboyqiao/edgex-device-rtsp:0.1.0-dev
    ports:
    - "49983:49983"
    - "1935:1935"
    - "8089:8089"
    container_name: edgex-device-rtsp
    hostname: edgex-device-rtsp
    networks:
      edgex-network:
        aliases:
        - edgex-device-rtsp
    volumes:
    - db-data:/data/db
    - log-data:/edgex/logs
    - consul-config:/consul/config
    - consul-data:/consul/data
    depends_on:
    - data
    - command

2.客户端推拉流
(1)rmtp

client 推流:

ffmpeg -re -i file.flv -c copy -f flv rtmp://ip:1935/custom_name
ffmpeg -re -i /dev/video0 -f video4linux2 -r 12 -s 640x480  -f flv rtmp://192.168.17.128:1935/custom_name

client 拉流:

   http://ip:8089/live/custom_name.flv

(2)rtsp (ipc)

RTSP协议的IPC设备地址示例:

海康威视RTSP流格式:
rtsp://username:password@//ch/

其中videotype值可能是h264或者h265,根据实际产品说明书指定

主码流格式:
rtsp://admin:1234@192.168.8.125:554/h264/ch1/main/av_stream

子码流格式:
rtsp://admin:1234@192.168.8.125:554/h264/ch1/sub/av_stream

其中端口号后面的路径就是下面protocol地址中的path值。

先调用EdgeX API注册IP Camera设备:(当前只支持turnoff和turnon命令,编写profile文件的时候请注意,只填这两个device resource)

{
    "name":"ipc1_device_name",
    "adminState":"UNLOCKED",
    "operatingState":"ENABLED",
    "protocols":{
        "rtsp":{
            "Schema":"rtsp",
            "Host":"192.168.8.125",
            "Port":"554",
            "Password":"1234",
            "User":"admin",
            "Path":"/h264/ch1/sub/av_stream",
            "DumpPath":""
        }
    },
    "service":{
        "name":"edgex-device-rtsp"    
    },
    "profile":{
        "name":"test-rtsp-profile"
    }
}

测试流:

postman中请求如下地址:
http://edgexfoundry_host_ip:48082/api/v1/device

找到turnon命令,发送命令,访问IPC视频流。
(如果是在edgex-ui-go的web页面中发送命令,选择set命令,参数值为true)

使用vlc打开network设备,输入:
http://edgex-device-rtsp_host_ip:8089/live/ipc_name

找到turnoff命令,关闭流。
(如果是在edgex-ui-go的web页面中发送命令,选择set命令,参数值为true)

device profile文件:

name: "test-rtsp-profile"
manufacturer: "VMware huaqiaoz"
model: "rtsp"
labels:
- "test"
description: "Test rtsp profile"
deviceResources:
-
  name: turnon
  description: "turnon actively"
  attributes:
    { name: "turnon" }
  properties:
    value:
      { type: "Bool", size: "1", readWrite: "RW", defaultValue: "false"  }
    units:
      { type: "String", readWrite: "RW", defaultValue: "ON" }
-
  name: turnoff
  description: "turnoff actively"
  attributes:
    { name: "turnoff" }
  properties:
    value:
      { type: "Bool", size: "1", readWrite: "RW", defaultValue: "false"  }
    units:
      { type: "String", readWrite: "RW", defaultValue: "OFF" }
deviceCommands:
-
  name: turnon
  set:
  - { index: "1", operation: "set", object: "turnon", parameter: "turnon", property: "value" }
-
  name: turnoff
  set:
  - { index: "1", operation: "set", object: "turnoff", parameter: "turnoff", property: "value" }
coreCommands:
-
  name: turnon
  put:
    path: "/api/v1/device/{deviceId}/turnon"
    parameterNames: ["turnon"]
    responses:
    -
      code: "204"
      description: "set the message."
      expectedValues: []
    -
      code: "503"
      description: "service unavailable"
      expectedValues: []
-
  name: turnoff
  put:
    path: "/api/v1/device/{deviceId}/turnoff"
    parameterNames: ["turnoff"]
    responses:
    -
      code: "204"
      description: "set the message."
      expectedValues: []
    -
      code: "503"
      description: "service unavailable"
      expectedValues: []

原作者:huaqiaoz
原文链接:https://www.edgexfoundry.club/user/huaqiaoz/article/5d0c8ac5e3f1bf0001e85e9a

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值