Create an MP4 video from a set of 16 bit images (mono)
조회 수: 24 (최근 30일)
이전 댓글 표시
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
Richard Burnside
2023년 6월 14일
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.
답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!