picamera icon indicating copy to clipboard operation
picamera copied to clipboard

Whole RAM buffer is sometimes written to file from PiCameraCircularIO

Open 3gfisch opened this issue 4 years ago • 0 comments

Hi, I have a RaspberryPi surveillance camera project. And spend evenings debugging my code to find out the PiCamera API sometimes safes not the amount of seconds I give with the copy_to but saves everything in memory.

What my Programm does: Start recording h264 video in around 1GB RAM loop with; stream = picamera.PiCameraCircularIO(camera, seconds=500) Then cyclic also grab an jpg image; camera.capture(streamImg, 'bgr', use_video_port=True) Then some processing with OpenCV and a Coral Edge TPU and logic where i decide if something interesting happened and determine how long i want to save to disk with; stream.copy_to(p.recEventTimeDir + '.h264', seconds=recTimeToSaveL) And empty the stream after saving..

But sometimes (3-10x a day of 200 videos) it saves the whole RAM loop ~1GB to the file. Most times it worked correctly... But my debugging output showed that it wanted to save only 65s for example and i got like 10 min of video. That’s where i tripple checked my debugging and made sure to save every cycle a debugging picture with the actual time i want to save on it. Next i tried to use the size instead of seconds parameter for the copy_to to try if this part of the API works better. So i roughly estimated my file size for testing and it worked. no 1GB videos 👍 but since its compressed i can’t use this for an exact (-+1sec) video recording so i looked what options else i have. I found the frames parameter here on git and though perfect, if this is a timing, timestamp issue but the size works then maybe the frames work too and i have a fixt framerate. But then i found out the framerate parameter is „new“ and not available in the pip installed 1.3 version... if i have seen this right the released 1.3 is 1 year older than the master wich is also mostly form 2018.?

So i tried to get the master branch installed, long story short, it was a pain for me to get the right commands and get it working but in the end it solved my problem, i first tried the seconds parameter again and it worked 👍 no 1GB videos any more 😁

So maybe this will help some people who face similar problems.

But as a general fix / outcome, wouldn’t it make sense to release the current master branch for pip (how ever this works) that every one who simply installs it has the newest versions with obviously some fixes in it? Or why is the release that old? Thanks

What i did to install the versions from git master see the following but without any guarantee, i searched and tried many command and im not an expert on pip or python.. to get the array part working was the hardest for me. I removed everything from pip and apt-get from PiCamera I use virtualenv wrapper but shuould work for every env if you replace the path to your venv .virtualenvs/cv/bin/python -m pip install --upgrade git+https://github.com/waveform80/picamera.git@master#egg=name[array] .virtualenvs/cv/bin/python -m pip install colorzero

3gfisch avatar Sep 08 '20 20:09 3gfisch