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

[RSDK-8274, RSDK-8624, RSDK-8647, RSDK-8687] Video Storage and Save/Fetch DoCommand #7

Closed
wants to merge 129 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 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
477f1a6
Remove vision service integration
seanavery Aug 27, 2024
982ce07
Change triplet
seanavery Aug 27, 2024
dd098b3
Update storage config
seanavery Aug 27, 2024
d3335f8
Add optional storage_path
seanavery Aug 28, 2024
3f4c883
Add name to default storage and upload path
seanavery Aug 28, 2024
558ea94
Rename to video store
seanavery Aug 28, 2024
71194ee
Fix make naming
seanavery Aug 28, 2024
d4010d2
Naming fix
seanavery Aug 28, 2024
5e9a3ce
Merge pull request #5 from viam-modules/vision-yeet
seanavery Aug 28, 2024
065b157
Remove debug ffmpeg logger
seanavery Aug 28, 2024
fcdf787
Add concat and h264 parser
seanavery Aug 29, 2024
d2b40fc
Concat initialization
seanavery Aug 29, 2024
e2aeb08
Add annexb bitstream filter
seanavery Aug 29, 2024
d9e52ac
Concat writes working
seanavery Aug 29, 2024
58392d0
Input validation
seanavery Aug 29, 2024
39c871c
Validate and match by time range
seanavery Aug 30, 2024
fae564e
Handle metadata string
seanavery Aug 30, 2024
ca23a8d
Abstract datetime parser
seanavery Aug 30, 2024
f5881e3
Create new concat struct
seanavery Aug 30, 2024
30762d9
Cleanup
seanavery Sep 3, 2024
a5654e8
Delete fetch comp name
seanavery Sep 3, 2024
d752970
close
seanavery Sep 3, 2024
aaea5ec
Comment helpers
seanavery Sep 3, 2024
e5a1c4c
concat
seanavery Sep 3, 2024
0422835
Add comments to concat flow
seanavery Sep 3, 2024
3322c46
Specify concat file location
seanavery Sep 3, 2024
ce73a77
Fix upload path
seanavery Sep 3, 2024
2db1577
Update readme
seanavery Sep 3, 2024
63b4f06
Lint
seanavery Sep 3, 2024
0129fed
Ignore bin
seanavery Sep 3, 2024
991dbf5
New line
seanavery Sep 3, 2024
1173352
Breakup long pointer arithmetic lines
seanavery Sep 3, 2024
5029eb0
Add more comments to concat operation
seanavery Sep 3, 2024
8093d04
Improve validate flow
seanavery Sep 3, 2024
df64d71
cleanup
seanavery Sep 3, 2024
94f4c19
Fix upload file name
seanavery Sep 4, 2024
2577335
Merge branch 'main' into save-cmd-review
seanavery Sep 4, 2024
76a6de3
Merge branch 'save-cmd' into save-cmd-review
seanavery Sep 4, 2024
87e20e7
Change profile name
seanavery Sep 4, 2024
3f8b4e5
Remove old todos
seanavery Sep 4, 2024
16993f5
Handle trimming in concat demuxer
seanavery Sep 4, 2024
fcab4f4
Add fetch command
seanavery Sep 4, 2024
29848c7
Remove trivial close flag
seanavery Sep 5, 2024
796015a
Organize nimplemented methods
seanavery Sep 5, 2024
0c6129a
Bump rdk and goutils dep
seanavery Sep 5, 2024
c702035
lint
seanavery Sep 5, 2024
3fb3924
Defer ffmpeg cleanup
seanavery Sep 5, 2024
9640348
Organize pointer arithmetic
seanavery Sep 5, 2024
52ba17e
make lint happy
seanavery Sep 5, 2024
b19551d
Comment clarity
seanavery Sep 5, 2024
9e48e06
Group free
seanavery Sep 5, 2024
a48bc1b
Remove copy
seanavery Sep 5, 2024
a8fc69a
Add omitempty flags
seanavery Sep 5, 2024
e114a23
Add codec enum handlers
seanavery Sep 5, 2024
77ad5f2
Change to viam namespace
seanavery Sep 5, 2024
546a31c
Unexport codec enum stuff
seanavery Sep 5, 2024
71bdb77
Fix module ref
seanavery Sep 5, 2024
e42f2e8
Include codec id lookups
seanavery Sep 5, 2024
f649b48
Dont return early on close
seanavery Sep 6, 2024
c74b5a6
Add configuration tests
seanavery Sep 6, 2024
b6e545e
Test make script
seanavery Sep 6, 2024
4d95d8a
Add sync attr and check data_manager service dep
seanavery Sep 6, 2024
85ab51e
Update readme
seanavery Sep 6, 2024
69c0db5
Add data manager checks to config tests
seanavery Sep 6, 2024
a7a174a
Check sync service has subtype data_manager
seanavery Sep 9, 2024
ac31aa2
Add git lfs config
seanavery Sep 9, 2024
ab9f2d5
Add test video clips
seanavery Sep 9, 2024
4e8d545
Add save do_command tests
seanavery Sep 9, 2024
e7909ee
Add invalid datetime save test
seanavery Sep 9, 2024
d171597
Format fix
seanavery Sep 9, 2024
6b98fa0
Pull in fetch
seanavery Sep 9, 2024
0706a70
Add todo comments for fetch
seanavery Sep 9, 2024
d67ae6f
Add fetch tests
seanavery Sep 9, 2024
e20b90d
Tmp path for fetch
seanavery Sep 9, 2024
011210a
Check max grpc size
seanavery Sep 9, 2024
8230a5d
Update readme
seanavery Sep 9, 2024
d54a527
Filename
seanavery Sep 10, 2024
204f579
Add clean script
seanavery Sep 10, 2024
1dd46bf
Move validate
seanavery Sep 10, 2024
c67818e
Do not overwrite the config
seanavery Sep 10, 2024
b3416e5
Release frame after encode
seanavery Sep 10, 2024
a5b998a
Check cam return is nil
seanavery Sep 10, 2024
cae1464
Check error msg
seanavery Sep 10, 2024
14efd1c
Remove todo comment
seanavery Sep 10, 2024
7ad11db
Remove props passthrough
seanavery Sep 10, 2024
3380049
Lint
seanavery Sep 10, 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 @@
vs:
image_amd64: ghcr.io/viamrobotics/antique2:amd64-cache
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessarily an actionable change, but what archs are we targeting for this module? Noticing that there is amd here as well

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope included inux/arm64, linux/amd64, and darwin/arm64 in the meta.json we're on the hook for.

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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.mp4 filter=lfs diff=lfs merge=lfs -text
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 @@
*video-store
FFmpeg
.env
*.DS_Store
bin
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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-demuxer=concat \
--enable-demuxer=mov \
--enable-demuxer=mp4 \
--enable-parser=h264 \
--enable-protocol=file \
--enable-protocol=concat \
--enable-protocol=crypto \
--enable-bsf=h264_mp4toannexb

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 test clean

