jacksonliam / mjpg-streamer

Fork of http://sourceforge.net/projects/mjpg-streamer/
2.96k stars 1.21k forks source link

Stream-Resolution: 640x480 works, but snapshot has: 4056x3040 (hq-cam/picam3 via libcamera in OctoPrint) #384

Closed Dephrilibrium closed 1 year ago

Dephrilibrium commented 1 year ago

Hi there,

firstly, sorry when I'm wrong, because tbh I'm using the arducam-fork but there issues are deactivated, so I hoped I can find help here.

I adjusted my libcamera-stream (via mjpg-streamer) to an resolution of 640x480, which works as expected, when I open the raw camera-stream-url http://<Pis DNS>:8080/?action=stream. As I tried to use the built-in timelapse (not octolapse!) I noticed that the snapshot resolution is the full camera-sensor resolution (4056x3040) instead of 640x480 (which I had expected). I had checked that by opening the camera-snapshot-url http://<Pis DNS>:8080/?action=snapshot. I'm not exactly sure why, but that causes some problems with missing frames and ffmpeg crashes when it builds the timelapse. I suggest, that the snapshot tries to start/open another camera-stream, because 640x480 uses

[2:56:05.610211948] [12386]  INFO Camera camera.cpp:1028 configuring streams: (0) 680x480-BGR888
[2:56:05.611685437] [12383]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1080-SBGGR12_1X12 - Selected unicam format: 2028x1080-pBCC

So the stream can't provide 4056x3040, due to the sensor is 2x2 binned to the "half" resolution. Here's the mjpg-output with e.g. 4000x3000 which uses the full sensor-resolution without pixel-binning:

[3:15:35.671643821] [13051]  INFO Camera camera.cpp:1028 configuring streams: (0) 4000x3000-BGR888
[3:15:35.672422206] [13048]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC

I also had a look on the configuration of OctoPrint, but there was no configuration-line for snapshot-parameters.

Specs: Hardware: Raspberry Pi 3 OS: Raspbian-OS Lite (based on debian 11 - bullseye) Connection: WLAN Software:

So, I'm not exactly sure, about how to configure the resolution (or even better - just taking a frame from the already running stream) for a snapshot.

Kind regards, Deph

jacksonliam commented 1 year ago

This fork doesn't have a libcamera plugin and I have no idea how the fork's one works. But I believe it uses software jpeg encoding so the frames it is providing could be any size independent of the camera resolution. If it is not obeying you're requested resolution you will have to raise that with them.

The snapshot URL provides the last jpeg frame that would normally be output in a stream, it's impossible for it to be a different resolution to the stream.

I haven't checked, but there might be some memory corruption with their libcamera plugin to the snapshot frame if you're using high framerates with large frame sizes.

Dephrilibrium commented 1 year ago

Hi jacksonliam,

firstly, sorry for the late response.

This fork doesn't have a libcamera plugin and I have no idea how the fork's one works. But I believe it uses software jpeg encoding so the frames it is providing could be any size independent of the camera resolution. If it is not obeying you're requested resolution you will have to raise that with them. you're using high framerates with large frame sizes.

Sure it has. Its sources can be found in: mjpg-streamer/mjpg-streamer-experimental/plugins/input_libcamera When you compile the repository a input_libcamera.so file is created in /home/<username>/mjpg-streamer-libcamera/mjpg-streamer-experimental path which can be used for the HQ-Cam.

But anyway. I hope there will be some updates from arducams site in future. Btw. is it planned that you will add the HQ-Cam also into your project?

Kind regards, Deph


Edit: Just in case, someone ends up in this issue, having the same problem.

I found the problem by using journalctl -f -u webcamd.service. Arducam tries to reconfigure the cameras stream for a snapshot. Sometimes a fatal-crash happens. So this seems to be a fault by arducams calls of the functions or something in libcamera won't work well.

So it looks like, when everythings went fine:

Mar 11 17:56:27 raspi3 webcamd.sh[9925]: Configuring still capture...
Mar 11 17:56:27 raspi3 webcamd.sh[9925]: Stream configuration adjusted
Mar 11 17:56:27 raspi3 webcamd.sh[9925]: Still capture setup complete
Mar 11 17:56:27 raspi3 webcamd.sh[9925]: [3:41:21.255443532] [9930]  INFO Camera camera.cpp:1028 configuring streams: (0) 4056x3040-BGR888
Mar 11 17:56:27 raspi3 webcamd.sh[9925]: [3:41:21.257894408] [9927]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC
Mar 11 17:56:30 raspi3 webcamd.sh[9925]: Configuring still capture...
Mar 11 17:56:30 raspi3 webcamd.sh[9925]: Stream configuration adjusted
Mar 11 17:56:30 raspi3 webcamd.sh[9925]: Still capture setup complete
Mar 11 17:56:30 raspi3 webcamd.sh[9925]: [3:41:23.930338718] [9930]  INFO Camera camera.cpp:1028 configuring streams: (0) 640x480-BGR888
Mar 11 17:56:30 raspi3 webcamd.sh[9925]: [3:41:23.969986627] [9927]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-pBCC

And this happens, when the stream-reconfiguring crashes:

Mar 11 17:56:42 raspi3 webcamd.sh[9925]: Configuring still capture...
Mar 11 17:56:42 raspi3 webcamd.sh[9925]: Stream configuration adjusted
Mar 11 17:56:42 raspi3 webcamd.sh[9925]: Still capture setup complete
Mar 11 17:56:42 raspi3 webcamd.sh[9925]: [3:41:36.264491764] [9930]  INFO Camera camera.cpp:1028 configuring streams: (0) 4056x3040-BGR888
Mar 11 17:56:42 raspi3 webcamd.sh[9925]: [3:41:36.266053268] [9927]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 4056x3040-SBGGR12_1X12 - Selected unicam format: 4056x3040-pBCC
Mar 11 17:56:45 raspi3 webcamd.sh[9925]: Configuring still capture...
Mar 11 17:56:45 raspi3 webcamd.sh[9925]: Stream configuration adjusted
Mar 11 17:56:45 raspi3 webcamd.sh[9925]: Still capture setup complete
Mar 11 17:56:45 raspi3 webcamd.sh[9925]: [3:41:38.963136452] [9930]  INFO Camera camera.cpp:1028 configuring streams: (0) 640x480-BGR888
Mar 11 17:56:45 raspi3 webcamd.sh[9925]: [3:41:38.994746061] [9927]  INFO RPI raspberrypi.cpp:851 Sensor: /base/soc/i2c0mux/i2c@1/imx477@1a - Selected sensor format: 2028x1520-SBGGR12_1X12 - Selected unicam format: 2028x1520-pBCC
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: [3:41:51.273581676] [9927] FATAL default request.cpp:117 assertion "request->status() == RequestPending" failed in complete()
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: Backtrace:
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::Request::Private::complete()+0xa0 (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076cddf04])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::PipelineHandler::completeRequest(libcamera::Request*)+0x30 (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076cd7e18])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::RPiCameraData::clearIncompleteRequests()+0x7c (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076d12f5c])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::PipelineHandlerRPi::stopDevice(libcamera::Camera*)+0x70 (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076d16158])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::PipelineHandler::stop(libcamera::Camera*)+0x38 (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076cd7f90])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::Object::message(libcamera::Message*)+0x74 (/usr/lib/arm-linux-gnueabihf/libcamera-base.so.0.0.4 [0x0000000076c0e7ec])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::Thread::dispatchMessages(libcamera::Message::Type)+0x210 (/usr/lib/arm-linux-gnueabihf/libcamera-base.so.0.0.4 [0x0000000076c10eb0])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::EventDispatcherPoll::processEvents()+0x38 (/usr/lib/arm-linux-gnueabihf/libcamera-base.so.0.0.4 [0x0000000076c0778c])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::Thread::exec()+0xb4 (/usr/lib/arm-linux-gnueabihf/libcamera-base.so.0.0.4 [0x0000000076c10b98])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: libcamera::CameraManager::Private::run()+0xd8 (/usr/lib/arm-linux-gnueabihf/libcamera.so.0.0.4 [0x0000000076caa858])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: ??? [0x0000000076ad3150] (/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.28 [0x0000000076ad3150])
Mar 11 17:56:57 raspi3 webcamd.sh[9925]: start_thread+0xd0 (./nptl/pthread_create.c:478)
Mar 11 17:56:57 raspi3 webcamd.sh[8719]: /home/<username>/Scripts/webcamd.sh: line 116:  9925 Aborted                 LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"  (wd: ~/mjpg-streamer-libcamera/mjpg-streamer-experimental)
Mar 11 17:56:57 raspi3 webcamd.sh[8719]: Scanning again in two minutes