Unifi Protect with Amcrest cameras

Best way to leverage your existing camera(s) on UDR or Unifi Protect is via Unifi Cam Proxy on GitHub.

It will create a dummy Unifi G3 Micro camera and enable you to use your RTSP (Real Time Streaming Protocol) enabled cameras even if they are not Unifi.

Optimal setup of Unifi Cam Proxy is via Docker on Raspberry Pi with the standard Raspbian OS on Pi.

Raspberry Pi Imager

Remember that if you are doing a clean install of OS on Pi, you will need to have keyboard and screen via HDMI to enable SSH, or you can edit the SSH file before you turn PI on.

Putty

Putty is the easiest and best tool to connect to Pi via SSH.

You need to know the IP address of the Pi, check the router screen or if you have it connected via HDMI, just type ifconfig.

Initial Raspberry Pi configuration

Once you have Raspbian OS installed on MicroSD, boot it and make sure you do the basics:

  • Change default password (Pi / Raspberry) = passwd
  • Enable Wifi and connect to your local network = raspi-config
  • Update to latest version = sudo apt update and sudo apt full-upgrade
  • Clean up old packages = sudo apt clean

Install Docker and Docker Compose on Raspberry Pi

  • Check Raspberry Pi OS version = cat /etc/os-release
  • Install Docker using this 1 line command: curl -sSL https://get.docker.com/ | sh
  • Check Docker version = docker version
  • Add user permission to docker group
sudo usermod -aG docker ${USER}
groups ${USER}
  • Install Docker Compose
sudo apt-get install libffi-dev libssl-dev
sudo apt install python3-dev
sudo apt-get install -y python3 python3-pip
sudo pip3 install docker-compose

Enable Docker at startup sudo systemctl enable docker

I suggest a sudo reboot of the Raspberry Pi and a test of Hello World docker run hello-world and you should get “Hello from Docker!”

UniFi Cam Proxy

Pre requirements includes few steps

1. Self-signed certificate generation created from another UniFi camera or directly from Raspberry Pi OS. These are steps to generate /tmp/client.pem certificate:

openssl ecparam -out /tmp/private.key -name prime256v1 -genkey -noout
openssl req -new -sha256 -key /tmp/private.key -out /tmp/server.csr -subj "/C=TW/L=Taipei/O=Ubiquiti Networks Inc./OU=devint/CN=camera.ubnt.dev/emailAddress=support@ubnt.com"
openssl x509 -req -sha256 -days 36500 -in /tmp/server.csr -signkey /tmp/private.key -out /tmp/public.key
cat /tmp/private.key /tmp/public.key > client.pem
rm -f /tmp/private.key /tmp/public.key /tmp/server.csr
cp /tmp/client.pem /home/pi/Documents/client.pem
cd /home/pi/Documents/
ls
Add new Device in UDR

2. Adoption token created in Protect UI page in UDR [valid for 60 minutes from time of generation]

  • Open https://{UDR_IP}/protect/devices/add
  • Login with your Unifi credential
  • Select G3 Micro from “Select device to add” list
  • Select “Continue on Web” and type random text in SSID / Password fields
  • Click “Generate QR Code”
  • Save QR Code as image file
  • Upload QR Code to https://zxing.org/w/decode.jspx
  • Extract the token above UDR IP in the ‘Raw Text’ field
  • Adoption token looks like this: cpZaMhfzmBgAqLIHPR0psvoMp3mvCDtu
Adoption token extraction

3. Confirm RTSP support for your cameras using VideoLan Client VLC -> Network Stream.
For Amcrest cameras, the default local credential is admin / admin and RTSP standard URL has this format rtsp://[username]:password@CAM_IP:554/cam/realmonitor?channel=1&subtype=0

RTSP test in VLC

Docker configuration

Make sure you have all pre requirements completed before you move fwd with the docker configuration file:

  • Certificate /home/pi/Documents/client.pem
  • Adoption Token cpZaMhfzmBgAqLIHPR0psvoMp3mvCDtu
  • RTSP URL for your camera rtsp://[username]:password@CAM_IP:554/cam/realmonitor?channel=1&subtype=0
  • Docker is working properly and you have permission to run container

Create Docker Compose YAML file in /home/pi/Documents/docker-cameras.yaml using VI docker-cameras.yaml

