Skip to content

yujinkim-msft/onvif-camera-mock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

onvif-camera-mocking

This project started as a fork from kate-goldenring/onvif-camera-mocking This project consists of tools and instructions for mocking an ONVIF-compliant IP camera and passing an RTSP stream to simulate a live video stream.

If you want to use the container without building it, you can download it using the following command:

docker pull winiotsaleskit.azurecr.io/onvif-camera-mocking:latest

Steps

Note: these steps only work on Linux and have only been tested on Ubuntu 22.04LTS

1. Set up your developer machine

  1. Install building dependencies

    sudo apt update
    sudo apt install flex bison byacc make m4 autoconf unzip \
        git g++ wget -y
  2. Install gstreamer dependencies

    sudo apt update
    sudo apt install gstreamer-1.0 libgstrtspserver-1.0-dev gstreamer1.0-rtsp \
        gstreamer1.0-plugins-ugly python3-gi
  3. Clone the repository

    git clone https://github.com/fcabrera23/onvif-camera-mock

2. Build the ONVIF server

The onvif_srvd project was forked, and the updated original dependencies to keep it up to date with gsoap version and fix broken dependencies.

  1. Build the onvif_srvd

    cd onvif_srvd
    make release
  2. Ensure the build was created - Using the ls command, check the onvif_srvd is available. You should see something like this:

    ubuntu@NUC-Ubuntu:/home/ubuntu/onvif-camera-mocking/onvif_srvd# ls
    generated  gsoap-2.8  LICENSE  Makefile  onvif_srvd  README.md  SDK  src  start_scripts  wsdl

3. Build the WS-Discovery Service

The wsdd project was forked, and the updated original dependencies to keep it up to date with gsoap version and fix broken dependencies.

  1. Move to the project root folder and build the wsdd

    cd wssd
    make release
  2. Ensure the build was created - Using the ls command, check the used is available. You should see something like this:

    ubuntu@NUC-Ubuntu:/home/ubuntu/onvif-camera-mocking/wsdd# ls
    CHANGELOG.md  generated soap-2.8 LICENSE  Makefile  README.md  SDK  src  start_scripts  wsdd  wsdl

4. Start the ONVIF and Discovery services with the RTSP feed

  1. Run ifconfig or ipconfig to determine your network interface. Then, pass your interface (such as eno1,eth0, eth1, etc) to the script. The following assumes eth0.

  2. Run the main.py python script to start the discovery services and RTSP feed. You can specify the network interface and optionally the resources directory, firmware version of the camera, and path to the MP4 streaming video file. The script uses the following environment variables and defaults:

    Argument Defaults Description
    INTERFACE No - Mandatory Network interface to expose discovery service
    DIRECTORY Defaults to $PWD The directory of the project
    FIRMWARE Default to 1.0 The "mock" firmware version of the camera
    MP4FILE Default to mocking color stripe video sPath to the video mp4 location

    Run the mocking camera using the following command:

    export INTERFACE=<interface>
    python3 main.py

5. Ensure that the ONVIF camera service is running and discoverable

Use one of the tools recommended by onvif_srvd for testing the ONVIF service.

Program OS
ONVIF Device Manager Windows
ONVIF Device Tool (GUI) Linux
gsoap-onvif Linux

Run the tool on the same device or network as your newly mocked camera. In the tool, look for a new camera called TestDev.

6. Build Docker container

You can build this as a container using the [Dockerfile.onvif-camera]. Note: Building the container can take up to 20-30 minutes. Once built, make sure to run it with the appropriate environment variables mentioned in Section 4.

