How to get individual image from video file with the .mat format?
3 views (last 30 days)
Show older comments
Hello,
I have video files of the color image (480x640x3 uint 8) and depth image (480x640 uint 16) with the .mat format both. I need to extract frames and save individual frames to separate image of jpeg files.
I tried a few ways to extract those files as suggested but they just didn't work such cell2mat and cat. I failed to convert using VideoReader since the .mat is not supported.
Am I need to convert the files to .mp4 video format first? If yes, how to do it? Any tips?
Thank you very much
0 Comments
Accepted Answer
Jan
on 25 Jul 2018
MAT files are created by Matlab and can contain data of any class and shape. Knowing the class of the single images is not sufficient to know, how the movie is store inside the file. The readers cannot guess this detail, but you can check it easily:
Data = load('YourFile.mat')
disp(Data)
What do you see? After a load command, we are not talking about importing from a MAT file, but now the inputs are the variables found in this files. And if you post, what this is, we can create a solution.
Usually It is useful if you post the failing code and the corresponding error messages.
10 Comments
Stephen23
on 7 Aug 2018
Edited: Stephen23
on 7 Aug 2018
@hana razak: Jan made one trivial mistake with the indexing, which is easy to fix:
Data = load('YourFile.mat');
nFrame = numel(Data.imagecolor);
for kk = 1:nFrame
imwrite(Data.imagecolor{kk}, ...
fullfile(Folder, sprintf('%06d.jpg',kk)));
end
"I really need the last answer so I can process my video way much faster instead of doing it one by one."
Given that your goal is to save the frames individually, I doubt that there is any convenient way to speed up this process: the slowest part is going to be the file reading/writing, not the very simple loop that occurs in MATLAB. Any attempt to speed up your code should be focused on the hard-drive (e.g. use an SSD rather than a HD, or a combo drive). Rather than guessing how to speed up this process you need to learn where the bottle-necks are. Start by using the profiler:
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!