Create an MP4 video from a set of 16 bit images (mono)

조회 수: 19 (최근 30일)
Jason 2023년 6월 14일
답변: Jason 2023년 6월 14일
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
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.
ReportMessage(app,'..Disklogger Opened'); %My reporting function
ReportMessage(app,['..Recording To Disk Started ', num2str(numFrames)]);
for x=1:numFrames
writeVideo(diskLogger, uint8(app.imgArray{x}));
ReportMessage(app,'DiskLogger Stopped');
disp('Finished Saving Video')
disp('checking file')
v = VideoReader(filename);
fr=v.FrameRate; %double
ReportMessage(app,['Video Saved as: ',filename, ' @',num2str(fr),'fps (',num2str(dur,'%.1f'),' s)']);
  댓글 수: 1
Richard Burnside
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개)

Jason 2023년 6월 14일
I think I've nearly done it myself.
1: The framerate issue was just a typo (missed the capital "L"
it should be diskLogger.FrameRate=1; instead of disklogger.FrameRate=1;
2: I can now see the video, i.e. its no longer white by dividing by 256 when I cast to uint8.
writeVideo(diskLogger, uint8(app.imgArray{x}/256));
They are however slightly darker than the full 16 bit. Are there any tricks to try to lighten up the images (video) more - i.e. make the darker areas a bit more lighter rather than black?




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by