7. Run it with Akri and Kubernetes

  • If you are using K3s on a Linux device, please follow the ONVIF for IP cameras guide.

    Once you have your Kubernetes cluster running and Akri installed, run the following command to enable the ONVIF discovery:

    sudo ip route add 239.255.255.250/32 dev cni0

    Note: If you're not using Flannel, you may need to check the Kubernetes network interface name and change it above.

    1. Find the IP of the mock ONVIF container:
    kubectl get pods -o wide
    1. Run route and find the network interface name that matches the IP of the ONVIF pod (i.e. cali909b8c65537).
    2. Now enable the ONVIF discovery:
    sudo ip route add 239.255.255.250/32 dev <insert interface name>
  • If you are using AKS Edge Essentials, please follow the Discover ONVIF cameras with Akri guide.

    Once you have your Kubernetes cluster running and Akri installed, run the following PowerShell command to enable the ONVIF discovery:

    Invoke-AksEdgeNodeCommand -command "sudo ip route add 239.255.255.250/32 dev cni0"

    Note: If you're not using Flannel, you may need to check the Kubernetes network interface name and change it above.

    1. Find the IP of the mock ONVIF container:
    kubectl get pods -o wide

    2.Find the network interface name that matches the IP of the ONVIF pod (i.e. cali909b8c65537):

    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "route"
    1. Now enable the ONVIF discovery:
    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "sudo ip route add 239.255.255.250/32 dev <insert interface name>"

    If you're using Scalable-cluster with an External virtual switch, you will need to enable the --dport 3702 and --sport 3702 firewall rule using the following command:

    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "sudo iptables -A INPUT -p udp --dport 3702 -j ACCEPT"
    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "sudo sed -i '/-A OUTPUT -j ACCEPT/i-A INPUT -p udp -m udp --dport 3702 -j ACCEPT' /etc/systemd/scripts/ip4save"   
    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "sudo iptables -A INPUT -p udp --sport 3702 -j ACCEPT"
    Invoke-AksEdgeNodeCommand -NodeType "Linux" -command "sudo sed -i '/-A OUTPUT -j ACCEPT/i-A INPUT -p udp -m udp --sport 3702 -j ACCEPT' /etc/systemd/scripts/ip4save" 

    If you everything was correctly set up, you should see the mocked camera discovered by Akri.

    PS C:\Users\Administrator\Desktop> kubectl get akrii
    NAME                CONFIG       SHARED   NODES             AGE
    akri-onvif-c9582f   akri-onvif   true     ["node1-ledge"]   7m28s
    PS C:\Users\Administrator\Desktop>

    8. Using a custom video RTSP feed

    Finally, if you want to create an RTSP feed with a custom video, copy the video file into the AKS-EE host first. For example, if you want to use the sample.mp4 file from your directory C:\Users\Admin\sample.mp4, copy it to the AKS-EE Linux node /home/aksedge-user/sample.mp4 file using the following cmd:

    Copy-AksEdgeNodeFile -FromFile C:\Users\fcabrera\Downloads\sample-15s.mp4 -toFile /home/aksedge-user/sample.mp4 -PushFile

    For more information, see Copy-AksEdgeNodeFile.

    Last step is to modify your Pod deployment to mount the necessary file and use that file in the RTSP streamer server. The following example uses the public docker container and mounts the file sample.mp4 to create the RSTP stream, but you can change the deployment for your environment.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: onvif-camera-mocking
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: onvif-camera-mocking
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
      minReadySeconds: 5    
      template:
        metadata:
          labels:
            app: onvif-camera-mocking
        spec:
          nodeSelector:
            "kubernetes.io/os": linux
          containers:
          - name: azure-vote-front
            image: winiotsaleskit.azurecr.io/onvif-camera-mocking:latest
            ports:
            - containerPort: 8554
            - containerPort: 1000
            - containerPort: 3702
            env:
            - name: INTERFACE
              value: "eth0"
            - name: DIRECTORY
              value: "/onvif-camera-mock"
            - name: MP4FILE
              value: /mnt/sample.mp4
            volumeMounts:
            - name: sample-volume
              mountPath: /mnt
          volumes:
          - name: sample-volume
            hostPath:
              path: /home/aksedge-user
              type: Directory

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 57.1%
  • C 33.8%
  • Makefile 5.9%
  • Python 1.9%
  • Shell 1.3%