Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1584

Python • Picamera2, unable to toggle preview while continuously recording

$
0
0
Hello, I am using a raspberry pi 4b with bookworm 64bit OS. I am sshed into my pi that has a pitft screen where I am displaying the preview(hence the preview size and using QT). I am trying to debug this python script to use it in a larger program I am converting from buster 0S and picamera -> bookworm OS and picamera2 library. I seem to have issues trying to toggle the preview page on/off while continuing to record the camera stream to the same output the entire time.

Here is my script:

Code:

from picamera2 import Picamera2, Previewfrom picamera2.encoders import H264Encoderimport timepicam2 = Picamera2()picam2.start_preview(Preview.QT, x=0, y=0, width=320, height=240)picam2.start()encoder = H264Encoder(1000000)picam2.start_recording(encoder, "test4.h264")time.sleep(5)picam2.stop_preview()time.sleep(5)picam2.start_preview(Preview.QT, x=0, y=0, width=320, height=240)time.sleep(5)picam2.stop_preview()time.sleep(5)picam2.start_preview(Preview.QT, x=0, y=0, width=320, height=240)time.sleep(5)picam2.stop() 
The issue I'm encountering is that there is only a recording while the preview is active. I aimed my camera at a stopwatch, and it contains a 15 second video showing the timer from 1-5, 10-15, and 20-25 seconds. I would like it to be recording for the entirety of the video, it seems that the stop_preview also stops the start_recording, and that start_preview boots the recording back up somehow. Basically, I want to toggle the preview on and off while maintaining a continuous recording. Any tips?

Statistics: Posted by katie2000c — Mon Oct 28, 2024 6:00 pm



Viewing all articles
Browse latest Browse all 1584

Trending Articles