$(BIN_OUTPUT_PATH)/video-store: *.go cam/*.go $(FFMPEG_BUILD)
go mod tidy
CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_CFLAGS=$(CGO_CFLAGS) go build -o $(BIN_OUTPUT_PATH)/video-store 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


test: $(BIN_OUTPUT_PATH)/video-store
git lfs pull
go test -v ./tests/

clean:
rm -rf $(BIN_OUTPUT_PATH)
rm -rf FFmpeg
git clean -fxd
102 changes: 102 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Video Storage
The `video-store` module brings security camera functionality to your smart machine! The module consumes a source [Camera](https://docs.viam.com/components/camera/) and saves the output as video files on disk. You can then upload video slices to the cloud using the [save](#save) command, or request the video bytes directly using the [fetch](#fetch) command.

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

## Configure your `video-store` component

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

```json
{
"name": <video_store_component_name>,
"namespace": "rdk",
"type": "camera",
"model": "viam:video:storage",
"attributes": {
"camera": <camera_component_name>, [required]
"sync": <data_manager_service_name>, [required]
"storage": { [required]
"segment_seconds": <length_of_video_segments>, [optional]
"size_gb": <total_storage_max_size>, [required]
"storage_path": <custom_path_to_store_video_files>, [optional]
"upload_path": <custom_path_to_upload_video_files>, [optional]
},
"video": { [optional]
"format": <video_format>, [optional]
"codec": <video_codec>, [optional]
"bitrate": <bits_pers_second>, [optional]
"preset": <video_preset>, [optional]
},
"cam_props": { [required]
"width": <pixel_width>, [required]
"height": <pixel_height>, [required]
"framerate": <frames_per_second>, [required]
},
},
"depends_on": [
<camera_component_name>, [required]
<data_manager_service_name> [required]
]
}
```

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_service_name>,
"namespace": "rdk",
"type": "data_manager",
"attributes": {
"tags": [],
"additional_sync_paths": [
<custom_path_to_upload_video_files>
],
"capture_disabled": true,
"sync_interval_mins": <sync_interval_minutes>,
"capture_dir": ""
}
}
```

## Do Commands
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to document do commands? Is it so that someone could integrate with this module in their own app if they wanted to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we need to document DoCommands in the README since the module is pretty much worthless without save/fetch interface.


### `save`

#### Save Request
```json
{
"command": "save",
"from": <start_timestamp>, [required]
"to": <end_timestamp>, [required]
"metadata": <arbitrary_metadata_string> [optional]
}
```

#### Save Response
```json
{
"command": "save",
"filename": <filename_to_be_uploaded>
}
```

### `fetch`

#### Fetch Request
```json
{
"command": "fetch",
"from": <start_timestamp>, [required]
"to": <end_timestamp> [required]
}
```

#### Fetch Response
```json
{
"command": "fetch",
"video": <video_bytes>
}
```
Loading
Loading