I have put together some instructions for setting up a Raspberry Pi h264 video streaming device that uses uv4l and v4l2rtspserver, along with an embedded timestamp.
I've set up a few of these now using my instructions below and had it running for a couple of months, so it appears to be fairly robust.
If you have some Pi's and ribbon cable connected cameras knocking around (I like using 3rd party 160 degree cameras), then these will produce a reasonable quality low latency h264 stream (that uses H/W decoding on my MacBook Pro 2013) at 1.3MP (1296x976).
It's much better than MotionEye because of the high frame rate and low latency this solution gives you.
You can stream over wifi with sufficient bandwidth and signal quality, but I'd recommend wired ethernet if possible. I even have a Raspberry Pi connected with a PoE HAT streaming to my SecuritySpy server.
Works with the latest Lite Buster Raspberry Pi OS image. Use a fresh image/install to ensure compatibility.
#Enable the raspberry pi camera within Interfacing Options > sudo raspi-config
#Run the following commands > curl http://www.linux-projects.org/listing/uv4l_repo/lpkey.asc | sudo apt-key add - > sudo nano /etc/apt/sources.list #Insert the following line in the sources.list file deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/stretch stretch main
> sudo apt update > sudo apt install cmake liblog4cpp5-dev libv4l-dev git vim uv4l uv4l-server uv4l-raspicam uv4l-raspicam-extras > sudo nano /etc/uv4l/uv4l-raspicam.conf #find the following lines in uv4l-raspicam.conf and alter them as follows encoding = h264 width = 1296 height = 972 framerate = 10 # Can be higher, but set to 10 as per Ben's recommendations. text-overlay = yes text-filename = /usr/share/uv4l/raspicam/textnew.json #optional rotation = 180
> sudo nano /etc/systemd/system/uv4l_raspicam.service #Replace the existing ExecStart line with the following: ExecStart=/usr/bin/uv4l -f -k --sched-fifo --mem-lock --config-file=/etc/uv4l/uv4l-raspicam.conf --driver raspicam --driver-config-file=/etc/uv4l/uv4l-raspicam.conf --enable-server off
#Set up the timestamp overlay > sudo nano /usr/share/uv4l/raspicam/uv4l-time-overlay.cpp #Given that this forum can't format code properly, copy text from the following pastebin link and paste it into the uv4l-time-overlay.cpp file created above.
https://pastebin.com/raw/u9erCFei
> cd /usr/share/uv4l/raspicam/ > sudo g++ -o uv4l-time-overlay uv4l-time-overlay.cpp -std=c++11 > sudo nano /etc/systemd/system/uv4l_raspicam_text.service #Copy the text below into this file [Unit] Description=UV4L Raspicam Text After=uv4l_raspicam.service
> cd > git clone https://github.com/mpromonet/v4l2rtspserver.git > cd v4l2rtspserver/ > cmake . > make > sudo make install > sudo reboot #The following line should run ok and not give you any "mmap: No such device" errors. If you do see those errors, check you've enabled the camera in rasps-config and check the ribbon cable is properly connected. Press ctrl+c to exit the command once tested. > v4l2rtspserver -U user:password -F10 -W 1296 -H 972 -P 8555 /dev/video1
> sudo systemctl daemon-reload > sudo systemctl enable uv4l_raspicam > sudo systemctl enable uv4l_raspicam_text > nano ~/.bashrc #At the very end of this file, copy and paste the following. Remember to change the user name and password. if ! pidof -x "v4l2rtspserver" >/dev/null; then v4l2rtspserver -U user:password -F10 -W 1296 -H 972 -P 8555 /dev/video1 fi
#Enable console auto login > sudo raspi-config Choose option 3: Boot Options Choose option B1: Desktop / CLI Choose option B2: Console Autologin Select Finish, and reboot the pi.
Now, on SecuritySpy, use the following device settings:
Address: RTSP port: 8555 Username: user Password: password Profile: Manual configuration Format: RTSP (video and audio) Request: unicast
This is great, many thanks for sharing! This certainly seems like one of the better solutions for turning a Raspberry Pi into an IP camera, I'm sure this will be useful for others.