Create an MP4 video from a set of 16 bit images (mono)
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have a cell array of images (app.imgArray) that are all 16 bit. Im trying to output them as a video file (preferable mp4), but Im not having any sucess yet. I've realised that the format has to be either double or unit8 (from error messages!), so when I convert to uint8, the code finishes, however, the mp4 video file is just white.
it also seems to ignore the frame rate=1 I code. It reads back 30fps.
dt = datestr(now,'dd-mmm-yyyy HH-MM-SS'); %get current dateTime
filepath='F:\Temp\';
filename=fullfile(filepath,[dt,'- VidMatlab.mp4']);
diskLogger=VideoWriter(filename,'MPEG-4'); % Use the MPEG-4 Codec
disklogger.FrameRate=1; %only have about 8 images and want to see them.
open(diskLogger);
ReportMessage(app,'..Disklogger Opened'); %My reporting function
data=app.imgArray;
class(data{1})
numFrames=size(data,2);
ReportMessage(app,['..Recording To Disk Started ', num2str(numFrames)]);
for x=1:numFrames
writeVideo(diskLogger, uint8(app.imgArray{x}));
end
ReportMessage(app,'DiskLogger Stopped');
close(diskLogger);
disp('Finished Saving Video')
%check
disp('checking file')
v = VideoReader(filename);
fr=v.FrameRate; %double
dur=v.Duration;
ReportMessage(app,['Video Saved as: ',filename, ' @',num2str(fr),'fps (',num2str(dur,'%.1f'),' s)']);
1 comentario
Richard Burnside
el 14 de Jun. de 2023
In the past I have found it necessary to render each frame on a figure then use "getframe" before encoding the frame to video. That was years ago so maybe that it no longer necessary.
Respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!