How to process float32 arrays by video compression tools and get back float32 values? Video and image formats which natively supports float32 values

48 views Asked by At

I have multiple arrays of float32 values, which might be interpreted as images. They go in the sequence. They are one channel only and they don't restrict itself to [0,1] range.

I would like to process them by ffmpeg and create compressed video out of them. Then I want to decompress them to the sequence of images, or possibly also raw array of float values.

Let's say I have RAWARRAYSFILE of float32 of frames with given dimensions and I want to convert it to the video. In ffmpeg there is a pix_fmt gray32le and I can convert my raw files into the video using e.g.

DIMX=3250
DIMY=2132
dd if=$RAWARRAYSFILE |  ffmpeg -y -framerate 30 -f rawvideo -s "${DIMX}x${DIMY}" -pix_fmt grayf32le  -i - vid.mp4

Now to get the sequence of the images back, I can

ffmpeg -i vid.mp4 -pix_fmt grayf32le out/processed%05d.tif

However not the vid.mp4 video nor out/processed%05d.tif will be float32. Are there a formats supported by ffmpeg which would support float32 natively?

Are you aware of any image format, which would natively support float32 values? Are you aware of any video format, which would natively support float32 values?

1

There are 1 answers

2
tshiono On

PFM image format stores still image as 32bit floating point pixels. The format is so simple that it will be easy to write your own code to read/write PFM files.

Here's an example for creating a sequence of images with float grayscale:

ffmpeg -i vid.mp4 -pix_fmt grayf32le out/processed%05d.pfm

Please note you'll need to use FFmpeg 4.4 or later to process PFM files.

Another possible option will be DPX image format which also supports little-endian 32bit float pixel data.