ep1cman / unifi-protect-backup

Python tool to backup unifi event clips in realtime
MIT License
576 stars 25 forks source link

Continuous Backups #93

Closed wolveix closed 1 year ago

wolveix commented 1 year ago

Hey! Apologies if this is covered in your documentation, I couldn't find it anywhere.

Is it possible instead of uploading events, to simply backup days in segments? For example, I'd ideally like to be able to backup full days in 10-minute segments, rather than a bunch of tiny events. My main reason being that I have a camera in my living room, which ends up triggering a staggering amount of events. Reviewing the footage is rather frustrating for this reason :)

Thanks!

IgorWolbers commented 1 year ago

You could create a service or cron job that starts and stops recurring at a specific time of day. See the documentation on how to setup the service. Give it enough time to catch up on backups and that should mimic what you are asking for I think.

wolveix commented 1 year ago

@IgorWolbers I appreciate the quick response :) I'm running it as a Docker container, and it's currently catching up on past events. Are you suggesting it'll start uploading set interval segments after this process has completed? If so, how and I tweak the segment length? Or perhaps I'm misunderstanding something :)

Edit: From re-reading your response, I think you're suggesting that setting up a cron job at this interval will achieve what I want, in which case I think that one of us is misunderstanding the other :D As far as I can tell, this service pulls registered events from Protect, rather than grabbing segmented sections. Your suggestion would limit downloads and such to that timeframe, but the end result would remain the same. Please do correct me if I'm wrong!

ep1cman commented 1 year ago

Hi,

While this tool could be adapted to continously spit out N-minute long segments, I deem this out of scope for this tool. The API provided by unifi protect from my experience is kinda flaky and prone to crashing etc. So instead of relying on this API, for backing up continious camera feeds, I feel there is a much better solution: RTSP.

Many tools already exist out there that are able to make recordings from an RTSP stream. A quick experiment with ffmpeg allowed me to save 10s clips with the following command:

ffmpeg -rtsp_transport tcp -y  -i "rtsps://RTSP_URL_FROM_UNIFI_PROTECT" -c:v copy -c:a copy -f ssegment -segment_time 10 -segment_atclocktime 1 -strftime 1 -reset_timestamps 1 recordings/%Y-%m-%d_%H-%M-%S.mkv
wolveix commented 1 year ago

Ah, I didn't even think of using RTSP! I've got a lot of experience with FFmpeg, so that should be straight forward. Thank you so much @ep1cman!