Giter Club home page Giter Club logo

raspi-cam-srv's Introduction

raspiCamSrv

The Raspberry Pi Camera Server (raspiCamSrv) is a web server which can be deployed on a Raspberry Pi device giving access to installed cameras and allows to control these.

It can be installed on all Raspberry Pi platforms which allow connection of one or multiple cameras and supports the currently existing camera types. Up to now, it was tested on Pi Zero W, Pi Zero 2 W, Pi 4 and Pi 5 running Bullseye as well as Bookworm together with camera modules 1, 2, 3, HQ and GS. On Pi 5, also parallel installation of two different cameras was tested.

raspiCamSrv is built with Flask 3.0 and uses the Picamera2 library.

Due to responsive layout from W3.CSS, all modern browsers on PC, Mac or mobile devices can be used as clients.

Feature Overview V2.7.1

For more details and update procedure, see the User Guide and Release Notes.
For installation procedure, see below.

Live Overview

  • The Live screen shows a live stream of the active camera and allows individually selecting and setting all camera controls supported by Picamera2.
  • The live stream (MJPEG stream) can also be directly accessed through the endpoint http://<server>:<port>/video_feed.
    It can be configured whether or not authentication is required.
  • Web access to photo snapshots is achieved through the URL http://<server>:<port>/photo_feed.
    The setting for necessity of authentication applies also to photo snapshots.
  • For systems with 2 Raspberry Pi cameras (currently Pi 5) both cameras can stream simultaneously.
    The non-active camera stream and photo can be accessed through endpoints http://<server>:<port>/video_feed2 and http://<server>:<port>/photo_feed2, respectively.
  • Triggered capture of videos and photos (see Triggered Capture of Videos and Photos) with motion detection
  • Event viewer with calendar overview
  • Notification on captured events by e-Mail (see Notification)
  • Extended Motion Capturing Algorithms are available, including Frame Differencing, Optical Flow and Background Subtraction
  • The Extended Motion Capturing Algorithms can be run in a testing mode, showing live views of intermediate image processing results which can help for a better understanding of the algorithms and adjustment of their variable parameters.
  • For cameras with focus control (camera 3), it is also possible to graphically draw autofocus windows and trigger the autofocus to measure the LensPosition which is translated into a focal distance (see Focus handling).
  • For zooming, the intended image section can be drawn graphically on the live stream area.
  • Photos, raw photos and videos can be taken, which are shown in the lower part of the Live screen together with their metadata or alternatively with their histogram (see Photo taking).
  • Videos can be recorded along with audio if a microphone (e.g. USB microphone) is connected to the Raspberry Pi (see Recording Audio along with Video)
  • "Intelligent" camera control supporting simultaneous camera access from different tasks as long as the requested configurations are compatible (see raspiCamSrv Tasks and Background Processes).
    This includes a continuous live stream while taking photos, videos or photo series.
  • For raw photos and videos, a jpeg placeholder is shown
  • The photos taken may be added to a display buffer for inspection of photos and metadata and for comparison (see Photo Display)
  • On the Config screen, camera configurations can be specified for four different use cases (Live View, Photo, Raw Photo and Video). These will be applied together with the selected controls when photos or videos will be taken. The Live view configuration will also be immediately applied to the Live stream.
  • When modifying Stream Sizes to non-standard aspect ratios, an option can assure that this is syncronously done for all camera configurations, so that Live Stream, Photos, Raw Photos and Videos have all the same aspect ratio and are not distorted.- The Info screen shows the installed cameras, and, for the active camera, the camera properties as well as the available sensor modes.
  • The Photos screen allows scrolling through all available photos and videos with detail views of selected items.
  • With the Photo Series screen, different kinds of photo series (Exposure Series, Focus Stacks, Timelapse Series) can be configured, executed and monitored during their progress.
  • The Photo Series screen allows also to persist specific Camera Configurations together with Camera Controls in the file system for later reuse.
  • Photo Series can be set to be automatically continued on server start if they had been interrupted by a server stop or system shotdown or reboot.
  • The Settings screen allows a few configuration settings such as selection of the active camera as well as selecting the type of photos, raw photos and videos in the range supported by Picamera2
  • The Settings screen includes also functions to control the raspiCamSrv Server Configuration.
    The entire configuration can be persisted or loaded from stored configuration files.
  • It is also possible to configure the server to use the persisted configuration on server startup.
  • Access to the server requires registration and authentification.
  • Generator for executable Python code including the entire interface to Picamera2 of a raspiCamSrv session.
    (See Generation of Python Code for Camera)

