-
Notifications
You must be signed in to change notification settings - Fork 15
ffmpeg hanging on motion capture (sometimes) #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, I have checked the code and I have seen that for Pi 1, 2, 3 the Video configuration was used for videos recorded during motion capturing and not, as for Pi Zero and Pi 4 the Live View configuration. I do not have these models and I cannot test these. I only have Pi Zeros, Pi 4 and Pi 5. With Pi 4, I did not find any issues. So,. probably, in your case with a Pi 3, the issues were seen because the Video Configuration with the higher resolution and memory requirements were used. Probably, you can check the videos to see which resolution they have. I have fixed this in V3.5.1. If you update to this version, you could check if the issue is still there. On the other hand .... On my Pi Zeros and Pi 4, I usually use the "main" stream with low resolution and the RGB888 Stream Format for the Live View configuration, which gives much better quality. |
Thanks for the response! I didn't think that the warnings in log were related to the problem -- I half posted them to simply show that there was nothing more troublesome than that being reported. The video format being saved on my Pi 3 has been a 640 x 480 YUV video at <500kb/s bitrate (mediainfo reports 240kb/s with 475bk/s nominal bit rate). Interestingly (and this is probably unrelated), it has consistently recorded 8.9s when 10 seconds is specified as video record length (the default). Since my last post I upped it to 15 seconds and upon checking it now, it's saving 13.8s of video... except for once when it went on for almost six minutes?? It didn't actually record that much footage (the filesize is a quarter that of the other videos, with an average 0.090 FPS framerate) as it clearly stalled for quite some time. I wonder if this happens to be an instance where ffmpeg was able to recover, eventually. I just cloned raspiCamSrv fresh, set up motion capture again, but this time selected 'main' for Stream on the Config tab. The very first motion trigger caused ffmpeg to lock up entirely. Even lowering the resolution to 320x240 didn't help. Restarting the service and switching back to 'lores' fixed this. So at least that seems like a decent way to trigger the lockup on demand... although I think the lores stream is making consistent motion detection difficult (the mjpeg compression seems to trigger even a Mean Square Threshold of 20). Also... I just noticed that I've only been adjusting the resolution in the Live View tab of Config. The Video tab has been, I presume, 640 x 480 from 'main' stream this entire time, given that I haven't changed that. Adjusting live/photo/video resolutions to mode_1 (1296 x 972) but keeping Live View on 'lores' works fine, but at this resolution on 'main' it's even more perplexing... the ffmpeg process exits (unsuccessfully -- no video is saved), but it seems to crash out the camera entirely with errors:
(Ignore the hostname -- I meant for this to run on a Zero 2 W but after the aforementioned memory issues I moved the microSD to my Pi 3) Restarting the service (thus reloading my 640x480 config with Live View on lores) fixes that error. Speaking of the Zero 2 W though, I just swapped the card back into that and hooked it up to the camera and it seems to now be working fine. No clue why, as even libcamera-hello wouldn't work with it the other day ( |
Hi, However, there were issues with the bad YUV MJPEG stream quality and also with video recording, not only during motion capturing. Today, I did some testing with a Pi Zero running on bullseye. I am attaching some screenshots: Within about an hour of operation with active motion capturing, the system has registered about 230 events and recorded the same number of videos: But also here, I see the message
This has also been reported in Picamera2 Issue: ffmpeg exception 1053, however without a final solution, as far as I can see. As you mentioned memory issues on Pi Zero 2, I had a look at my performance monitoring for the Pi Zero W during the test: With memory usage of ~30%, I do not see any issues. However, with an average CPU utilization of ~70% and CPU temperature of ~60 °C this is probably not the ideal device for 24/7 motion detection. Summarizing, I would say that bullseye seems to be preferable over bookworm, at least on Pi Zero, and if video recording is required. I have a Pi Zero 2 with bookworm recording a photo series for several month now, which works absolutely fine. |
The only 'memory' issue I had with the Zero 2 was the aforementioned error on attempting to initialise the camera, rather than noticing any actual high memory usage. It seemed to fail out without even attempting, best as I could tell. At any rate, either that resolved itself or I fixed it in my sleep somehow. The Zero 2 W had been capturing photo and video (mostly) successfully for four days straight (and I mean straight, as the background noise was easily triggering motion capture so it captured 8GB of mostly useless data, but that's just down to tweaking the threshold properly, I hope). However, it managed to get hot enough to soften the 3D printed mounting bracket it was attached to, and so I decided to try limiting it to 600MHz in an attempt to manage heat, but this actually almost immediately caused the Zero 2 W to start exhibiting issues much like my Pi 3 did, as What I do know is that switching Live View to Info screen for posterity: |
Hi I also have issues with motion capture on a PiZero2W - maybe also related to ffmpeg? I'm running raspiCamSrv V3.5.2 on a Pi5 with camera imx477 and also on a PiZero2W with camera ov5647 - both on latest version of bookworm 64bit. Live view works well for both setups. However it looks like that the PiZero2W does not capture pictures and also no videos. When trying motion detection an error message is displayed (see screenshot below). |
Hi thanks for quick reply... On PiZero2W with bookworm I used "MeanSquareDiff"... and you are right, with the standard settings in LiveView I got very blured image. I did similar ajustments as you mentioned and got at least a good live view. However no motion detection... Luckily I had another SD-card with bullseye 32bit. For testing I booted this on my PiZero2W and installed raspi-cam-srv. There everything is working as expected. However as you described only "MeanSquareDiff" available... I will continue testing and if this fullfills my needs I will stay with bullseye. On the other side, it would be a pitty, it your nice camera-application will not work properly on PiZero2W and Bookworm... if you want I can continue testing on this. |
It is very likely that motion tracking on Pi Zero with Bookworm does not work because of the ffmpeg issue. If "Background Subtraction" is not available as option, you need to install OpenCV, numpy and matplotlib (see RaspiCamSrv Installation step 10). This is possible when running Bookworm on a Pi Zero. With Bullseye it is not. You can also check the events log file at |
I can confirm, that Bullseye does not support advanced motion capturing... in the meantime I setup a new SD-card with Bookworm 32bit (headless) on my PiZero2W and installed raspi-cam-srv V3.5.2 (also ffmpeg; python3-opencv; numpy; matplotlib; flask-jwt-extended). Unfortunately still no advanced motion capturing - only "Mean Squar Diff". |
Yes, thats the package to be installed (see RaspiCamSrv Installation step 10). Whether it could be imported successfully can be seen in dialog Settings/Parameters. Not sure whether 32bit OS would prevent one of the reqired packages to be successfully installed. |
yes, I can confirm that everything was installed according to RaspiCamSrv Installation, but there was no extended motion detection - only mean square diff. now I followed your recommendation and installed on PiZero2W recommended OS by imager (V1.8.5), which is Bookworm 64bit with desktop. Installation of raspi-cam-srv (exactly as described in instructions) went smoothly and application runs well. Advanced motion detection is available, but testing mode is not working at all. I put some screenshot below... Event.log is empty, no failure indications... and it also looks like that enough memory is available... On my Pi5 RaspiCamSrv runs without any issues. |
thanks a lot... in the meantime I did some further testing and also get the impression, that my issues are related to low performance of Raspi PiZero2W - and not due to ffmpeg issues. With the original raspi HQ cam (imx477) I got very blured image in live view. With your recommended settings this is solved, however motion detection (test modus and real) the advanced features still not work - I still get the same failure as reported before. Very strange - on your PiZero it seem to work without this failure. As conclusion, I think Raspi-Cam-Srv runs well on PiZero 2W, as long as the right settings are used and motion detection only used in "mean square diff". Unfortunately controlling sensitivity is here quite hard and I get lots of faults (false negative and false positive - depending on threshold). Since I'm observing outside in nature a masking function could improve this - I alredy have requested this here On the other hand, I can confirm, that everything runs very well on my Pi5 (also with both cameras imx477 and ov5647). Motion detection with advanced features works very well and gives very satisfying results. thanks for all your support :-) |
Sorry to not have a fully understood trigger for this issue, but I'm having problems with motion triggered video capture not saving, seemingly because there's an ffmpeg thread 'stuck' indefinitely:
├─ 2240 ffmpeg -loglevel warning -y -use_wallclock_as_timestamps 1 -thread_queue_size 64 -i - -c:v copy /home/zopiac/raspi-cam-srv/raspiCamSrv/static/events/2025-04-13T11-19-31.mp4
Latest errors in systemd log at the time were:
but these are also present for other encodes which complete successfully. It had gone hours without failing, recording dozens of motion events, before this one popped up. Restarted the service and it happened again within half an hour. Six hours later and I'm still waiting for it to repeat itself.
On the other hand, yesterday I was messing around with different settings and it froze like this nearly every single time motion triggered -- I think it had to do with the sensor mode(s) I was using. Today nothing has changed but it "randomly" hangs on some captures. Maybe resolution or bitrate settings can cause some pipeline to choke with varying frequency?
Killing the ffmpeg process doesn't allow the server to continue detecting motion; restarting the service seems to be the best bet. A rudimentary workaround may be to routinely check for a running ffmpeg process, waiting a minute, and then restarting the service if it's that process is still running. I can try and figure out more about the issue if I'm given somewhere/something to look for, though.
I am currently using a Raspberry Pi 3 with OV5647 camera sensor (640x480 lores mode) and Raspbian Bookworm on kernel 6.12.20. I get memory issues on a Zero 2 but can test on a Pi 5 if it would help... with no guarantee it'll trigger within a day or even a week.
The text was updated successfully, but these errors were encountered: