by lostapathy · 6y ago · 0 comments
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.
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?
https://hochgatterer.me/hkcam/
I agree on the comment for rtsp though. Most solutions have multiple seconds of latency which is a bit suboptional.
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.).
Both 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. 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?
I was surprised that gamers haven't implemented this yet as a DIY Elgato project.
But it only works with the pi webcam, not with usb cameras
https://github.com/phoboslab/jsmpeg#example-setup-for-stream...
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.
[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.targetThe 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.
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.