Skip to content

fcabrera23/onvif-camera-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

This project provides a set of tools and instructions for mocking an ONVIF-compliant IP camera and passing an RTSP stream to simulate a live video stream. It can be run as a Docker container or built locally. Users can also mount a volume or folder with the container to simulate the RTSP camera with the mounted video file.

Note

This project started as a fork from kate-goldenring/onvif-camera-mocking

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

Prerequsites

Note

These steps only work on Linux and have only been tested on Ubuntu 22.04LTS

  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

Getting started

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

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

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

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.

Build Docker container and run it with Kubernetes

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 previously.

  • 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>

    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

Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •