signag / raspi-cam-srv

Web Server for Raspi Camera Access
MIT License
36 stars 4 forks source link

Using raspiCamSrv with OctoPrint #5

Open jesternberg opened 4 months ago

jesternberg commented 4 months ago

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):

signag commented 4 months ago

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.

Probably, for now you would need duplicate installations of raspi-cam-srv. A better solution would be, of course, to allow for an additional streaming endpoint for the second camera.

I could think of a page in raspiCamSrv showing live streams of both cameras simultaneously. Then, you could use both endpoints for streaming.

I am currently refactoring in order to support an uninterrupted live stream while taking pictures or videos.
This would also be a precondition for a snapshot endpoint. This will take a little bit. Therefore, I do not currently know when I will get to new features.

signag commented 4 months ago

since snapshots are not currently exported

The best solution would be to provide endpoints for snapshots for both cameras.

I'll put that on the list.

signag commented 4 months ago

The endpoint for photo snapshots for the active camera is now available in V2.1 See Web Cam Settings

Endpoints for the second camera will follow later

signag commented 4 months ago

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.

With version V2.3.0 one server instance supports streaming for both cameras sumultaneously.

bradley1999 commented 3 months ago

Problem viewing live stream if any changes are made on another screen. Live feed stops and can't be viewed unless program is stopped and restarted. On Terminal only message is "WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise." Any ideas why the live feed stops and can't be restarted? Also the service configuration change doesn't work after installation. Change shows user name, but closing an SSH session stops the feed. Using Rpi 4 with latest 64 Bookworm, official Camera module 3. Viewing on Macbook Pro using Firefox. Same problem on Safari and Chrome.

signag commented 3 months ago

On Terminal only message is "WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise."

This is a warning which is not related to the issue that the live stream does not show.

This warning originates from the libcamera library (one of the lowest levels in the stack used by Picamera2).
I also see it on some systems (Pi4, Pi Zero) but not on Pi5.

The warning shows up with instantiation of a camera object, even before the camera is configured or started.

In issue #102 for the libcamera project (https://github.com/raspberrypi/libcamera/issues/102) it is recommended to increase the log level for libcamera to 3

In raspiCamSrv, this level is set to 2 by default (in __init__.py, line 70).
If you do not want to see this warning, you can change the value from 2 to 3.

I prefer to leave it at 2 in order not to miss any warnings which might be relevant.

signag commented 3 months ago

Problem viewing live stream if any changes are made on another screen.

Which changes did you make which caused the live stream to disappear?

Sometimes, a specific camera configuration (Sensor Mode, Stream Size or others) may lead to errors within Picamera2, for example in the decoder. Typically, there should be an exception thrown by the relevant program.

Did you see any error messages in addition to the warning which you have mentioned?

If you run raspiCamSrv as service, you would need to look into the journal.

I am working on a solution to make raspiCamSrv more robust against errors in these backgound processes.

signag commented 3 months ago

Also the service configuration change doesn't work after installation.

Could you please specify what exactly you mean with 'service configuration change'?

Which of the Service Configuration procedures did you follow (with or without Audio Support)?

bradley1999 commented 3 months ago

On the initial bootup, ipaddress:5000, live stream is shown, but only Photo, Raw, Video black control buttons. No Hide or Clr. At top right red stream icon is on. Take photo, nothing happens. Click on Raw or Video, same negative response. No errors thrown on Terminal. When browser refreshed, still no changes.

Stop running with Ctrl-C, then restart causes live stream to appear, with Hide and Clr controls, plus photo below and metadata. Red stream icon is on.

Move to Trigger settings to start motion detection, red movement icon is on, but any movement in front of camera is ignored. Can't take photo or video.

I'm using a 16Gb SSD card, is this too low and would a larger memory make a difference?

When I close a SSH session, the screen is lost with a can't connect message, so Raspicamsvr has closed down. I wanted to keep it running in the background without having to restart each time.

Added a few screenshots

Screenshot 2024-03-20 at 13 45 30 Screenshot 2024-03-20 at 13 46 12 Screenshot 2024-03-20 at 13 53 08
bradley1999 commented 3 months ago

live view config screenshot

Screenshot 2024-03-20 at 14 11 01
signag commented 3 months ago

I wanted to keep it running in the background without having to restart each time.

To keep the Flask server running independently from the SSH session, you need to configure it as service.
The description is under Service Configuration.
Did you have issues with this?

Thanks for the other info.
I could partly reproduce the issue with video taking and with motion detection.
Taking photo and raw photo worked.
However, I have a camera model 1 currently connected to the Pi4. Trying now with a model 3.

bradley1999 commented 3 months ago

For independent running without audio, I followed the info to install as service. A check of this line sudo journalctl -e gave this response, appears to start then stop several times, before starting. I have rebooted. When the SSH session closes, so does Raspicamsrv and laptop browser shows no connection.

Screenshot 2024-03-20 at 15 34 59
signag commented 3 months ago

Please post the entire error description (flask)[3357]: ...

bradley1999 commented 3 months ago

Do you need just this one line expanded, or the full 1000 lines!

signag commented 3 months ago

Just two lines (flask)[xxxx] with the same number xxxx

bradley1999 commented 3 months ago

I wonder if there is a permissions issue. Configuring service without audio shows these lines

nano ~/raspiCamSrv.service and sudo cp ~/raspiCamSrv.service /etc/systemd/system

In the first line it shows open a SSH session, but is this before moving to the repository and virtual environment? I also deleted and added user name jules, but without the <> brackets. Are the brackets required? I'm sure they're not.....

I

signag commented 3 months ago

If you don't mind, would you show the content of the service file:
cat /etc/systemd/system/raspiCamSrv.service

Here is mine (for user 'sn' which should be 'jules' in your case: image

bradley1999 commented 3 months ago

Here's what I get

Screenshot 2024-03-20 at 16 25 01
bradley1999 commented 3 months ago

Comparing mine to yours I can see twice, but no idea why as I added jules in the nano configuration

signag commented 3 months ago

There are two more places where you need to replace <user> with jules

bradley1999 commented 3 months ago

I also couldn't expand the lines you asked for. Can't move right to see the text of the full line. Have repeated the process, but different higher line numbers appear, I'm guessing as it's a different session

bradley1999 commented 3 months ago

Yes I can see the two errors now, but how to change them? Where are the two other locations found? Using a nano session as in your description, only one location is shown as needing changing.

signag commented 3 months ago

Normally, when you have the file open in nano (remember to sudo when editing in /etc/systemd/system), you just

bradley1999 commented 3 months ago

Thanks for the help. Changed user name in the two extra places and I think that's done it! Closed SSH session and checked web browser which shows this

Screenshot 2024-03-20 at 17 01 51
bradley1999 commented 3 months ago

Now sudo journalctl -e gives this (last section as there are a lot of lines)

Screenshot 2024-03-20 at 16 57 44
bradley1999 commented 3 months ago

Is that what is expected....how does it compare with your response to sudo journalctl -e ?

signag commented 3 months ago

You should see this:
image

In your screenshot, I do not see the service start.

Probably, you need to restart it:
sudo systemctl stop raspiCamSrv.service
sudo systemctl start raspiCamSrv.service

bradley1999 commented 3 months ago

Here's what I can see on Terminal startup

Screenshot 2024-03-20 at 19 08 21
bradley1999 commented 3 months ago

The bottom line shows session opened, but it's not a smooth start, it stops and starts over first few seconds of startup, why not just one start?

bradley1999 commented 3 months ago

here's my startup on Terminal

Screenshot 2024-03-20 at 19 35 51
signag commented 3 months ago

The bottom line just refers to your user session and not to the Flask server.
You need to look at the red error messages with [Flask]

They say that there is no file /home/jules/prg/raspi-cam-srv/.venv/bin/flask
This refers to the Flask executable. You may check yourself:
cd ~/prg/raspi-cam-srv/.venv/bin
ls -al

If the output looks like
image
your setup is OK.

If you do not see flask, you did not install Flask within the virtual environment as has been requested in step 9 of the RaspiCamSrv Installation.

You may check where Flask is installed:
Make sure that the virtual environment is deactivated. Then enter
which flask
You will see
image

Now, activate the virtual environment and repeat the which command:
image

If your output is still /usr/bin/flask, then Flask is not installed where it should be.

Then you can repeat step 9 of the RaspiCamSrv Installation and everything should be fine.

signag commented 3 months ago

here's my startup on Terminal Screenshot 2024-03-20 at 19 35 51

This does not tell you that you have started Flask from your virtual environment.
The system will find Flask also at /usr/bin because this is in the Path.

The service script, however, expects that Flask is installed in your virtual environment.

bradley1999 commented 3 months ago

after ls -al get this

Screenshot 2024-03-20 at 19 50 42
bradley1999 commented 3 months ago

seems to be missing 4 lines compared to yours. Followed the installation step by step.

fonttools pyftmerge pyftsubset ttx

are these missing lines responsible for my live view missing probs?

signag commented 3 months ago

No

signag commented 3 months ago

Please show again the content of the service file: cat /etc/systemd/system/raspiCamSrv.service

The error message before also complained about the working directory.

bradley1999 commented 3 months ago

Which flask responds correctly.

I'm still seeing twice, despite changing it and rebooting!

Screenshot 2024-03-20 at 20 07 34
bradley1999 commented 3 months ago

still seeing USER twice

signag commented 3 months ago

Probably, you did not save the file or did not open with sudo:

sudo nano /etc/systemd/system/raspiCamSrv.service

Then make the changes

Then save with "^O" (<Ctrl + O>)
Hit to confirm the file name:
image

Then exit with "^X"

Then check again with
cat /etc/systemd/system/raspiCamSrv.service

signag commented 3 months ago

In the meantime, I have committed some fixes which should cover most of the issues described earlier for Pi4 with Cam3.
The reason was that the encoder failed with higher resolutions.
Now, the resolutions for video are set to lower values for Pi4, similar as for Pi Zero.

To update:
cd ~/prg/raspi-cam-srv
git pull

bradley1999 commented 3 months ago

Ok so redid the changes which had these results

Screenshot 2024-03-20 at 21 23 43 Screenshot 2024-03-20 at 21 24 04
bradley1999 commented 3 months ago

after changes now I see

Screenshot 2024-03-20 at 21 33 49
bradley1999 commented 3 months ago

How do I change port 5000 which is now in use.....not sure why?

signag commented 3 months ago

It seems that the raspiCamSrv service is now active. This will of course use port 5000.

Did you check with
sudo journalctl -e ?

Did you try to connect?

bradley1999 commented 3 months ago

yes, it connects to port 5000 but i'd like it to be another port. Motion was running, but trying to stop it caused an error. The Stop button had no effect. 1000 lines of error code....here is the last part

Screenshot 2024-03-20 at 22 19 39
bradley1999 commented 3 months ago

The updated fixes seem to have changed something...the Hide and Clr buttons below the live window have returned, but onpressing Photo, no pic is taken.

signag commented 3 months ago

The Hide and Ctrl buttons are only visible if a photo has been taken and shown in the lower area. See the user guide.

So, if you see it, you must have taken a photo.

signag commented 3 months ago

If you want to use another port, you just change 5000 to the port you want to use in the service script or when you start the Flask server directly

bradley1999 commented 3 months ago

Tried to change port 5000 which was apparently in use, not sure what else is using it.

Screenshot 2024-03-21 at 10 16 58
bradley1999 commented 3 months ago

So followed instructions, changing it to port 5001 in Flask and url address.

Screenshot 2024-03-21 at 10 18 05

Which gave this on webpage

Screenshot 2024-03-21 at 10 19 47

and a long error readout

Screenshot 2024-03-21 at 10 21 41 Screenshot 2024-03-21 at 10 22 58