This gist describes the necessary software installation steps for a Raspberry PI in order to enable the PI's camera to act as an external camera for the Dragonfly Java application. This gist shows, how to make a Raspberry PI an RTSP streaming server. The resulting feed can then be used as input for the Dragonfly Java app or the Accuware Dragonfly Demo - Calibration Mode server. The RTSP server on the Raspberry PI must be made publicly available, if calibration is a requirement.
-
Raspberry PI Zero W, 2, 3, 3b, 3b+, 4 with a Raspberry PI-Cam 5 MP or a SainSmart Wide Angle Fish-Eye Cam (recommended).
-
USB cams are not addressed by this gist, even though possible. The configuration of U4VL is slightly different. We don't recommend the use of USB cameras with a Raspberry PI for latency reasons.
-
Ubiquity Robotics Raspberry PI image. This gist refers to the 2019-06-19 image available here. Basically it is an Ubuntu 16.04 Mate derivate.
-
A recent version of the
GStreameron your Mac or Linux PC (1.14 sufficient, 1.16 recommended). Check the GStreamer documentation, how to install it.
Please note: Although technically possible to use any of the a.m. Raspberry PI devices, we recommend to use at least a Raspberry PI 3B+, since it has sufficient computation power and allows you to use 5GHz Wifi, which is mostly not that crowded.
Before first boot and after having flashed the SD card with the image (e.g. using Etcher):
- Enable headless SSH by placing an empty
sshfile into the boot partition/bootof the SD - Enable headless Wifi by placing a
wpa_supplicant.confinto the boot partition to the boot partition/bootof the SD. 5GHz Wifi preferred, if possible.
country=<your-two-letter-code>
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="<your-ssid>"
psk="<your-password>"
key_mgmt=WPA-PSK
}On problems with Wifi: https://www.raspberrypi.org/forums/viewtopic.php?t=191061
- Find the IP of the PI
- SSH to it
After having found out the IP of the IP on your network SSH to the PI:
ssh pi@<ip-of-pi>Initial password is raspberry.
sudo apt-get update
sudo apt-get upgradesudo raspi-config- Change user password. This is from then on your SSH password. Strongly recommended.
- Interfacing options/Enable camera
sudo rebootssh pi@<ip-of-pi>Use your changed password now.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gstreamer1.0-tools
sudo apt-get install gstreamer1.0-plugins-good
sudo apt-get install gstreamer1.0-plugins-bad
sudo apt-get install gstreamer1.0-plugins-ugly
sudo apt-get install gstreamer1.0-libavTest your installation. In order to do this run this command on your Pi:
raspivid -t 0 -w 640 -h 480 -fps 48 -b 2000000 -awb tungsten -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=0.0.0.0 port=5000If you have installed GStreamer via the DMG file installation package, run this command in a terminal on your Mac:
/Library/Frameworks/GStreamer.framework/Commands/gst-launch-1.0 -v tcpclientsrc host=<your_Pi's_IP> port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! osxvideosink sync=falseRun this command in a terminal on your Linux PC. The same command works on your Mac, if you have installed GStreamer via brew:
gst-launch-1.0 -v tcpclientsrc host=<your_Pi's_IP> port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=falseYou should see a video. This is already H.264, but not RTSP.
So we are going to enable this now. Terminate the raspivid server on your PI by typing CTRL-C.
sudo apt-get install libglib2.0-dev
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-devDownload gst-rtsp-server from https://gstreamer.freedesktop.org/src/. Should match the installed gstreamer version. This can be checked by
dpkg -l | grep gstreamerAt the time of writing this is 1.14.4 for Buster lite. Please edit the commands below for other versions (i.e. replace all occurrences of 1.14.4 with the code of the version you are using).
wget https://gstreamer.freedesktop.org/src/gst-rtsp-server/gst-rtsp-server-1.14.4.tar.xz
tar -xf gst-rtsp-server-1.14.4.tar.xz
cd gst-rtsp-server-1.14.4
./configure
make
sudo make installTest your setup:
cd examples
./test-launch --gst-debug=3 '( videotestsrc ! x264enc ! rtph264pay name=pay0 pt=96 )'If you have installed GStreamer via the DMG file installation package, run this command in a terminal on your Mac:
/Library/Frameworks/GStreamer.framework/Commands/gst-launch-1.0 -v rtspsrc location=rtsp://<your_Pi's_IP:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! osxvideosink sync=falseRun this command in a terminal on your Linux PC. The same command works on your Mac, if you have installed GStreamer via brew:
gst-launch-1.0 -v rtspsrc location=rtsp://<your_Pi's_IP>:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! autovideosink sync=falseYou should see a test video.
Terminate the RTSP server on the PI with CTRL-C.
Now we want to see the camera. For this we use the nice raspivid wrapper gst-rpicamsrc.
cd ~
sudo apt-get install git
git clone https://github.com/thaytan/gst-rpicamsrc.gitProceed with
cd gst-rpicamsrc
./autogen.sh
make
sudo make installAs the time of this writing the Raspbian build procedure does not work on Ubiquity. While compilation and linking is going fine, there is a runtime issue:
mmal: mmal_component_create_core: could not find component 'vc.ril.camera'
The problem has been discussed and resolved here.
The workaround is to use meson and ninja in order to build the camera driver. Since the default version of meson is not sufficient for the build, you need to install meson via the Python3 installer in order to get a more recent meson version.
Proceed with:
cd gst-rpicamsrc
pip3 install --user meson
mkdir build
~/.local/bin/meson --prefix=/usr build
ninja -C build -v
cd build
sudo ninja installCheck, if gst-rpicamsrc is installed
gst-inspect-1.0 | grep rpicamsrcNow for the final test:
cd ../gst-rtsp-server-1.14.4/examples
./test-launch --gst-debug=3 "( rpicamsrc bitrate=8000000 awb-mode=tungsten preview=false ! video/x-h264, width=640, height=480, framerate=30/1 ! h264parse ! rtph264pay name=pay0 pt=96 )"If it runs, remove --gst-debug=3 and let it run as a deamon by appending & to the command line above.
If you have installed GStreamer via the DMG file installation package, run this command in a terminal on your Mac:
/Library/Frameworks/GStreamer.framework/Commands/gst-launch-1.0 -v rtspsrc location=rtsp://<your_Pi's_IP>:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! osxvideosink sync=falseRun this command in a terminal on your Linux PC. The same command works on your Mac, if you have installed GStreamer via brew:
gst-launch-1.0 -v rtspsrc location=rtsp://<your_Pi's_IP>:8554/test latency=0 buffer-mode=auto ! decodebin ! videoconvert ! autovideosink sync=falseFor more insight into gst-rpicamsrc and possible other parameters as already used above:
Hi, first of all thank you so much for this tutorial! The outcome is simply awesome.
Just wanted to give my feedback as for my install in Mars 2025.
Hardware used:
Base install:
After the first boot, I configured a fixed IP locally in the Raspberry Pi:
Check the interface IDs:
ls /sys/class/netEdit my network interface configuration:
sudo nano /etc/network/interfacesMy configuration looks like this:
I saved the file with Ctrl+O and exited with Ctrl+X, and I rebooted the system with
sudo reboot.Aftert reboot, I logged via SSH and worked on my regular computer with
ssh [email protected]and updated the system:... and enabled the camera in
raspi-config, followed by another reboot.Once inside the Pi again, I started working on your guide, but had to make a few adjustments due to errors in my outcome. So this is what I did in order to achieve success.
After it is tested successfully, I continued to the RTSP part. First, to install all the libraries I needed for the whole process:
Then to get the code and compile the gstreamer:
After getting the test video with success, it was time to install gst-rpicamsrc:
Then, I checked successfully if it was installed:
gst-inspect-1.0 | grep rpicamsrcAnd did the final test with:
And also executed it as a Daemon (background process) with:
~/gst-rtsp-server-1.18.4/build/examples/test-launch "( rpicamsrc bitrate=8000000 awb-mode=tungsten preview=false ! video/x-h264, width=1280, height=720, framerate=30/1 ! h264parse ! rtph264pay name=pay0 pt=96 )" &And now I wanted it to start streaming automatically on every boot. I created a service file with:
sudo nano /etc/systemd/system/rtsp-stream.serviceAnd made it like this:
After saving the file, I reloaded systemd to recognize the new service:
sudo systemctl daemon-reloadAnd enabled the service to start automatically at boot:
sudo systemctl enable rtsp-stream.serviceAnd rebooted the system to test it all out... with success! Now, every time my Raspberry Pi Zero W is running, I can get its feed on the following address:
rtsp://192.168.1.7:8554/testSo, thank you so much for your guide, and as for the rest of the stuff I had to do to make it run for me, I used Google Gemini and did some digging on my part. With all of this information, I hope we can help anyone who wants to do this simple but very cool project! Kudos to you all!