Hi,
I am using thermal/infrared cameras (Optris Xi 410) to record videos. Since the values can be converted to actual temperatures, I need to be able to either:
- Save video frames as float
- Save video frames as 16U to later convert and have the desired precision (uint8 is too restrictive)
To have the desired value range, I am currently saving the output as single-channel 16U avi video with the FFV1 fourcc. Due to the lack of compression, the videos get prohibitively large, since I need to record over several hours with multiple cameras. Therefore, I would like to switch to a codec with compression. I tried XVID and DIVX, but they either get converted to uint8 or it fails to load the frames.
For recording, I use Debian 12, reading on Ubuntu 24.04, opencv-python version 4.10.0.84.
Here are the snippets how I read/write the frames (with xvid codec, not the working ffv1 one:
twriter_thermal = cv2.VideoWriter(filename=recfilepath, apiPreference=cv2.CAP_FFMPEG, fourcc=cv2.VideoWriter_fourcc(*'XVID'), fps=25, frameSize=(thermal_width.value, thermal_height.value),
params=[cv2.VIDEOWRITER_PROP_DEPTH, cv2.CV_16U, cv2.VIDEOWRITER_PROP_IS_COLOR, 0, ])
...
writer_thermal.write(tempimg.astype(np.uint16))
and for reading:
cap = cv2.VideoCapture(videoroot, cv2.CAP_FFMPEG)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc(*'XVID'))
cap.set(cv2.CAP_PROP_FRAME_TYPE, cv2.CV_16U)
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0.0)
With cap.read()
always returns this way. Here are my questions:
- Is it possible to use a codec with compression for 16bit single-channel videos? If so, which one?
- Is this caused by some other mistake I am making?
- I am also grateful for any other insight on how to write/read 16bit or float video frames in any form.
Best regards and thank you in advance!