[Sharing] DIY CCTV with AMB82-MINI & Frigate 0.14

Hey everyone! :smiling_face:

I just released a video on setting up a DIY CCTV system using the AMB82-MINI with Frigate 0.14. In this video, I walk through how I’ve used the AMB82-MINI as the camera for the system and share some detailed setup and configuration.

Highlights include:

  1. System Overview: Using the AMB82-MINI, a Lenovo Yoga 520, and Frigate 0.14 to create a complete setup.
  2. Frigate 0.14 Features: Exploring the new interface, recording playback, and configuration tips.
  3. AMB82-MINI Review: Pros, cons, and how it compares to previous setups.

I dive into configuring both the AMB82-MINI and Frigate, share some insights, and discuss the performance of the AMB82-MINI for both high and low-resolution streams. The AMB82-MINI has been a game-changer for me, offering robust features and better performance than my previous ESP32-CAM.

Check out the video here:

DIY CCTV with AMB82-MINI & Frigate 0.14

How did I build it

  1. First I programmed the AMB82-MINI and placed it in a dummy CCTV camera.
  2. I then connected the USB port to a USB Extender over RJ45 since it’s operating outside. It’s a passive extender, and it’s possible to power the AMB82-MINI over 5 meters, but there’s a catch see while it does work for long distance, but the supply voltage is reduced as other factors come into play (ex. distance, resistance, adapter used, etc.). In my experience, using a bad power supply can cause noise to the video and using a bad rj45 extender (those manufactured without the extra capacitor in the PCB) also overtime voltage drop, I noticed in 4 days my amb82-mini would die out due to lack of voltage, the fix is short term fix is a power cycle/rebooting by disconnecting and reconnecting the plug. I’m attempting to replace my current USB extender over rj45 to another brand and test if it fixes the issue.
  3. I then placed it under an Aluminum Umbrella to protect the AMB82-MINI Outdoors, it has survived hot weather like above 50 degrees Celsius outdoors, survived heavy rains, and survived windy weather from typhoons.
  4. I Connected the RTSP Server in Frigate, with the code below.

AMB82-MINI Code:

I used the default Double Video With Audio Template code and changed the channel used in Video Setting configV1 and configV2 to 1080p and 720p respectively. I used a lower resolution on the substream because I thought it would be stressful on my CPU back then using openvino as the substream is used for detection in frigate.

/*

 Example guide:
 https://www.amebaiot.com/en/amebapro2-arduino-video-rtsp/
 */

#include "WiFi.h"
#include "StreamIO.h"
#include "VideoStream.h"
#include "AudioStream.h"
#include "AudioEncoder.h"
#include "RTSP.h"

// Default preset configurations for each video channel:
// Channel 0 : 1920 x 1080 30FPS H264
// Channel 1 : 1280 x 720  30FPS H264
// Channel 2 : 1280 x 720  30FPS MJPEG

// Default audio preset configurations:
// 0 :  8kHz Mono Analog Mic
// 1 : 16kHz Mono Analog Mic
// 2 :  8kHz Mono Digital PDM Mic
// 3 : 16kHz Mono Digital PDM Mic

VideoSetting configV1(VIDEO_FHD, CAM_FPS, VIDEO_H264, 0);    //Mainstream
VideoSetting configV2(VIDEO_HD, CAM_FPS, VIDEO_H264, 1);     //Substream
AudioSetting configA(1);
Audio audio;
AAC aac;
RTSP rtsp1;
RTSP rtsp2;
StreamIO audioStreamer(1, 1);   // 1 Input Audio -> 1 Output AAC
StreamIO avMixStreamer(3, 2);   // 3 Input Video1 + Video2 + Audio -> 2 Output RTSP1 + RTSP2

char ssid[] = "";   // your network SSID (name)
char pass[] = "";       // your network password
int status = WL_IDLE_STATUS;

