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

Python • Re: Picamera2, unable to toggle preview while continuously recording

$
0
0
I solved my own issue! If anyone else encounters something similar, an in-depth read of the picamera docs got me what I needed. This is my updated code:

Code:

from picamera2 import Picamera2, Previewfrom picamera2.encoders import H264Encoderimport time picam2 = Picamera2()picam2.preview_configuration.enable_lores()picam2.preview_configuration.lores.size = (320, 240)picam2.configure("preview")picam2.start_preview(Preview.QT)encoder = H264Encoder(1000000)picam2.start_recording(encoder, "test6.h264")picam2.start()time.sleep(5)picam2.stop_preview()picam2.start_preview(Preview.NULL)time.sleep(5)picam2.stop_preview()picam2.start_preview(Preview.QT)time.sleep(5)picam2.stop()
Little messy but it works. Essentially, I needed to send the "lores" stream to the preview window, and then keep the recording stream using the default main stream from the camera. This way the recording can maintain quality and the preview screen can be a lower resolution as the screen is tiny anyways. I also realized that instead of stopping the preview and delaying, you need to immediately start the preview and set it to null in order for there to not be gaps in the recording. Not entirely sure why this is the case, but it will not work for me without doing this. If anyone else finds a more elegant solution feel free to let me know otherwise I consider this case closed!

Statistics: Posted by katie2000c — Mon Oct 28, 2024 10:34 pm



Viewing all articles
Browse latest Browse all 1286

Trending Articles