version: "3.9"
services:
  unifi-cam-proxy-1:
    restart: unless-stopped
    image: keshavdv/unifi-cam-proxy
    volumes:
      - "./client.pem:/client.pem"
    command: unifi-cam-proxy --host {UDR_IP} --mac {CAM_MAC1} --cert /client.pem --token {Adoption token} rtsp -s rtsp://[username]:password@CAM_IP1:554/cam/realmonitor?channel=1&subtype=0 --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=50"'
  unifi-cam-proxy-2:
    restart: unless-stopped
    image: keshavdv/unifi-cam-proxy
    volumes:
      - "./client.pem:/client.pem"
    command: unifi-cam-proxy --host {UDR_IP} --mac {CAM_MAC2} --cert /client.pem --token {Adoption token} rtsp -s rtsp://[username]:password@CAM_IP2:554/cam/realmonitor?channel=1&subtype=0 --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=50"'

Start Docker Compose with docker-compose -f /home/pi/Documents/docker-cameras.yaml up -d --remove-orphans

Wait for download and extract of all the components needed.

Connect to UDR https://{UDR_IP}/protect/devices/ and verify you can see the cameras:

Amcrest cameras added to UniFi Protect

Stop Docker Compose with docker-compose -f docker-cameras.yaml down

Please note that CPU load is high on Raspberry PI during live streaming, monitor it with top command:

Optimize CPU load

Amcrest cameras stream using H.265 codec for video and AAC codec for audio as you can review in VLC -> Tools -> Codec Information:

Amcrest streaming information

Unifi Cam Proxy settings expect H.264 codec which causes a lot of overload on Raspberry Pi CPU and ffmpeg library to transcode from H.265 to H.264 codec.

Unifi G3 Micro streams in H.264 with bi-directional audio as reported in the quick start guide

Unifi G3 Micro Video / Audio specifications

Docker command in YAML file provides arguments to ffmpeg library --ffmpeg-args '-c:v copy -vbsf "h264_metadata=tick_rate=50"' and according to ffmpeg documentation:

  • -c:v copy define the codec name and specifically, set FFmpeg to copy the bitstream of the video to the output
  • -vbsf "h264_metadata=tick_rate=50" set the video bitstream and codec to H264 [deprecated]

Reducing frame rate and resolution

Amcrest cameras have 2 substreams on channel #1 you can connect:

SubStreamResolutionCodecURL
01920×1080
@ 30 fps
H.265 hevc with AAC MP4rtsp://[usr]:psw@CAM_IP:554/cam/realmonitor?channel=1&subtype=0
1640×480 @ 30 fpsH.264 AVC
with AAC MP4
rtsp://[usr]:psw@CAM_IP:554/cam/realmonitor?channel=1&subtype=1
Available SubStream in Amcrest camera

Using SubStream #1 which is VGA, instead of SubStream #0 (Full HD) allows to have PI at ~30% CPU load.

VGA resolution on H264

Sources:

Advertisement

Foscam FI8905W – Settings to do

Hack to wide IR Led angle = add oven paper or best greaseproof paper which wide illumination angle

ZoneMinder – Wiki – Foscam = path to integrate video streaming from website

iSpy free software = configure software on computers

Email settings for Gmail

4mm lens for FI8905W = 4mm Fixed Iris Lens 1/3″ CS F1.6 IR Corrected

Steps to change lens = from 12mm to 2.8mm

Lens 4mm similar

Lens 4mm ebay

Outdoor Wireless IP Camera – Foscam FI8905W

Foscam FI8905W Outdoor Wireless IP Camera – Outdoor Cameras.

 

Model

FI8905W

Resolution

640 x 480 Pixels(300k Pixels)

Color

White

Image Sensor

1/4″ Color CMOS Sensor

Display Resolution

640 x 480 Pixels(300k Pixels)

Lens

f: 6mm (8mm and 12mm Optional), F: 1.2 (IR Lens)

Mini Lumination

0.5Lux

Lens Type

Glass Lens

Viewing Angle

42 Degree (30 Degree and 22 Degree Optional)

Input

N/A

Output

N/A

Audio Compression

N/A

Image Compression

MJPEG

Image Frame Rate

15fps(VGA),30fps(QVGA)

Flip Mirror Images

Vertical / Horizontal

Light Frequency

50Hz, 60Hz or Outdoor

Video Parameters

Brightness, Contrast

Ethernet

One 10/100Mbps RJ-45

Wireless Standards

IEEE 802.11b/g

Data Rate

802.11b: 11Mbps(Max.), 802.11g: 54Mbps(Max.)

Wireless Security

WEP & WPA & WPA2 Encryption

Pan/Tilt Angle

No Pan/Tilt

Infrared Light

