Piipcam – 1080P IP Camera on a Raspberry Pi Zero W
github.com
github.com
I've been trying to get this working lately and nothing works "well". Motion is popular, but is limited to mjpeg rather than h.264. uv4l is closed source and not up to date with current OS versions. None of the various cvlc incantations to do better actually seem to work on my pi zero w, etc.
https://hochgatterer.me/hkcam/
I agree on the comment for rtsp though. Most solutions have multiple seconds of latency which is a bit suboptional.
gst-launch-1.0 rtpbin name=rtpbin rpicamsrc preview=0 bitrate=4000000 do-timestamp=1 ! 'video/x-h264, width=1920, height=1080, framerate=30/1,profile=high' ! h264parse ! rtph264pay config-interval=1 pt=96 ! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 ! udpsink host=YOUR_IP port=YOUR_PORT rtpbin.send_rtcp_src_0 sync=false async=false
Gstreamer should include rpicamsrc directly nowadays for your convenience.But I couldn't figure out how to stream RTSP, especially not in a way that would preserve NTP timestamp information when restreaming (for synchronization with other streams). There is gst-rtsp-server, but as far as I can tell the idea is that you use it as a library to build your own custom server code.
Is there a simple way I was missing?
Like I have this 10 line bash script, that I want it to run for a few years, with no maintenance, that don’t get corrupted from power loss, or lock up from memory leaks, that auto restarts when necessary, but not bring down network either.
And it requires 10+ years of experience in managing and developing on GNU/Linux, a few notable certificates maybe, a bit of embedded background being a plus, to do it right enough, in about 0.25-1.0 man-month.
I’ve tried something like that on Alpine Linux, and it didn’t work always. Mostly due to proficiency issues on me, but it definitely was unnecessarily hard.
The only thing I don't know how to deal with is a memory leak but as long as it's an easy simple script and no Java app, there should not be anything running that could leak memory.
[Unit]
Description=auto start script
After=multi-user.target
[Service]
Type=simple
ExecStart=/home/pi/script.sh
User=pi
WorkingDirectory=/home/pi
Restart=on-failure
[Install]
WantedBy=multi-user.targetBoth rpos and piipcam serve h.264 RTSP streams that you can pull into OBS and turn into a virtual webcam.
raspivid -l -o tcp://0.0.0.0:3333 --mode 2 -b 3000000 -t 0 --drc off --flush
looped in a screen session on the rpi (running raspbian), and mpv --profile=low-latency tcp://192.168.1.100:3333/
on the client whenever I wanted to see the camera. It wasn't polished, but it got the job done. It died probably due to SD card flakiness, and then I had to move the camera anyway. Next incarnation will be nfsroot.In fact I had a hope it can stream h.265 to save bandwidth. I've heard it was supposed to have hardware h.265 encoding.
But it only works with the pi webcam, not with usb cameras
https://github.com/phoboslab/jsmpeg#example-setup-for-stream...
Since you use motion, I suppose you want to have some kind of detection going on.
I was toying with 2 pi0+cam and one pi4 some weeks ago.
Here's my conclusion (I should write a blog post about it):
- use a pi0+camera dedicated to live streaming ; that's the one you want to connect to to see what's going on (fixed IP, RTSP stream)
- use another pi0+camera or add an IR sensor to the first pi0, in the same spot, to detect motion events (either through motion installed on the pi or the IR sensor)
- use a third connected pi4 for continuous recording of the live stream (in chunks of 5 minutes) to HDD/SSD and/or recording of the live feed once a motion is triggered (you can use motion hooks to trigger API on this pi from the pi0)
- you could also simply do motion detection on the pi4 but you are at the mercy of artifacts in the stream and they WILL trigger motion detection ; that's why you want to do motion detection closest to the source
Motion introduces too much latency to use as a two-ine-one "detect and live stream" (MJPEG conversion takes a lot of CPU clock and adds artifacts).
Most motionEyeOS tutorials I read are PoC that makes you install motionEyeOS on every pi and use the motion MJPEG stream instead of an h264 feed from the camera. It also introduces a lot of CPU bottlenecks and unreliable network connectivity.
I found that motion web UI is now enough for live streaming of what motion "sees" but motionEyeOS helps understanding many of motion options. It's especially useful to draw masks. And then you move on to building your own infrastructure with those bricks (http API, live streaming, hl264 streaming, etc.).
Looks very interesting.
When you say "works great with other types of cameras", could you explain? You've tested with other cameras and could you tell us which?
* Logitech C920
* Raspberry Pi Camera
* e-Con AR0521
* ZED2 Depth camera (in V4L2 mode)
In case your camera is not one of the above, APStreamline falls back to requesting an MJPG stream from the camera and then encoding it to H264 that using the x264enc software encoder. The software encoder has good quality but it requires more CPU power.
Is there some process you setup on Github for others if we test with our own cameras and let you know?
I was surprised that gamers haven't implemented this yet as a DIY Elgato project.
http://robot247.io/robot/pibot
I think overall these devices are amazing for lifting video from one place to another.
One day though, i will work on getting h.264 working.
[1] https://raspberrypi.stackexchange.com/questions/23182/how-to...
I implemented a similar solution (with http-based streaming), but using Motion with an old USB camera. I assumed this solution would also use an USB camera.
I still prefer the Motion solution. Streaming through http opens a lot more possibilities.
What we need is some alternative firmware just like OpenWRT, but aimed at IP cameras. That would be a real challenge, therefore it is probably better to build the IP camera from ground up with security and trust in mind. The PineCube from Pine64 seems a really good step in this direction. Just like their PinePhone, being so hard to liberate an existing phone, it's actually easier to design and produce from scratch one that is really free and open and therefore trustworthy.
Some interesting options also from Friendlyarm to make small Linux driven embedded boards with cameras. https://www.friendlyarm.com/index.php?route=product/product&...
RPI-based camera is great to learn stuff, but to make a product-like devices, there are too many to choose on the market already, cheap and easy and most likely more robust.
Isn't ip-camera a solved problem?
Not if you care about:
- image quality, most of these 10$ camera modules have "sensors" that only work halfway decent with good lighting and are little more than static noise at night
- general build quality, expect issues with the power supply or at temperature extremes
- security, there's no OpenWRT or equivalent for these, so even if you make your own firmware you're still responsible to keep it up to date yourself
- no "advanced" features such as a back-up battery, durable (!) on board storage and a wireless fallback in case there is an attacker who simply cuts the cables
However a word of warning:
Wifi streaming video can really degrade your wifi for other devices. especially if the streaming device is at the edge of the range of the wifi.
Ethernet streaming is really the way forward.
I've done a TON of work in this for reasons and can tell you that streaming over 2.4Ghz especially is an anti-pattern unless you're dealing with super low-quality streams and/or only dealing with 1-2 devices. Even 5Ghz can get froggy with traffic contention. Working against a 15fps 1080p stream on 5Ghz is actually how I test streams with poor health and unpredictable behavior. Throw streaming over TCP into the mix and oof.
Also throwing another network component into the mix may not work for most folks.
---
PS: Before someone yells at me for saying "TCP streaming" because "clearly UDP is the right tool for the job!": nope. TCP is the use-case.
You can, and it solves one of the problems: other clients wanting to use your bandwidth. With careful setup, and a low noise floor (ie not an apartment block) you could do this.
However you have to remember that you can only really run as fast as your slowest wifi camera[1]. That means that in practical terms, you need to make sure that all your cameras are syncing at the highest practical speed (this means not using the on board antenna in most cases)
[1] its more complex than this, but my understanding is that slower devices eat up the available transmit/receive time. which means that everything else is slowed down.
https://github.com/BreeeZe/rpos
Either way, OBS supports RTSP so you can pull feeds in and surface them as a virtual webcam to the rest of your OS.
Motion[1] has a lot less resolution and it's video is not good. But, at least, I can access the video stream through http. That makes an huge difference when implementing a solution. For non-tech users you can just stick the camera's streaming webpage to a phone home screen and give instant access to the video stream.
Then the camera could be placed anywhere as long as it can get power, and your computer could connect to both the camera and the internet.
But, I don't understand why the project would really benefit from the Pi Zero hosting a wifi hotspot... it seems like it would be better for it to just join an existing wifi network.
Preferably that web tool should do it for you.
Either way, a lot of consumer products have that one step.
Accessing the cameras then is no different than accessing anything behind NAT on a home network. The AP can have holes punched for port forwarding to the cameras, some kind of dyndns solution could be used to give them a persistent name if the AP's public network address is dynamic. There are other solutions in this space as well...
My preference however is to not punch any holes and not bother with supporting external connections at this layer. Instead I have the cameras establish and maintain ssh connections w/reverse tunnels on an external server having a static IP on the internet. Those reverse tunnels only listen on localhost ports at the server, requiring a locally executed process to reach the camera tunnels. In the case of my server's configuration, that basically requires logging into the server via ssh to reach the camera tunnels. For an authorized user with ssh access to the server, it's trivial to access the tunnels with a web browser by establishing a SOCKS proxy via ssh and configuring a web browser to use it.
I've ~reproduced this setup for some friends/family members, using extremely cheap VPS instances strictly for terminating the ssh tunnels and providing a self-signed cert https proxy w/basic auth to reach the camera tunnels more conveniently using a smartphone's browser. It seems to work fine for them once they get the self-signed cert permanently accepted in their phone's browser, and is more convenient since they're not IT people and won't be running an ssh client anytime soon. The main problem that's come up is reconfiguring their cameras wifi when they upgrade their home network. They forget about the cameras wifi dependency, and by the time they discover the problem it's too late and we're talking usb2serial GPIO console to reconfigure wpa_supplicant time.
I've got a setup I built based on this: https://befinitiv.wordpress.com/wifibroadcast-analog-like-tr... that's well below 100ms if latency. It's still not as good as analog video for fast drones though.
These days most drone people just blow money on the new-ish DJI digital video stuff (which works on non-DJI drones). It's pretty spectacular, but it's over a grand (in AUD) worth of gear so for now I'm sticking with my old analog video gear.
I'm working on an open-source NVR: https://github.com/scottlamb/moonfire-nvr that is secure, will run on a Raspberry Pi 4, and has a good recording schema. I wouldn't describe the UI as nice yet, but I'd welcome help in making it so!
There are some other open source NVRs (I see someone mentioned Shinobi). Probably a couple reasonably-priced commercial software options (people like Blue Iris, but it's Windows-only). Some commercial NAS devices have NVR support (eg Synology). Dedicated NVRs from manufacturers like Dahua/Hikvision (but my experience is they're awful). YMMV.
You’d have then to compile the source.