how to divide the .wmv (movie) format to multiple images?

sir, Now i need to know how to make the .wmv movie to the multiple frames of the images. here i use the mmreader function to find the frames but it shows the error the
warning: Unable to determine the number of frames in this file.
1. how to find the number of frames in the .wmv
2. Next how to make the movie to the multiple images

Answers (1)

The movie is a variable-time movie. You need to read in the entire movie once before mmreader knows the number of frames in the movie.
You use mmreader to read one frame at a time, and imwrite() the cdata of the frame to a file.

12 Comments

how to use imwrite , are you specified using imwrite to save each frame can you explain the answer in the coding sir
imwrite(YourDataMatrix, 'YourFileName.tif');
readerobj = mmreader('dec072012132350.wmv');
frame = read(readerobj,inf);
readerobj.NumberOfFrames
Warning: Unable to determine the number of frames in this file.
ans =
498
now I found the number of frames and how to save all the frames of the video into the image
readerobj = mmreader('dec072012132350.wmv');
fidx = 1;
while true
try ME
frame = read(readerobj, fidx);
catch
break;
end
imgname = sprintf('frame%05d.tif', fidx);
imwrite(frame, imgname);
fidx = fidx + 1;
end
I run your following script its shows the warning
readerobj = mmreader('dec072012132350.wmv');
fidx = 1;
while true
try ME
frame = read(readerobj, fidx);
catch
break;
end
imgname = sprintf('frame%05d.tif', fidx);
imwrite(frame, imgname);
fidx = fidx + 1;
end
Warning: Unable to determine the number of frames in this
file.
Warning: This try-catch syntax will continue to work in R2007b,
but may be illegal or may mean something different in future releases of MATLAB.
See Release Notes for MATLAB Version 7.4, "Warning Generated by try-catch" for details.
Now what to do sir
They are only warnings.
To get rid of the second one, change
try ME
to
try
and change
catch
to
catch ME
I am not expecting it to show even that. The imwrite() take place silently. But if you like, before the "fidx = fidx + 1" line, add
fprintf('wrote frame to %s\n', imgname);
sir i get the total number of frame at 498 by using this code
readerobj = mmreader('dec072012132350.wmv');
frame = read(readerobj,inf);
readerobj.NumberOfFrames
Warning: Unable to determine the number of frames in this file.
ans =
498
now I found the number of frames
end
but i save the code in editor window to run it shows the ans=1 but in the command window i run separately each codes line by line it shows the ans = 498 how its possible
and also i run your script
readerobj = mmreader('dec072012132350.wmv');
fidx = 1;
while true
try
frame = read(readerobj, fidx);
catch ME
break;
end
imgname = sprintf('frame%05d.tif', fidx);
imwrite(frame, imgname);
fprintf('wrote frame to %s\n', imgname);
fidx = fidx + 1;
end
in the command window its show the more than 498 frames been saved and also run accords through the editor window show ans = 3 but separately in command window its gives the result of saved images more than 498 frames . i didn't have deep knowledge in the mmreader concept so clearly explain as soon as possible sir
Any "ans =" you get from my script should be ignored, as the script makes no calculations that are intended to be output.
For your script try
readerobj = mmreader('dec072012132350.wmv');
frame = read(readerobj,inf);
numframe = readerobj.NumberOfFrames;
numframe
sir i found the mistake i did i save the file name as 1.m so the ans= 1, and the file name 2.m so the ans = 2 thank you for your kind help
Yes, that would do it. You cannot name a .m file with a number -- or rather, if you do, the number will be output instead of running the file.

Sign in to comment.

Tags

Asked:

on 17 Dec 2012

Community Treasure Hunt

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

Start Hunting!