0

Is it possible instead of copying a variable content to a given location ( stream.copy_to('motion.h264') ) save it in a variable to be further processed. Reason I would like to do so, is to be able to downgrade video resolution once the video buffer has been collected.

Thanks in advance!

import io
import random
import picamera

def motion_detected():
    # Randomly return True (like a fake motion detection routine)
    return random.randint(0, 10) == 0

camera = picamera.PiCamera()
stream = picamera.PiCameraCircularIO(camera, seconds=20)
camera.start_recording(stream, format='h264')
try:
    while True:
        camera.wait_recording(1)
        if motion_detected():
            # Keep recording for 10 seconds and only then write the
            # stream to disk
            camera.wait_recording(10)
            stream.copy_to('motion.h264')
finally:
    camera.stop_recording()
Bert
  • 29
  • 5
  • Yes, you can use the object to keep and read the data etc, the docs there seemed to tell it well, https://picamera.readthedocs.io/en/release-1.10/api_streams.html – antont Sep 13 '20 at 17:29
  • I know, I know - unfortunately the doco does not provide a clear example. That's where I need help with... Ty – Bert Sep 13 '20 at 18:09
  • 1
    it seems you deleted this question and created again the same question. If you want to access these compressed data then you don't have to assign to other variable because you have it all in `stream` - and you can use `stream.readall()` to get all buffer or `stream.read1()` to use it in `for`-loop. i found it digging in source code of `copy_to` but problem can be that it directly generates compressed data (probably using special `chip` in picamera hardware) which it is easy to save to file but it would need other module to decompress, downgrade and compress back. – furas Sep 13 '20 at 21:07

0 Answers0