Movie2avi only last frame

4 views (last 30 days)
Natasha
Natasha on 11 Apr 2014
Commented: Walter Roberson on 11 Apr 2014
For the code below I get no errors until I try to save to movie to an .avi file. If I use the code as shown I get no errors but the movie contains only the last photo specified. If I replace the F(i) after movie2avi with F I get error messages. I am somewhat new to matlab and there may be a very obvious fix to this, thank you in advance for your patience and help.
Code:
clear all;
for i=420:434;
name='March_03_20cm01';
filetype='.jpg'
name1=strcat(name,num2str(i),filetype);
d = imread(name1);
imshow(d)
hold on
x=[2500,0];
y=[2300,250];
plot(x,y,'LineWidth',5);
F(i)=getframe(gcf);
hold off
movie(F(i))
end
movie2avi(F,'RicePilewLineb.avi')
Error Messages:
Error using avifile/addframe>ValidateFrame (line 288)
Frame must be 0 by 0.
Error in avifile/addframe (line 158)
ValidateFrame(aviobj,width, height,dims);
Error in movie2avi (line 67)
avimov = addframe(avimov,mov);
Error in picwline (line 19)
movie2avi(F,'RicePilewLineb.avi')

Answers (1)

Walter Roberson
Walter Roberson on 11 Apr 2014
If your source images are not exactly the same size then imshow() could result in frames that are not all the same size, leading to getframe() storing frames of different sizes. Frames must, however, be exactly the same size for movie2avi to work.
I do not know why you movie(F(i)) ? As that would be a single frame it would be clearer if you were to use
imshow(F(i).cdata)
drawnow()
but even then, it is not clear why you would show a copy of what was just captured ?
  2 Comments
Natasha
Natasha on 11 Apr 2014
All of the photos are exactly the same size they are from a series of time lapse images.
Walter Roberson
Walter Roberson on 11 Apr 2014
In any case it would be safer to getframe() a particular rectangle

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!