New in V2.7.0

  • This version introduces configurability for access to streaming with or without authentication.

Known Issues

  • In Safari (e.g. on an iPad), there is still an issue with the Live Screen:
    Due to the specific timing of the onload event, AF Windows may not be visible immediately after the page has been loaded. If you just 'pull' the entire window down for a short time (don't touch the AF Windows canvas), they will show up.
    If the Live stream does not show up (e.g. after visiting another screen), take a photo and then push Hide/Show. This will show the live stream.
  • There may be an issue configuring specific sensor modes or stream sizes for the Live View in Config. As a result, the live view will not show up and the server log will show an exception. You may need to reset the server (see Reset Server)
    This is already fixed but may not yet be available in your environment (see picamera2 Issue #959)

Limitations

The software is still being tested and extended.

  • USB cameras are detected but currently not supported. One reason is that many USB cameras use the YUYV format whereas raspiCamSrv uses MJPEG for the Live stream and YUYV would require OpenCV for rendering.
  • raspiCamSrv will not automatically detect a changed camera setup, for example if cameras are plugged in and out while the Raspberry Pi is running (certainly, this would apply only to USB cameras and nobody will unplug a Pi camera without shutting down the system). However, there is a Reset Server button on the Settings screen, which, when pressed, will force the configuration to be updated.
  • Although the layout is responsive, it may not be "good-looking" with all sizes of browser windows

Credits

Setup / Getting Started

Required

  • A Raspberry Pi (Zero W, Zero 2 W, Pi 1, Pi 3, Pi 4, Pi 5)
  • A Raspberry Pi camera
  • A suitable camera cable
    (Pi Zero W, Pi Zero 2 W and Pi 5 have the small CSI-2 camera port, requiring a special cable which is usually not shipped with the camera)
  • A microSD card
  • A suitable power supply
    For Pi Zero W or Pi Zero 2 W, a normal mobile phone charger is sufficient as long as it has a Micro-USB connector
  • Optionally, a case for the specific model may ease handling.
    For Pi Zero W or Zero 2 W, offerings for the official case (e.g. here) should include a special short camera cable.
    The cover for the camera is fine for camera models 1 and 2. For camera model 3, some handwork is necessary to enlarge the hole to a square for the camera body.
  • A Wifi network with internet access and known access credentials (SSID, password)
  • A PC or Mac with network access and (micro)SD card reader

The setup description, below, assumes a completely autonomous or 'headless' setup, where the Raspberry Pi requires nothing but a power supply cable without any necessity to ever connect it to a display, keyboard or mouse.
Pi Zero Cover
Here, the camera model 2 is installed.

The described steps were successfully executed with Raspberry Pi Imager version 1.8.5 and a Raspberry Pi Zero W.

System Setup

For system setup, follow the instructions of the Raspberry Pi Getting Started Documentation for OS installation using Imager.
Make sure that SSH is enabled on the Services tab.

Once the SD card is written, insert it into the Raspberry Pi and power it up.
Initially, it will take several minutes until it is visible in the network.

RaspiCamSrv Installation

If you want to update an existing installation to the latest version, see Update Procedure.

In case of problems during installation and usage, see Troubleshooting

Step Action
1. Connect to the Pi using SSH:
ssh <user>@<host>
with <user> and <host> as specified during setup with Imager.
2. Update the system
sudo apt update
sudo apt full-upgrade
3. Create a root directory under which you will install programs (e.g. 'prg')
mkdir prg
cd prg
4. Check that git is installed (which is usually the case in current Bullseye and Bookworm distributions)
git --version
If git is not installed, install it with
sudo apt install git
5. Clone the raspi-cam-srv repository:
git clone https://github.com/signag/raspi-cam-srv
6. Create a virtual environment ('.venv') on the 'raspi-cam-srv' folder:
cd raspi-cam-srv
python -m venv --system-site-packages .venv
For the reasoning to include system site packages, see the picamera2-manual.pdf, chapter 9.5.
7. Activate the virtual environment
cd ~/prg/raspi-cam-srv
source .venv/bin/activate
The active virtual environment is indicated by (.venv) preceeding the system prompt
8. Make sure that picamera2 is available on the system:
python
>>>import picamera2
>>>quit()
If you get a 'ModuleNotFoundError', see the picamera2 Manual, chapter 2.2, how to install picamera2.
For raspiCamSrv it would be sufficient to install without GUI dependencies:
sudo apt install -y python3-picamera2 --no-install-recommends
9. Install Flask 3.0 with the virtual environment activated.
Raspberry Pi OS distributions come with Flask preinstalled, however with versions 1.1 or 2.2.
RaspiCamSrv requires Flask 3.0, which can be installed with
pip install Flask==3.0.0
If you want to check the Flask version, you may need to deactivate/activate the virtual environment first:
deactivate
source .venv/bin/activate
flask --version
This should reveal version 'Flask 3.0.0'.

Make sure that Flask is really installed in the virtual environment:
which flask should output
/home/<user>/prg/raspi-cam-srv/.venv/bin/flask
10. Optional installations:
The following installations are only required if you need to visualize histograms for some of the Photo Series
or if you are interesten in using Extended Motion Capturing Algorithms.
It is recommended to do the installation with an activated virtual environment (see step 7), although some of these packages might come preinstalled.
Install OpenCV: sudo apt-get install python3-opencv
Install numpy: pip install numpy
Install matplotlib: pip install matplotlib
11. Initialize the database for Flask
(with raspi-cam-srv as active directory and the virual environment activated - see step 7):
flask --app raspiCamSrv init-db
12. Check that the Flask default port 5000 is available
sudo netstat -nlp | grep 5000
If an entry is shown, find another free port (e.g. 5001)
and replace port 5000 by your port in all flask commands, below and also in the URL in step 12.
13. Start the server
(with raspi-cam-srv as active directory and the virual environment activated - see step 7):
flask --app raspiCamSrv run --port 5000 --host=0.0.0.0
14. Connect to the server from a browser:
http://<raspi_host>:5000
This will open the Login screen.
15. Before you can login, you first need to register.
The first user will automatically be SuperUser who can later register other users (User Management)
16. After successful log-in, the Live screen will be shown
17. Done!
18. For usage of raspiCamSrv, please refer to the User Guide

When the Flask server starts up, it will show a warning that this is a development server.
This is, in general, fine for private environments.
How to deploy with a production WSGI server, is described in the Flask documentation

Service Configuration

When the Flask server is started in a SSH session as described in step 10, above, it will terminate with the SSH session.

Instead, you may want the server to start up independently from any user sessions, restart after a failure and automatically start up when the device is powered up.

In order to achieve this, the Flask server start can be configured as service under control of systemd.

The following procedure is for the case where audio recording with video is not required. Otherwise, see next section.

Step Action
1. Open a SSH session on the Raspberry Pi
2. Copy the service template raspiCamSrv.service which is provided with raspiCamSrv to your home directory
cp ~/prg/raspi-cam-srv/config/raspiCamSrv.service ~
3. Adjust the service configuration:
nano ~/raspiCamSrv.service
Replace all (4) occurrences of '<user>' with the user ID, specified during System Setup
If you need a port different from 5000 (see RaspiCamSrv Installation, step 10), replace also port 5000 by your port.
4. Stage the service configuration file to systemd:
sudo cp ~/raspiCamSrv.service /etc/systemd/system
5. Start the service:
sudo systemctl start raspiCamSrv.service
6. Check that the Flask server has started as service:
sudo journalctl -e
7. Enable the service so that it automatically starts with system boot:
sudo systemctl enable raspiCamSrv.service
8. Reboot the system to test automatic server start:
sudo reboot

Service Configuration for Audio Support

If it is intended to record audio along with videos, a slightly different setup is required (see Settings):
Instead of installing the service as a system unit, it needs to be installed as user unit (see systemd/User) in order to get access to PulseAudio.

Bookworm Systems

If your system is a bookworm system (lsb_release -a) follow these steps:

Step Action
1. Open a SSH session on the Raspberry Pi
2. Copy the service template raspiCamSrv.service which is provided with raspiCamSrv to your home directory
cp ~/prg/raspi-cam-srv/config/raspiCamSrv.service ~
3. Adjust the service configuration:
nano ~/raspiCamSrv.service
Replace '<user>' with the user ID, specified during System Setup
If necessary, raplace also the standard port 5000 with your port.
Remove the entry User=<user> from the [System] section
In section [Install], change WantedBy=multi-user.target to WantedBy=default.target
4. Create the directory for systemd user units
mkdir -p ~/.config/systemd/user
5. Stage the service configuration file to systemd for user units:
cp ~/raspiCamSrv.service ~/.config/systemd/user
6. Start the service:
systemctl --user start raspiCamSrv.service
7. Check that the Flask server has started as service:
journalctl --user -e
8. Enable the service so that it automatically starts with a session for the active user:
systemctl --user enable raspiCamSrv.service
9. Enable lingering in order to start the unit right after boot and keep it running independently from a user session
loginctl enable-linger
10. Reboot the system to test automatic server start:
sudo reboot

Bullseye Systems

If your system is a bullseye system (lsb_release -a), which is currently still the case for Pi Zero, follow these steps:

Step Action
1. Open a SSH session on the Raspberry Pi
2. Clone branch 0_3_12_next of Picamera2 repository
cd ~/prg
git clone -b 0_3_12_next https://github.com/raspberrypi/picamera2
3. Copy the service template raspiCamSrv.service which is provided with raspiCamSrv to your home directory
cp ~/prg/raspi-cam-srv/config/raspiCamSrv.service ~
4. Adjust the service configuration:
nano ~/raspiCamSrv.service
- Replace '<user>' with the user ID, specified during System Setup
- If necessary, raplace also the standard port 5000 with your port.
- Add another Environment entry: Environment="PYTHONPATH=/home/<user>/prg/picamera2"
- Remove the entry User=<user> from the [System] section
- In section [Install], change WantedBy=multi-user.target to WantedBy=default.target
For an example of the final .service file, see below
5. Create the directory for systemd user units
mkdir -p ~/.config/systemd/user
6. Stage the service configuration file to systemd for user units:
cp ~/raspiCamSrv.service ~/.config/systemd/user
7. Start the service:
systemctl --user start raspiCamSrv.service
8. Check that the Flask server has started as service:
journalctl --user -e
9. Enable the service so that it automatically starts with a session for the active user:
systemctl --user enable raspiCamSrv.service
10. Enable lingering in order to start the unit right after boot and keep it running independently from a user session
loginctl enable-linger
11. Reboot the system to test automatic server start:
sudo reboot

Below is an example .service specification for user "sn":

[Unit]
Description=raspiCamSrv
After=network.target

[Service]
ExecStart=/home/sn/prg/raspi-cam-srv/.venv/bin/flask --app raspiCamSrv run --port 5000 --host=0.0.0.0
Environment="PATH=/home/sn/prg/raspi-cam-srv/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Environment="PYTHONPATH=/home/sn/prg/picamera2"
WorkingDirectory=/home/sn/prg/raspi-cam-srv
StandardOutput=inherit
StandardError=inherit
Restart=always

[Install]
WantedBy=default.target

raspi-cam-srv's People

Contributors

signag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

raspi-cam-srv's Issues

Web Cam Photo URL returns invalid picture when saved

I'm trying to intergrate my rpi-cam with HomeAssistant and trying to trigger a picture when my motion sensor detect something (I know I could do something similar only with raspi-cam-srv but I already have some motion sensor so...).

If I use the URL given in the WebCam tab I can see the image in my browser but if I save it (right click -> save as) and open it with my image viewer I get this error :
Format error decoding Jpeg: Invalid JPEG format: first two bytes are not an SOI marker

And I'm getting the same issue when setting the Picture URL into my HA setup.

Taking picture in the Live tab and saving them from the Photos tabs works just fine tho...

Happy to provide any information you need !

Raspberry Pi 5 x64 Bookworm with Camera Module 3 - No cameras detected

When starting up the camsrv, I see error logs in the terminal that says the following:

WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.

  • Running on all addresses (0.0.0.0)
  • Running on http://127.0.0.1:5000
  • Running on http://192.xxx.xx.xx:5000
    Press CTRL+C to quit
    [2024-03-04 21:52:16,600] ERROR in app: Exception on / [GET]
    Traceback (most recent call last):
    File "/workspace/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 867, in full_dispatch_request
    rv = self.dispatch_request()
    ^^^^^^^^^^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 852, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/raspiCamSrv/auth.py", line 273, in wrapped_view
    return view(**kwargs)
    ^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/raspiCamSrv/home.py", line 25, in index
    Camera().startLiveStream()
    ^^^^^^^^
    File "/workspace/raspi-cam-srv/raspiCamSrv/camera_pi.py", line 878, in new
    activeCam = Camera.getActiveCamera()
    ^^^^^^^^^^^^^^^^^^^^^^^^
    File "/workspace/raspi-cam-srv/raspiCamSrv/camera_pi.py", line 1054, in getActiveCamera
    raise SystemError("No cameras were found on the server's device")
    SystemError: No cameras were found on the server's device
    [2024-03-04 21:55:12,597] ERROR in camera_pi: Thread 140735407976832: Camera._thread - Exception.

rpi5-1
rpi5-2
I've attached two pictures of the cable hook up into cam0 slot.

Camera not showing in Live

Brand new install on bookworm. I tested camera with libcamera-hello:

wyohman@raspberrypi:~ $ libcamera-hello
[0:04:34.782090969] [873] INFO Camera camera_manager.cpp:284 libcamera v0.2.0+46-075b54d5
[0:04:34.954627653] [876] WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:04:34.960985705] [876] INFO RPI vc4.cpp:447 Registered camera /base/soc/i2c0mux/i2c@1/imx708@1a to Unicam device /dev/media0 and ISP device /dev/media1
[0:04:34.961190133] [876] INFO RPI pipeline_base.cpp:1144 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Preview window unavailable
Mode selection for 2304:1296:12:P
SRGGB10_CSI2P,1536x864/0 - Score: 3400
SRGGB10_CSI2P,2304x1296/0 - Score: 1000
SRGGB10_CSI2P,4608x2592/0 - Score: 1900
Stream configuration adjusted
[0:04:34.966523388] [873] INFO Camera camera.cpp:1183 configuring streams: (0) 2304x1296-YUV420 (1) 2304x1296-SBGGR10_CSI2P
[0:04:34.967358705] [876] INFO RPI vc4.cpp:611 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected unicam format: 2304x1296-pBAA
#0 (0.00 fps) exp 30141.00 ag 2.00 dg 1.06
#1 (30.01 fps) exp 29981.00 ag 1.97 dg 1.10

As well as libcamera-still -o test.jpg and the jpg looked very nice.

Updated config to start automatically and I was able to create a user and login. When Iogin I can see the right side options Focus, Zoom, etc.. but nothing on the Live side.

If I click Photo, Raw or Video, I see this message at the bottom (message shown for each button).

Error in Camera.takeImage: Phototaking caused error: [Errno 12] Cannot allocate memory
Error in Camera.takeRawImage: Taking raw photo caused error: [Errno 12] Cannot allocate memory
Error in Camera.takeImage: Phototaking caused error: [Errno 12] Cannot allocate memory

Feels like I must missing something but I went over the instructions multiple times.

Info shows what I would expect for my setup (RPI 3b+ and imx708_wide)

Video_Feed image size

Hi,

This might not be a problem, only user error, but I don't know where else to get the information I might need.

I have setup the latest version as of today and I can stream from 2 cameras (PiCam 3) at the same time on my Raspberry Pi 5 4GB. I can change the resolution of one of them. But I cannot see how to change the resolution of the other and I cannot seem to get the settings to save.

Is there documentation I am missing?

Your help is appreciated.

New features request

HI,
thanks to your software I can finally use the Raspi Cam V3 on Raspberry PI 5, I think it's the only application that can stream without problems, at least for the moment.
From my point of view you could implement small but interesting functions, such as:

  • save the webcam configuration so if the service is restarted the settings are preserved
  • disable the user registration tab once the first user registers
  • put an option to make the stream accessible without access (i.e. the url /video_feed), it would be very useful for example for Octoprint which is set up to display the streaming from a specific url

I understand that your software is just beginning and you probably already have a lot of changes in mind but I hope my suggestions will inspire you! (if I knew how to program in Python I would gladly give you a hand but unfortunately it is not one of my known languages)

In the meantime, I'm already reporting your software in the Octoprint forum as I see it as the only solution for those who use that software ;)

Error Connecting To Server: sqlite3.OperationalError: no such table: user

Following the RaspiCamSrv Installation, when I followed step #14 (below) from my browser (http://<My_Host_IP>:5000):

Connect to the server from a browser:
http://<raspi_host>:5000
This will open the [Login](https://github.com/signag/raspi-cam-srv/blob/main/docs/Authentication.md#log-in) screen.

I got the following:

(.venv) <redacted>@<redacted>:~/prg/raspi-cam-srv $ flask --app raspiCamSrv run --port 5000 --host=0.0.0.0
 * Serving Flask app 'raspiCamSrv'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
 * Running on http://<redacted>:5000
Press CTRL+C to quit
[2024-05-07 17:46:02,945] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 865, in full_dispatch_request
    rv = self.preprocess_request()
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 1239, in preprocess_request
    rv = self.ensure_sync(before_func)()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/raspiCamSrv/auth.py", line 235, in load_logged_in_user
    g.nrUsers = get_db().execute("SELECT count(*) FROM user").fetchone()[0]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: user
<redacted IP> - - [07/May/2024 17:46:02] "GET / HTTP/1.1" 500 -
[2024-05-07 17:46:03,068] ERROR in app: Exception on /favicon.ico [GET]
Traceback (most recent call last):
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 1455, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 869, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 865, in full_dispatch_request
    rv = self.preprocess_request()
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/app.py", line 1239, in preprocess_request
    rv = self.ensure_sync(before_func)()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jim/prg/raspi-cam-srv/raspiCamSrv/auth.py", line 235, in load_logged_in_user
    g.nrUsers = get_db().execute("SELECT count(*) FROM user").fetchone()[0]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such table: user
<redacted IP>- - [07/May/2024 17:46:03] "GET /favicon.ico HTTP/1.1" 500 -

Possibly a missing step in the RaspiCamSrv Installation to a initialize the creation of the table? If so, what might that step be and should it be run from the virtual environment activated (I'm a bit new to virtual environments)?

ModuleNotFoundError: No module named 'picamera2'

Using a fresh image of 2023-12-11-raspios-bookworm-arm64-lite.img.xz

Raspberry PI OS Lite 64 Bit Bookworm on a Raspberry PI 5

After connecting through ssh I ran the following commands:

sudo apt update
sudo apt full-upgrade -y
mkdir prg
cd prg
sudo apt install git -y
git clone https://github.com/signag/raspi-cam-srv
cd raspi-cam-srv
python -m venv --system-site-packages .venv
cd ~/prg/raspi-cam-srv
source .venv/bin/activate
pip install Flask==3.0.0

when I entered 'flask --app raspiCamSrv init-db' I received the error below.

(.venv) pi@pitest:~/prg/raspi-cam-srv $ flask --app raspiCamSrv init-db
Traceback (most recent call last):
File "/home/pi/prg/raspi-cam-srv/.venv/bin/flask", line 8, in
sys.exit(main())
^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/cli.py", line 1064, in main
cli.main()
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/click/core.py", line 1682, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/click/core.py", line 1729, in resolve_command
cmd = self.get_command(ctx, cmd_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/cli.py", line 579, in get_command
app = info.load_app()
^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/cli.py", line 309, in load_app
app = locate_app(import_name, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/cli.py", line 236, in locate_app
return find_best_app(module)
^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/.venv/lib/python3.11/site-packages/flask/cli.py", line 64, in find_best_app
app = app_factory()
^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/raspiCamSrv/init.py", line 71, in create_app
from . import home
File "/home/pi/prg/raspi-cam-srv/raspiCamSrv/home.py", line 4, in
from raspiCamSrv.camera_pi import Camera
File "/home/pi/prg/raspi-cam-srv/raspiCamSrv/camera_pi.py", line 9, in
from picamera2 import Picamera2, CameraConfiguration, StreamConfiguration, Controls
ModuleNotFoundError: No module named 'picamera2'

Updating

I thought I did an update but I can't find the instructions. What is the process to just update an existing install?

Few questions (noob)

Discussed in #17

Originally posted by tatterz91 May 26, 2024

  1. It doesn't let my view the Live stream when I press record. It says Video settings are incompatable with Live Stream configuration. Why?

  2. Seems like half the time I press Stop Record, it throws up a Internal Server Error "either the server is overloaded or there is an error in the application." Why?

I'm using the Pi 4 B 8gb
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
11.9
the standard camera module 3
version="V2.6.1"

Using raspiCamSrv with OctoPrint

I am using raspiCamSrv with RPI5 and 2 cameras. Is it correct to have two versions of the service running on different ports to be able to use the multicam plugin? or is there a better solution.

Also since snapshots are not currently exported you cannot configure the snapshot url in OP. I tried the following path, based on video_feed, but it is not quite right. Using mimetype='multipart/x-mixed-replace, I do see the snapshot directly in a browser. OP is expecting the mimetype to be image/jpeg but with that as the mimetype, both OP and browser do not error but image is not displayed. Any suggestions as to what is wrong?

diff --git a/raspiCamSrv/home.py b/raspiCamSrv/home.py
index c0ccb85..f6cc62f 100644
--- a/raspiCamSrv/home.py
+++ b/raspiCamSrv/home.py
@@ -48,6 +48,23 @@ def video_feed():
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')

+def gen2(camera):

  • """Snapshot generator function."""
  • #logger.debug("In gen2")
  • yield b'--frame\r\n'
  • frame = camera.get_frame()
  • #l = len(frame)
  • #logger.debug("Got frame of length %s", l)
  • yield b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n--frame\r\n'

[email protected]("/snapshot")
+# @login_required
+def snapshot():

  • #logger.debug("In snapshot")
  • return Response(gen2(Camera()),
  •                mimetype='image/jpeg; boundary=frame')
    
  •                #mimetype='multipart/x-mixed-replace; boundary=frame')
    

@bp.route("/photos/")
@login_required
def displayImage(photo: str):

Problems when installing on Raspberry PI5 + setting different port than 5000

During the installation, following your steps here https://github.com/signag/raspi-cam-srv?tab=readme-ov-file#raspicamsrv-installation at step 9 the command "flask --app raspiCamSrv init-db" returns me this log:

Traceback (most recent call last):
File "/home/pi/.local/bin/flask", line 8, in
sys.exit(main())
^^^^^^
File "/home/pi/.local/lib/python3.11/site-packages/flask/cli.py", line 1064, in main
cli.main()
File "/usr/lib/python3/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/click/core.py", line 1651, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/click/core.py", line 1698, in resolve_command
cmd = self.get_command(ctx, cmd_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/.local/lib/python3.11/site-packages/flask/cli.py", line 579, in get_command
app = info.load_app()
^^^^^^^^^^^^^^^
File "/home/pi/.local/lib/python3.11/site-packages/flask/cli.py", line 309, in load_app
app = locate_app(import_name, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/.local/lib/python3.11/site-packages/flask/cli.py", line 236, in locate_app
return find_best_app(module)
^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/.local/lib/python3.11/site-packages/flask/cli.py", line 64, in find_best_app
app = app_factory()
^^^^^^^^^^^^^
File "/home/pi/prg/raspi-cam-srv/raspiCamSrv/init.py", line 22, in create_app
Path(app.instance_path + "/raspiCamSrv.log").touch(exist_ok=True)
File "/usr/lib/python3.11/pathlib.py", line 1109, in touch
fd = os.open(self, flags, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/prg/raspi-cam-srv/instance/raspiCamSrv.log'

The command "flask --version" returns this:
Python 3.11.2 Flask 3.0.0 Werkzeug 3.0.1

I also need to change the default listening port from 5000 to any other because the port 5000 is already used form Octoprint.
Thanks in advance!

Feature Request: SocialMedia-Connection

It would be cool if we could set up a live stream on YouTube, Twitch, ....

If the stream is not listed, this will be an easy way to make the video-feed available online.
That should also be safer.

It looks like there are already good bibloths for this ( https://pypi.org/project/pylivestream/ ).
Unfortunately, I don't know much about Python, otherwise I would have created a PR ๐Ÿ˜…

Restarting service doesn't saved reload pan/crop, but 'Load Saved Configuration' does

This is primarily an issue due to the fact that idle streams (watching then leaving the stream) keeps the CPU loaded indefinitely, so I systemctl restart raspiCamSrv on a cron schedule for power/thermal reasons, but anyway:

Restarting the server service resets the pan and crop I have set (lens used is a bit too wide for the given use case), but going to Settings > Load Saved Configuration -- which I assumed would effectively load the same settings as restarting it entirely -- does preserve any pan/crop set on last Store Configuration. Consistency here would be nice, although so too would better cleanup of unused threads when there are no connected clients.

Feature Request: Toggle Live Auth

Id like to have a toggle in the config that controls the X_feed streams authentication from and can switch between off to on so that they cannot be accessed without a user account. I've read that they previously required a login but I can't figure out a way to do this now. Can this be added?

flask app is running on port 5000, but can't browse to <ip_address:5000> and no logs.

I am trying to run raspi-cam-srv on a Pi 5 with 64 bit Bookworm and two Arducam 16 MP Autofocus cameras over CSI connections.
First, a little background information for context:
The Pi 5 is running Klipper/Mainsail/Crowsnest to host a 3D printer environment.
Crowsnest is another camera application that uses camera-streamer on the back end. While Crowsnest is able to detect both Arducams, it has a warning in its own logs that says:
[03/30/24 22:51:30] crowsnest: INFO: Found 2 total available Device(s)
[03/30/24 22:51:30] crowsnest: ================================================================
[03/30/24 22:51:30] crowsnest: WARN: 'libcamera' devices are currently not supported on Pi 5!
[03/30/24 22:51:30] crowsnest: ================================================================
[03/30/24 22:51:30] crowsnest: Detected 'libcamera' device -> /base/axi/pcie@120000/rp1/i2c@88000/imx519@1a
[03/30/24 22:51:30] crowsnest: Detected 'libcamera' device -> /base/axi/pcie@120000/rp1/i2c@80000/imx519@1a

Which led me to go searching for an alternative solution, and I ended up here with raspi-cam-srv.

After going through all of the basic configuration steps, and then also setting up raspi-cam-srv to run as a background service, I am unable to access the web server interface which appears to be running on port 5000, and no logs are generated.

pi@gemeaux:~ $ ps -ef | grep 5000
pi           967       1  0 Mar30 ?        00:00:08 /home/pi/prg/raspi-cam-srv/.venv/bin/python /home/pi/prg/raspi-cam-srv/.venv/bin/flask --app raspiCamSrv run --port 5000 --host=0.0.0.0
pi         29829   29795  0 09:19 pts/1    00:00:00 grep --color=auto 5000
pi@gemeaux:~ $ cd prg
pi@gemeaux:~/prg $ cd raspi-cam-srv/
pi@gemeaux:~/prg/raspi-cam-srv $ ls
config  docs  instance  LICENSE  logs  output  raspiCamSrv  README.md
pi@gemeaux:~/prg/raspi-cam-srv $ cd logs
pi@gemeaux:~/prg/raspi-cam-srv/logs $ ls
raspiCamSrv.log
pi@gemeaux:~/prg/raspi-cam-srv/logs $ source .venv/bin/activate
-bash: .venv/bin/activate: No such file or directory
pi@gemeaux:~/prg/raspi-cam-srv/logs $ cd ..
pi@gemeaux:~/prg/raspi-cam-srv $ source .venv/bin/activate
(.venv) pi@gemeaux:~/prg/raspi-cam-srv $ ls
config  docs  instance  LICENSE  logs  output  raspiCamSrv  README.md
(.venv) pi@gemeaux:~/prg/raspi-cam-srv $ cd logs
(.venv) pi@gemeaux:~/prg/raspi-cam-srv/logs $ ls -al
total 8
drwxr-xr-x  2 pi pi 4096 Mar 28 01:57 .
drwxr-xr-x 11 pi pi 4096 Mar 28 01:57 ..
-rw-r--r--  1 pi pi    0 Mar 31 05:57 raspiCamSrv.log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.