60 IR LEDs,Night visibility up to 30 metres

Gross Weight

953g (Color Box Size:250x120x200mm)

Net Weight

953g

Storage Temperature

-10°C ~ 60° (14°F ~ 140°F)

Storage Humidity

0% ~ 90% non-condensing

CPU

2.0GHZ or above (suggested 3.0GHz)

Memory Size

256MB or above (suggested 1.0GHz)

Display Card

64M or above

Supported OS

Microsoft Windows 2000/XP/VistaWindows 7

Browser

IE 6.0, IE7.0,IE8.0,Firefox or other standard browsers

Certification

CE,FCC

Warranty

Limited 1-year warranty

 

 

 

Apexis APM-J011-WS Wireless IP Camera

 

APM-J011-WS Wireless IP Camera.

New Feature:

> Iphone APP downloadable (app: Apexis IP Control)

> Support Gmail/Hotmail function

> 15 preset positions monitoring

> Free DDNS for Remote viewing

> Freely control alarm sound ON/OFF

> Freely control alarm record ON/OFF

> More than 14 languages for worldwide users

> Support VLC mode

> Support MSN feature

Basic Feature:

> MJPEG video compression format

> Built-in Microphone and Speaker

> Support two-way audio function

> Freely control upload image to FTP

> Freely control Pan/Tilt angle by software

> Freely control Pan/Tilt speed by software

> Freely control network indicator LED on/off

> Support up to 9 users online simultaneously

> Motion detection alert with snapshots via email

> Allow remote view & record from anywhere anytime

> Multi-level user management with password protection

> Wi-Fi compliant with wireless standards IEEE 802.11b/g

> Support both WEP & WPA WPA2 encryption for wireless

> Support Mobile phone login from User Interface via browser directly

> Support IE, Safari, Firefox, Google chrome browser or any other standard browsers

 

Specification: Model: APM-J011-WS

Image  Sensor

 Image Sensor

1/4″ Color CMOS Sensor

 Display Resolution

640 x 480 Pixels(300k Pixels)

 Lens

f: 6 mm, F:2.0 (IR Lens)    (3.6mm lens optional)

 Mini. Illumination

0.5Lux

Lens

 Lens Type

Glass Lens

 Viewing Angle

60 Degree               (3.6mm lens is 90Degree)

Audio

 Input

Built-in Microphone

 Output

Built-in Speaker

 Audio Compression

ADPCM

Video

 Image Compression

MJPEG

 Image Frame Rate

15fps(VGA),30fps(QVGA)

 Resolution

640 x 480(VGA), 320 x 240(QVGA)

 Flip Mirror Images

Vertical / Horizontal

 Light Frequency

50Hz, 60Hz or Outdoor

 Video Parameters

Brightness, Contrast

Communication

 Ethernet Interface

Build in 10/100Mbps,Auto MDI/MDIX , RJ-45

 Supported Protocol

HTTP,FTP,TCP/IP, UDP, SMTP, DHCP, PPPoE, DDNS, UPnP, GPRS

 Wireless Standard

IEEE 802.11b/g

 Data Rate

802.11b: 11Mbps (Max.), 802.11g: 54Mbps (Max.)

 Wireless Security

WEP & WPA WPA2 Encryption

Physical

 Pan/Tilt Angle

Horizontal:270° & Vertical: 120°

 Infrared Light

10 IR LEDs, Night visibility up to 10 meters

 Alarm Input

1 Channel on/off Input

 Alarm Output

1 Channel relay Output

 Dimension

100(L) x100(W) x120mm(H)

 Gross Weight

App. 750g

 Color Box

210 x 130 x 190 mm

 Net Weight

App. 550g

Power

 Power Supply

DC 5V/2.0A (EU,US,AU adapter or other types optional)

 Power Consumption

5 Watts (Max.)

Environment

 Operate Temper.

0° ~ 55°C  (14°F ~ 131°F)

 Operating  Humidity

20% ~ 85% non-condensing

 Storage Temper.

-10°C ~ 60° (14°F ~ 140°F)

 Storage Humidity

0% ~ 90% non-condensing

PC System Requirements

 CPU

2.0GHZ or above (suggested 3.0GHz)

 Memory Size

256MB or above (suggested 1.0GHz)

 Display Card

64M or above

 Supported OS

Microsoft Windows 2000/XP/Vista/7

 Browser

IE6.0/7.0/8.0/Firefox/Safari/Google chrome or other standard browsers

Certification

 CE, FCC, RoHS

Warranty

 Limited 1-year warranty