How to write a video file without changing the pixel values?
6 views (last 30 days)
I want to write a video file using 60x60 image with 10 frames and 3 chanels (60,60,3,10). The pixel values of the first channel is between 0 and 1, all the pixel values for 2nd, and 3rd channels are zero. The issue is that the VideoWritter convert the pixel values to uint8 and the pixel values are changing after writing the video. Is there any way to save the orginal pixel values?
s = rng;
data = rand(60,60,10);
v = VideoWriter('data','MPEG-4');
v.FrameRate = 1; % create the video writer with 1 fps
open(v); % open the video writer
images = zeros(60,60,10,'single'); % Allocate space
images_3chn = zeros(60,60,3,10,'single'); % Allocate space for 4D matrix
images_3chn(:,:,1,:) = data ;
images_3chn(:,:,:,j) = im2single((images_3chn(:,:,:,j))); % convert to 3 channels
DGM on 2 Dec 2021
Edited: DGM on 2 Dec 2021
As far as I know, no. Anyone is free to correct me on that.
I don't know of any common formats for lossless video that use floating-point data and are also supported by MATLAB tools. The video tools support lossless compressed JPEG2000 files via the 'Archival' profile, but not for floating-point data.
See the docs for VideoWriter
If there were such a format, would any other software be able to use it? If not, then what's the point of using a video file format? If all you need to do is store a MxNx3xF numeric array in a floating-point format for use in MATLAB, why not just use a .mat file?