A replacement high-level driver for the Raspberry Pi RaspiMJPEG C++, integrated with the RPi_Cam_Web_Interface.
This program is designed to develop a libcamera-based, multi-stream camera system. It supports the latest Raspberry Pi models and offers features such as:
- Preview streams: A real-time view of the camera feed.
- Full-resolution video recording: Capture high-quality video.
- Still image capture: Take high-resolution photos.
- Motion detection: Automatically trigger events when motion is detected.
A key aspect of this system is its integration with the RPi_Cam_Web_Interface, providing a graphical interface(GUI) for managing all camera operations instead of command line interface(CLI).
See 8. FIFO for more details.
| Command | Description |
|---|---|
im |
Capture still image |
ca |
Start/stop video recording |
pv |
Setup preview |
ro |
Set rotation |
fl |
Set flipping |
sc |
Set counts |
md |
Setup motion detection |
wb |
Adjust white balance |
mm |
Set metering mode for exposure |
ec |
Adjust exposure compensation |
ag |
Set analogue gain |
is |
Set ISO |
px |
Set video resolution |
co |
Adjust image contrast |
br |
Adjust image brightness |
sa |
Adjust image saturation |
qu |
Set image quality |
bi |
Set video bitrate |
sh |
Adjust image sharpness |
git clone git@github.com:consiliumsolutions/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
bin/install-rpicam-mjpeg.sh./install.sh./start.shVisit our program at: http://localhost/html/ and start using it!
Now, you can directly skip to 3. Running rpicam-mjpeg on RPi_Cam_Web_Interface.
Follow the following steps to manually set up and install the rpicam-apps system on your Raspberry Pi.
- Build and install the raspberrypi/libcamera library; see documentation here.
- NOTE: Do not use the
libcamerapackages from the official repositories, these are outdated.
- NOTE: Do not use the
- First fetch the necessary dependencies for rpicam-apps.
sudo apt install -y cmake libboost-program-options-dev libdrm-dev libexif-dev libavdevice-dev
sudo apt install -y meson ninja-build- Configure the rpicam-apps build For desktop-based operating systems like Raspberry Pi OS:
meson setup build -Denable_libav=enabled -Denable_drm=enabled -Denable_egl=enabled -Denable_qt=enabled -Denable_opencv=disabled -Denable_tflite=disabledNOTE:
meson setuponly needs to be run once.
- Build rpicam-apps with the following command:
meson compile -C buildFinal Step (Optional)
To install the rpicam-apps binaries system-wide, run:
sudo meson install -C buildThis allows you to use the binaries from anywhere in the terminal without needing to navigate to the build directory each time.
The official instructions to build rpicam-apps; see documentation here.
This section focuses on setting up the web interface for managing the camera system.
GPAC is not available in the Bookworm repos (see issue #689). Follow these instructions to build GPAC from source:
-
Clone the GPAC repository:
git clone https://github.com/gpac/gpac.git
-
Install the necessary dependencies:
sudo apt install build-essential pkg-config g++ git cmake yasm sudo apt install zlib1g-dev libfreetype6-dev libjpeg-dev libpng-dev libmad0-dev libfaad-dev libogg-dev \ libvorbis-dev libtheora-dev liba52-0.7.4-dev libavcodec-dev libavformat-dev libavutil-dev \ libswscale-dev libavdevice-dev libnghttp2-dev libopenjp2-7-dev libcaca-dev libxv-dev \ x11proto-video-dev libgl1-mesa-dev libglu1-mesa-dev x11proto-gl-dev libxvidcore-dev \ libssl-dev libjack-jackd2-dev libasound2-dev libpulse-dev libsdl2-dev dvb-apps mesa-utils \ libcurl4-openssl-dev -
Build GPAC:
cd gpac ./configure make -
Install GPAC system-wide:
sudo make install
After building and installing GPAC, proceed with the RPi_Cam_Web_Interface installation:
-
Clone the RPi_Cam_Web_Interface repository:
git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git cd RPi_Cam_Web_Interface -
Set rpicam-mjpeg as the raspimjpeg driver:
mv bin/raspimjpeg bin/raspimjpeg.bak ln -s `which rpicam-mjpeg` bin/raspimjpeg -
Modify the
install.shscript to exclude GPAC installation:sed -i 's/gpac//p' install.sh -
Run the installation script:
./install.sh
-
During installation, use the following options:
- Start automatically: No
- Port: 80
If you don’t have the following, create them:
mkfifo /var/www/html/FIFO # This should have been created by the installer, however, check if it exists.
mkdir /dev/shm/mjpeg # This is where the preview stream will be written; it may be deleted across reboots.
sudo chmod -R 777 /dev/shm/mjpeg # Typically this directory would be owned by www-data, if you are not that user give yourself access ;)
mkfifo /var/www/html/FIFO1 # Scheduler/motion detection FIFO- This acts the scheduler's FIFO file we will be writing into.
catto see the updates in the file
Visit http://localhost/html/ on your Raspberry Pi to access the RPi_Cam_Web_Interface.
Info
However, since the browser on the Raspberry Pi might be laggy, it's recommended to access the interface from another device on the same network.
Simply open a browser and navigate tohttp://<Raspberry_Pi_IP>/html/(replace<Raspberry_Pi_IP>with your Raspberry Pi's local IP address).
The web interface should already be running, but if it is not, you can start the Apache web server using the following command:
sudo systemctl start apache2When you open the interface for the first time (by visiting http://<Raspberry_Pi_IP>/html/), it may appear broken. This is expected as we need to start the driver (rpicam-mjpeg) first.
Now, you can start running rpicam-mjpeg by running the start.sh script in the RPi_Cam_Web_Interface repository. This will use the global configuration file (/etc/raspimjpeg), which should have been adjusted based on your choices at installation.
NOTE: If start.sh does not work due to a raspimjpeg: command not found error, you have not installed rpicam-mjpeg correctly.
Alternatively, you can run the binary directly (and specificy locations with CLI arguments)
./build/apps/rpicam-mjpeg --preview_path /dev/shm/mjpeg/cam.jpg --media-path /var/www/html/media --video_path 'vi_%v.mp4' --image_path 'i_%i.jpg' --control_file /var/www/html/FIFO --motion_pipe /var/www/html/FIFO1At this point, your web interface should successfully display the preview. This means that you have successfully configured the RPi_Cam_Web_Interface and integrated it with rpicam-mjpeg.
To quit the FIFO environment and stop rpicam-mjpeg, use Ctrl + C in the terminal where it is running.
If you need to clean the build and start fresh, follow these steps:
rm -rf ./buildmeson setup build
meson compile -C buildsudo meson install -C buildNote: The installation step is only required if you need to install the binaries system-wide. For local testing, you can simply run the binaries directly from the
builddirectory.
This will ensure the previous build is removed, a fresh build is created, and the updated binaries are installed.
This project implements comprehensive automated testing for the rpicam_mjpeg program using Python scripts. The testing suite ensures that each FIFO command functions as expected and that any changes to the codebase do not introduce regressions. The tests include both functional command execution and detailed verification of their effects using image analysis.
- Automated Tests: Each FIFO command (
im,ca,pv,ro,fl,sc,md,wb,mm,ec,ag,is,px,co,br,sa,qu,bi,sh) is tested individually to verify its functionality.
-
Install Dependencies:
sudo apt install python3 python3-pillow
-
Ensure FIFO Directory Exists
Ensure FIFO Directory Exists: The FIFO is located at /var/www/html/FIFO. Ensure this directory exists and has the appropriate permissions.
sudo mkdir -p /var/www/html sudo mkfifo /var/www/html/FIFO sudo chmod 777 /var/www/html/FIFO
python3 testing/main.pyThe testing result would be stored in testing_report.txt in the main directory, it would also be printed out.
You don’t need FIFO commands to interact with the camera system, but if you want to use it for advanced control, here are the steps:
To quit the FIFO environment and stop rpicam-mjpeg, use Ctrl + C in the terminal where it is running.
On terminal a:
./build/apps/rpicam-mjpeg --still-output /tmp/cam.jpg --fifo /tmp/FIFOOn terminal b:
echo 'im' > /tmp/FIFORun this command to take a still picture
On terminal a:
./build/apps/rpicam-mjpeg --video-output /tmp/vid.mp4 --fifo /tmp/FIFO --nopreviewOn terminal b:
echo 'ca 1 10' > /tmp/FIFOTo record video for 10 seconds; Or
echo 'ca 0' > /tmp/FIFOTo stop recording. (TBD)
On terminal a:
./build/apps/rpicam-mjpeg --preview-output /tmp/cam.jpg --fifo /tmp/FIFO --nopreviewOn terminal b:
echo 'pv 1000 500' > /tmp/FIFOTo set the size of preview window as 1000 x 500.
On terminal a:
./build/apps/rpicam-mjpeg --motion-output /tmp/schedulerFIFO --fifo /tmp/FIFOOn terminal b:
echo 'md 1' > /tmp/FIFOTo start motion detection.
1: starts the motion detection
NOTE:
catto see the updates
echo 'md 0' > /tmp/FIFOTo stop motion detection.
0: stops the motion detection
On terminal a:
./build/apps/rpicam-mjpeg --video-output /tmp/vid.mp4 --fifo /tmp/FIFO
echo 'ca 1 30' > /tmp/FIFO
echo 'mm centre' > /tmp/FIFOTo change metering option during video recording;
On terminal a:
./build/apps/rpicam-mjpeg --video-output /tmp/vid.mp4 --fifo /tmp/FIFOOn terminal b:
echo 'ca 1 30' > /tmp/FIFO
echo 'ec 5' > /tmp/FIFOTo change exposure during video recording, restricted between -10 to 10;
On terminal a:
./build/apps/rpicam-mjpeg --video-output /tmp/vid.mp4 --fifo /tmp/FIFOOn terminal b:
echo 'ca 1 30' > /tmp/FIFO
echo 'ag 100 100' > /tmp/FIFOTo change red and blue gain during video recording;
On terminal a:
./build/apps/rpicam-mjpeg --video-output /tmp/vid.mp4 --fifo /tmp/FIFOOn terminal b:
echo 'ca 1 30' > /tmp/FIFO
echo 'is 1000' > /tmp/FIFOTo change iso during video recording;
The source code is made available under the simplified BSD 2-Clause license.