How to change movie to image per frame

1 view (last 30 days)
Mr Smart
Mr Smart on 20 Nov 2012
Answered: Sk Sahariyaz Zaman on 28 Apr 2016
Hello , anyone does know I need to change video to image with each frames.And now my problem was: I can`t read in matlab, mpg or wav file.When I read this short movie with mmreader . But Matlab says - warning: Unable to determine the number of frames in this file.I have short movie. Here my .m file from internet:
% Read and play back the movie file
obj=mmreader('shuttle.wmv');
nFrames =obj.numberOfFrames;
vidHeight = obj.Height;
vidWidth = obj.Width;
% Preallocate movie structure.
mov(1:nFrames) = ...
struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),...
'colormap', []);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(obj, k);
end
% Size a figure based on the video's width and height.
hf = figure;
set(hf, 'position', [150 150 vidWidth vidHeight])
% Play back the movie once at the video's frame rate.
movie(hf,mov, 1, obj.FrameRate);
******* And how to make video to image per frame.Thanks

Answers (2)

Walter Roberson
Walter Roberson on 20 Nov 2012
Edited: Walter Roberson on 20 Nov 2012
Movies that were recorded with variable frame rates cannot have their numberOfFrames determined until they have been read through completely.
You can work around by not preallocating and simply reading everything at once:
mov = read(obj);
Side note: because of MATLAB's copy-on-write behavior, pre-allocating the cdata field does not help; the cdata will be completely overwritten in your assignment, not using the pre-allocated memory.

Sk Sahariyaz Zaman
Sk Sahariyaz Zaman on 28 Apr 2016
Let me know, it solve your problem or not.

Categories

Find more on Convert Image Type 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!