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

Camera board • raw .dng video and Pyqt5 ThreadPoolExecutor/QThreadPool?

$
0
0
Hi,

A few months ago, therealdavidp helped me build a python script that allowed me to record uncompressed .dng files at a high enough framerate to turn them into a video sequence. Here's the code in question:

Code:

from concurrent.futures import ThreadPoolExecutorfrom picamera2 import Picamera2import osimport datetimeimport timeimport keyboardimport pathlibdef save_dng(i, metadata, raw_im):        picam2.helpers.save_dng(raw_im, metadata, config['raw'],str(new_dir)+"/"+ f"image_{i:04}.dng")pool = ThreadPoolExecutor(4)picam2 = Picamera2()raw = {'size': (2028, 1080), 'format': 'SBGGR12'}config = picam2.create_video_configuration({'size': (640, 360)}, raw=raw)picam2.configure(config)picam2.start(show_preview=True)while keyboard.read_key() == "p":   new_dir = pathlib.Path(str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')) + "_" + "picam2")   new_dir.mkdir()   new_dir.chmod(0o777)   for i in range(1440):                request = picam2.capture_request()        pool.submit(save_dng, i, request.get_metadata(), request.make_buffer('raw'))        request.release()pool.shutdown()        
Since then, I've developed an interface with Pyqt5 to create an opensource camera with all the settings allowed by the Picamera2 library, different image formats as well as different video formats (.h264, .mp4).
I'd like to integrate into this interface the ability to record .dngs to create uncompressed video sequences.
However, I don't know the best way to go about it.
Should I stick with ThreadPoolExecutor and try to interface it with Pyqt5?
Or should I replace ThreadPoolExecutor with Pyqt5's Multithreading, in particular with QRunnable and QThreadPool?

I've already implemented multithreading in my script for recording video in .h264 and .mp4 to prevent the preview that appears on my screen during recording from slowing down. It works pretty well, but if I've done it, I've probably done it in a pretty crappy way.
If I have to use multithreading, I'm having a bit of trouble converting the script designed with therealdavidp to use Pyqt's multithreading.
Could you help?

Thanks

ps: I'm not copying my main script here, it's much too long. I have a "lite" version that keeps a bit the same logic, which makes 150 lines if needed.

Statistics: Posted by davebixby — Mon Mar 04, 2024 3:29 pm



Viewing all articles
Browse latest Browse all 4824

Trending Articles