How to change movie to image per frame

조회 수: 4 (최근 30일)
Mr Smart
Mr Smart 2012년 11월 20일
답변: Sk Sahariyaz Zaman 2016년 4월 28일
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

답변 (2개)

Walter Roberson
Walter Roberson 2012년 11월 20일
편집: Walter Roberson 2012년 11월 20일
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 2016년 4월 28일
Let me know, it solve your problem or not.

Community Treasure Hunt

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

Start Hunting!

Translated by