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
Note: these steps only work on Linux and have only been tested on Ubuntu 22.04LTS
-
Install building dependencies
sudo apt update sudo apt install flex bison byacc make m4 autoconf unzip \ git g++ wget -y
-
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
-
Clone the repository
git clone https://github.com/fcabrera23/onvif-camera-mock
The onvif_srvd project was forked, and the updated original dependencies to keep it up to date with gsoap version and fix broken dependencies.
-
Build the onvif_srvd
cd onvif_srvd make release
-
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
The wsdd project was forked, and the updated original dependencies to keep it up to date with gsoap version and fix broken dependencies.
-
Move to the project root folder and build the wsdd
cd wssd make release
-
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
-
Run
ifconfig
oripconfig
to determine your network interface. Then, pass your interface (such aseno1
,eth0
,eth1
, etc) to the script. The following assumeseth0
. -
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
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.
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.
-
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.
- Find the IP of the mock ONVIF container:
kubectl get pods -o wide
- Run
route
and find the network interface name that matches the IP of the ONVIF pod (i.e.cali909b8c65537
). - 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.
- 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"
- 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>
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