0

I'm running Pi 4 with a 5 megapixel OV5647 camera attached to its camera port. I'm using motion to run motion detection, with the goal of running low-res stream at 2 frames per second for detection and ramping it up to 1080p 30 frames once motion is detected. So far I only found config options to increase framerate in motion, and even that does not seem to work.

My motion.conf file has, among other, following values (value comments came with default config):

# Image width (pixels). Valid range: Camera dependent, default: 320
width 1920

# Image height (pixels). Valid range: Camera dependent, default: 240
height 1080

# Maximum number of frames to be captured per second.
# Valid range: 2-100. Default: 100 (almost no limit).
framerate 2

#########################################################################################

# The mini-http server listens to this port for requests (default: 0 = disabled)
stream_port 8081

# Quality of the jpeg (in percent) images produced (default: 50)
stream_quality 90

# Output frames at 1 fps when no motion is detected and increase to the
# rate given by stream_maxrate when motion is detected (default: off)
stream_motion on 

# Maximum framerate for stream streams (default: 1)
stream_maxrate 30

Unfortunately, this does not seem to affect stream on port 8081 - it keeps going at 2 fps even when motion is detected. Furthermore, even if I change config to

framerate 30

I don't get more than 6 fps, whether there is motion or not, allthewhile htop shows just 1 core busy and then maximum at 50%, even during 8081 stream active.

At the same time, I get 30fps 1080p from raspivid. I can easily split raspivid output and write it into several output streams in my app, so I was wondering, can I somehow feed it into motion? Perhaps emulate a web-cam or ip-cam? Or, maybe, run some other form of motion detection on it?

P.S. I have considered running motion until it detects something, then shutting its process down and starting raspivid, but I'd like to avoid a few seconds lag that would exist before activating raspivid stream in this case. AFAIU, raspivid and motion can't use the same camera directly at the same time?

0

My digging for how to split video streams, especially with different resolutions, led me to MMAL C library used by Pi: http://www.jvcref.com/files/PI/documentation/html/index.html AFAIU, it gives you much lower lever access to Pi hardware, allowing accelerated operations on raw video stream.

In case someone needs to have several video streams, like one high-res stream and one low-res stream, or a stream with stills, for analysis like motion detection, there are a few examples here in more high-level languages:

C# (.NET) library (this one even has it's own motion detection capabilities) https://github.com/techyian/MMALSharp/wiki/Advanced-Examples

Python library https://picamera.readthedocs.io/en/release-1.6/recipes2.html#recording-at-multiple-resolutions

Rust also seems to have a few wrappers for original lib, but I haven't had a chance to look deeper into them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.