Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC #4

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ad7c9b4
poc in progress
seanavery Aug 5, 2024
6d80dad
Remove segment wrap
seanavery Aug 6, 2024
893d866
Add deleter routine
seanavery Aug 6, 2024
4d08c13
Clean up path setters
seanavery Aug 6, 2024
c882b9b
Remove segment list and csv helpers
seanavery Aug 6, 2024
7fa5f79
Add copy helper
seanavery Aug 6, 2024
2ab2177
fsnotify working
seanavery Aug 7, 2024
759fd7a
Simple detection handling
seanavery Aug 7, 2024
bc0f91c
Add upload path setter
seanavery Aug 7, 2024
e2d1bb2
Add mutex
seanavery Aug 7, 2024
aab2f56
Remove stale copier
seanavery Aug 7, 2024
a3625b4
Change detect config
seanavery Aug 7, 2024
57315de
Remove outdated test
seanavery Aug 7, 2024
cd1342f
Change output pattern
seanavery Aug 7, 2024
dc0f851
Quick fix to storage deleter
seanavery Aug 7, 2024
407b660
Remove extra spacing
seanavery Aug 7, 2024
6b7f6fe
Remove dotenv
seanavery Aug 7, 2024
b903538
Merge pull request #1 from viam-modules/simple-detect-tagging
seanavery Aug 7, 2024
4920daf
Comments
seanavery Aug 7, 2024
9d5513d
happy lint
seanavery Aug 7, 2024
e3e6ae2
Add folder creators for storage/upload
seanavery Aug 7, 2024
a365090
Comments are helpful
seanavery Aug 7, 2024
9e898d1
Try lint in CI
seanavery Aug 7, 2024
7c56445
Test lint
seanavery Aug 7, 2024
0a62bf1
Add ffmpeg build dep to lint
seanavery Aug 7, 2024
bc44c46
Support x86 build
seanavery Aug 7, 2024
2b8312d
Install libx264 if not avail
seanavery Aug 8, 2024
215a839
Add comments to enoder
seanavery Aug 8, 2024
7fde866
More comments
seanavery Aug 8, 2024
7154f76
Install libx264
seanavery Aug 8, 2024
dcf6e60
Fix ffmpeg install
seanavery Aug 8, 2024
cc978c0
Fix vcs issue
seanavery Aug 8, 2024
e302fd8
Make camera props configurable
seanavery Aug 8, 2024
15dfd27
Init readme
seanavery Aug 8, 2024
ac3aa96
Add camera props to attrs
seanavery Aug 13, 2024
12995ca
Remove cam prop defaults
seanavery Aug 19, 2024
cd905fd
Add error check to fs walk
seanavery Aug 19, 2024
11a7e33
Impl latest frame cache
seanavery Aug 19, 2024
a81f392
Merge pull request #2 from viam-modules/atomic-frame
seanavery Aug 19, 2024
0bdb4db
Remove comments
seanavery Aug 19, 2024
9a05b3e
Fetch timebase from encoder
seanavery Aug 19, 2024
e3e2023
Remove some todos
seanavery Aug 19, 2024
b6cb04f
Add cam_props to readme
seanavery Aug 19, 2024
fd3d230
Merge branch 'main' into poc-review-ref
seanavery Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .canon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fv:
image_amd64: ghcr.io/viamrobotics/antique2:amd64-cache
image_arm64: ghcr.io/viamrobotics/antique2:arm64-cache
image_arm: ghcr.io/viamrobotics/antique2:armhf-cache
minimum_date: 2023-10-26T20:00:00.0Z
update_interval: 168h0m0s
user: testbot
group: testbot
persistent: true
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: run linter on each commit

on:
push:
branches:
- main
paths:
- '**/**.go'
- 'Makefile'
- '.github/workflows/lint.yml'
pull_request:
paths:
- '**/**.go'
- 'Makefile'
- '.github/workflows/lint.yml'

jobs:
quality-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libx264-dev

- name: Run linter
run: make lint
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*filtered-video
FFmpeg
*.mp4
.env
*.DS_Store
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SOURCE_OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
SOURCE_ARCH ?= $(shell uname -m)
TARGET_OS ?= $(SOURCE_OS)
TARGET_ARCH ?= $(SOURCE_ARCH)
normalize_arch = $(if $(filter aarch64,$(1)),arm64,$(if $(filter x86_64,$(1)),amd64,$(1)))
SOURCE_ARCH := $(call normalize_arch,$(SOURCE_ARCH))
TARGET_ARCH := $(call normalize_arch,$(TARGET_ARCH))

BIN_OUTPUT_PATH = bin/$(TARGET_OS)-$(TARGET_ARCH)
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)

FFMPEG_TAG ?= n6.1
FFMPEG_VERSION ?= $(shell pwd)/FFmpeg/$(FFMPEG_TAG)
FFMPEG_VERSION_PLATFORM ?= $(FFMPEG_VERSION)/$(TARGET_OS)-$(TARGET_ARCH)
FFMPEG_BUILD ?= $(FFMPEG_VERSION_PLATFORM)/build
FFMPEG_OPTS ?= --prefix=$(FFMPEG_BUILD) \
--disable-shared \
--disable-programs \
--disable-doc \
--disable-everything \
--enable-static \
--enable-libx264 \
--enable-gpl \
--enable-encoder=libx264 \
--enable-muxer=segment \
--enable-muxer=mp4 \
--enable-demuxer=segment \
--enable-protocol=file \
--enable-protocol=concat \
--enable-protocol=crypto

# TODO: cleanup libx264 static link
CGO_LDFLAGS := "-L$(FFMPEG_BUILD)/lib -lavcodec -lavutil -lavformat -l:libjpeg.a /usr/lib/aarch64-linux-gnu/libx264.a -lz"
CGO_CFLAGS := -I$(FFMPEG_BUILD)/include
GOFLAGS := -buildvcs=false
export PKG_CONFIG_PATH=$(FFMPEG_BUILD)/lib/pkgconfig

.PHONY: lint tool-install

$(BIN_OUTPUT_PATH)/filtered-video: *.go cam/*.go $(FFMPEG_BUILD)
go mod tidy
CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS) go build -o $(BIN_OUTPUT_PATH)/filtered-video main.go

$(FFMPEG_VERSION_PLATFORM):
git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch $(FFMPEG_TAG) $(FFMPEG_VERSION_PLATFORM)

$(FFMPEG_BUILD): $(FFMPEG_VERSION_PLATFORM)
# Only need nasm to build assembly kernels for amd64 targets.
ifeq ($(SOURCE_OS),linux)
ifeq ($(SOURCE_ARCH),amd64)
which nasm || (sudo apt update && sudo apt install -y nasm)
endif
endif
cd $(FFMPEG_VERSION_PLATFORM) && ./configure $(FFMPEG_OPTS) && $(MAKE) -j$(NPROC) && $(MAKE) install

tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
github.com/edaniels/golinters/cmd/combined \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/rhysd/actionlint/cmd/actionlint

lint: tool-install $(FFMPEG_BUILD)
go mod tidy
CGO_CFLAGS=$(CGO_CFLAGS) GOFLAGS=$(GOFLAGS) $(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/.golangci.yaml
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Filtered Video
The `filtered-video` module brings security camera functionality to your smart machine! The module consumes a source [Camera](https://docs.viam.com/components/camera/) and a [Vision Service](https://docs.viam.com/services/vision/), saves the camera output as video files to disk, and filters which video clips are uploaded to the cloud based on triggers from the vision service.

> **Note:** This component is a work in progress and is not yet fully implemented.

## Configure your `filtered-video` component

Fill in the attributes as applicable to the component, according to the example below.

```json
{
"name": "fv-cam",
"namespace": "rdk",
"type": "camera",
"model": "viam:camera:filtered-video",
"attributes": {
"camera": "webcam-1", // name of the camera to use
"vision": "vision-service-1", // name of the vision service dependency
"storage": {
"clip_seconds": 30,
"size_gb": 100
},
"video": {
"format": "mp4",
"codec": "h264",
"bitrate": 1000000,
"preset": "medium"
},
"objects": {
"Person": 0.8 // label key and threshold value
},
"cam_props": { // camera properties of the source camera
"width": 640,
"height": 480,
"framerate": 30
},
},
"depends_on": [
"webcam-1",
"vision-service-1"
]
}
```

Make sure to configure a [Data Manager Service](https://docs.viam.com/services/data/cloud-sync/) to uplaod video files to the cloud.

```json
{
"name": "data_manager-1",
"namespace": "rdk",
"type": "data_manager",
"attributes": {
"tags": [],
"additional_sync_paths": [
"/home/viam/.viam/video-upload/"
],
"capture_disabled": true,
"sync_interval_mins": 1,
"capture_dir": ""
}
}
```
Loading
Loading