Low latency and high FPS camera stream with a Raspberry Pi

I just saw that two very good sources, that both had an article about this topic, have gone offline without an archived version. And because I continued my work on a robot that is controlled by a Raspberry Pi, I had to figure out how to create a low latency and high FPS stream from the Pi’s camera that can be viewed in a web browser again.

Connect the camera

Plug in the ribbon cable into the Pi’s camera slot. The blue side of the cable should face towards the USB and ethernet port and the side with the pins exposed should face towards the HDMI out:

Figure 1: The ribbon cable connected the right way around

After that is done, boot up the pi and enter the configuration program:

sudo raspi-config

In the config dialog select “interfacing options” and then “camera”. Enable the camera:

Figure 2: Enable the camera

After enabling the camera, use the tabulator key to select “<Finish>” and reboot the system.

After the system rebooted, you can check the camera status with:

vcgencmd get_camera

If everything was wired and configured correctly, the output should be:

supported=1 detected=1

And you should be able to save a still image with:

raspistill -o image.jpg

The software

The software is heavily based on the pistreaming library. The python program creates a socket connection and serves as a web server. The website creates a web socket client and connects to the web server. I only changed the configuration of the camera, the JavaScript and HTML files to optimize the software for super-fast streaming.

Download and setup

Before you download the program, make sure to run update:

sudo apt-get update

After that’s finished, install the necessary libraries

sudo apt-get install ffmpeg python3-picamera python3-ws4py

Then download the modified program (or clone the original one from git)

wget https://nerdhutblog.files.wordpress.com/2018/12/camera-stream.zip
unzip ./camera-stream.zip
cd ./camera-stream.zip

Run it!

Start the server by executing:

python3 ./server.py

And then use a web browser and navigate to your Raspberry Pi’s IP address on the Port 8080 (if you use the modified software) or port 8082 (if you use the standard sources from GitHub).

The result should look like this:

Figure 3: The video stream in a web browser

Conclusion

And that’s it! Thanks to the pistreaming library, low-latency, and high FPS streams are super easy to do with the Raspberry Pi. Now go and use this simple application to make your projects even better!


One thought on “Low latency and high FPS camera stream with a Raspberry Pi

Leave your two cents, comment here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.