void setup() {
    Serial.begin(115200);

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to WPA SSID: ");
        Serial.println(ssid);
        status = WiFi.begin(ssid, pass);

        // wait 2 seconds for connection:
        delay(2000);
    }

    // Configure both camera video channels with corresponding video format information
    // Adjust the bitrate based on your WiFi network quality
    //configV1.setBitrate(2 * 1024 * 1024);     // Recommend to use 2Mbps for RTSP streaming to prevent network congestion
    //configV2.setBitrate(2 * 1024 * 1024);     // Recommend to use 2Mbps for RTSP streaming to prevent network congestion
    Camera.configVideoChannel(0, configV1);
    Camera.configVideoChannel(1, configV2);
    Camera.videoInit();

    // Configure audio peripheral for audio data output
    audio.configAudio(configA);
    audio.begin();
    // Configure AAC audio encoder
    aac.configAudio(configA);
    aac.begin();

    // Configure both RTSP with corresponding video format information
    rtsp1.configVideo(configV1);
    rtsp1.configAudio(configA, CODEC_AAC);
    rtsp1.begin();

    rtsp2.configVideo(configV2);
    rtsp2.configAudio(configA, CODEC_AAC);
    rtsp2.begin();

    // Configure StreamIO object to stream data from audio channel to AAC encoder
    audioStreamer.registerInput(audio);
    audioStreamer.registerOutput(aac);
    if (audioStreamer.begin() != 0) {
        Serial.println("StreamIO link start failed");
    }

    // Configure StreamIO object to stream data from video channels and AAC encoder to rtsp outputs
    avMixStreamer.registerInput1(Camera.getStream(0));
    avMixStreamer.registerInput2(Camera.getStream(1));
    avMixStreamer.registerInput3(aac);
    avMixStreamer.registerOutput1(rtsp1);
    avMixStreamer.registerOutput2(rtsp2);
    if (avMixStreamer.begin() != 0) {
        Serial.println("StreamIO link start failed");
    }

    // Start data stream from video channels
    Camera.channelBegin(0);
    Camera.channelBegin(1);

    delay(1000);
    printInfo();
}

void loop() {
    // do nothing
}

void printInfo(void) {
    Serial.println("------------------------------");
    Serial.println("- Summary of Streaming -");
    Serial.println("------------------------------");

    Camera.printInfo();

    IPAddress ip = WiFi.localIP();

    Serial.println("- RTSP Information -");
    Serial.print("rtsp://");
    Serial.print(ip);
    Serial.print(":");
    rtsp1.printInfo();

    Serial.print("rtsp://");
    Serial.print(ip);
    Serial.print(":");
    rtsp2.printInfo();

    Serial.println("- Audio Information -");
    audio.printInfo();
}

Frigate Configuration Code:
Here is my code in frigate, as you can see I’ve set it up in a way that is matched to my system, I’m using the Google Coral for detection. When it uses FFmpeg in go2rtc i use video=copy and audio=copy since the AMB82-MINI is already using H.264 and AAC making it already compatible in Frigate 0.14. I used preset-rtsp-restream so that I can watch the stream it in other devices and lastly i have set the “detect” to 1280x720 because the substream (which configV2 in the AMB82-MINI Code) is also set to 720p, the frames are recommended in frigate to be 5~10 as the TPU is used for the detection.

mqtt:
  enabled: false

ffmpeg:
  hwaccel_args: preset-vaapi

go2rtc:
  streams:
    camera1:
      - ffmpeg:rtsp://192.168.xxx.xxx:554/0#video=copy#audio=copy
    camera1_sub:
      - ffmpeg:rtsp://192.168.xxx.xxx:555/0#video=copy#audio=copy

cameras:
  camera1:
    ffmpeg:
      inputs:
        # High Resolution Stream
        - path: rtsp://127.0.0.1:8554/camera1
          input_args: preset-rtsp-restream
          roles:
            - record
        # Low Resolution Stream
        - path: rtsp://127.0.0.1:8554/camera1_sub
          input_args: preset-rtsp-restream
          roles:
            - detect
            - audio
      output_args:
        record: preset-record-generic-audio-copy
    detect:
      width: 1280
      height: 720
      fps: 10
    snapshots:
      enabled: true
    record:
      enabled: true
      retain:
        days: 21
      events:
        retain:
          default: 21

objects:
  track:
    - person
    - car
    - bicycle
    - motorcycle
    - dog
    - umbrella

birdseye:
  enabled: false

#logger:
#  default: info
#  logs:
#    frigate.record.maintainer: debug

detectors:
  coral:
    type: edgetpu
    device: pci

version: 0.14

2 Likes