Short recap (TLDR)
— Goal is to use Shinobi and Wyze cams. Cheap, easy and effective home solution.
— Wyze cams support RTSP via separate outdated firmware.
— Even with this fw RTSP appears to be laggy and sometimes stalls randomly.
— There is a hack allowing you to emulate SD-card and make camera write all footage on NFS share in your LAN. This hack is supported on new official firmwares.
— I made a script that makes realtime HLS stream based on these files from NFS.
— This stream is consumbed by Shinobi.
— PROFIT: I use latest official firmware and get stable recordings in Shinobi with all the juicy features 🎉
You can find my tool and short manual to it on github: https://github.com/n1ckyrush/wyzecam-hls
Long story. Choosing software & hardware.
I've decided to setup video surveillance at my new house. I'm a frugal engineer, and I want to get more quality with less expenses.
For cameras my choice was obvious — Wyze Cam.
1080p, H264, 15/10 FPS, 110° FOV, WiFi — sounds pretty sweet.
Cheap as dirt. $19.99 per camera (now it's $25.99, but anyway), plus ~$5 for an outdoor case if needed.
For software, it should be something modern with above average UI/UX with all essential features such as browsing videos by dates, timelapses and etc.
I've found an amazing product called Shinobi which is made basically by one guy (props to Moe) using node.js and ffmpeg.
The project is extremely actively maintained and get new features and bugfixes almost every day.
Okay, I have hardware and software, now there is the easiest part: just to connect these two pieces.
Ha. That's when my misery started.
WyzeCam + RTSP = 💔
Wyze Cam uses their own mobile app that allows you to manage cameras, view recordings and other stuff.
It's really nice and smooth, I like it. But the thing is that it doesn't support RTSP out of the box, and I need to link cameras with Shinobi somehow.
Thankfully, there is an official firmware from Wyze team that adds RTSP support to the camera.
The only thing is that it was released pretty long time ago and not actively maintained comparing to their stable firmware.
I have 6 Wyze cameras and I've installed RTSP firmware on all of them.
I've spent a couple months playing with different solutions and settings, but results are quite sad.
There is something with RTSP stream or with camera hardware which break stream sometimes. Sometimes Shinobi cannot pick it up until I restart Shinobi or camera. Sometimes there might be missing periods of time from 1 to 30 minutes. I've tried playing with all the settings, tried TCP/UDP, different probe size - results are kind of random. UDP works better but produces some green artifacts on videos which indicates that this is a bad WiFi connection due to lost packets.
I even tried to use different more powerful routers and wifi repeaters in my house because I thought that it might be something with the signal. Didn't work. It can work fine for a week, then produce glitches every day for a month.
Maybe firmware is glitchy, maybe hardware is not powerful enough to encode RTSP stream and provide stream to the mobile app at the same time, maybe something wrong with Shinobi or ffmpeg, I don't know 🤯. I've invested in this issue much more time than I would want to.
It's a pretty well-known fact, if you search for "wyze rtsp stability", you will find bunch of threads on reddit and official forums all describing the same issue.
Also, I've tried another app called motioneye, and to be honest it worked quite good with Wyze RTSP firmware, I don't know why.
It was pretty stable and I didn't have issues such as with Shinobi. But I didn't like motioneye because it feels pretty old and provides limited amount of features.
NFS instead of SD card? What?
I almost gave up at some point, I had Shinobi running at my home server with all the cameras, and it was working most of the time. Fine.
But one day when I needed to check some delivery guy, it appeared that the camera was offline exactly in that moment when I needed the footage. Damn. It really made me angry and I started looking on reddit for some solution, maybe some bright mind finally figured out that RTSP issue, who knows...
So, I've discovered that there is one genius who made a hack making camera think that some NFS is an sd-card inside.
Here is the original post from the author, it's quite entertaning, highly recommend to anyone who've read this post until here. I really appreciate your attention.
I've tried this solution and it worked just fantastic. Stable recordings in my NFS folder, every minute, day by day. Huge props to HclX for this solution. I truly think that he made impressive work to reverse engineer this thing and make his script working.
Now the instability issue is fixed, but I still want to have all nice features from Shinobi. I can deal with NFS, so I can either just browse thousands of 1 minute files in Finder or use Wyze app to scroll through the days using narrow scrollbar. Both ways won't make you feel any good, you can believe me.
How to convert MP4 to HLS stream?
I thought that it would be nice if Shinobi could consume these files from NFS in real time as it was a camera, then I would be able to use all the features and enjoy stability.
Apparently, it wasn't that straightforward. Shinobi cannot just consume mp4 files in some random folder, it was made to work with streams (RTSP, RTMP, HLS and etc).
So I made a script for this thing. The idea is super easy:
1. Grab the latest file from NFS folder made by Wyze cam.
2. Use ffmpeg to convert that 1 min mp4 file into HLS stream: m3u8 playlist + ts chunks.
3. Parse that playlist to create a new playlist that will be fed to Shinobi.
Why would I need to create two HLS playlists? Because if we give Shinobi the playlist generated based on that 1 min file, Shinobi will consume it immediately. Basically, it will make duration of a 'tick' 1 minute instead of typical 1 second. It might work for recordings, but it sucks for timelapses and other features, because it's supposed to be a realtime video stream from camera, not some prerecorded files.
So, the script dynamically generates another HLS file which provides 3 chunks of 2 seconds each. And every 2 seconds it will move 1 chunk forward. Basically, it provides a buffer of 6 seconds (just in case). That makes Shinobi think that this is a relatime stream from some camera and pull pls for updates every 2 seconds. Now it works much smoother, all features work fine.
Also, I've added NFS cleanup feature. It will delete all directories older than X days from NFS. We don't need to keep them because we have all the copies in Shinobi. It will be responsible for long term storage and will provide access to it via nice UI.
That's all. I've been using this solution for past month and still pretty happy about it.
I hope it was a useful article for you, wish you smooth connection and zero missed minutes in your video survelliance archive.
Thank you for your attention 🦄