Forming Video from frames but getting the error

1 view (last 30 days)
Hi,
I am trying to made a video using images (30 fps) but I am getting an error which I am failing to understand or correct it. Both code and error shown below.
Thanks for the help in advance!
Code:
%Read the Images
for m=2:10
images =imread(sprintf('frame%d.jpg',m));%name of files are frame2.jpg till frame190.jpg so on
end
% create the video writer with 30 fps
writerObj = VideoWriter('myVideo.avi');
writerObj.FrameRate = 30;
% open the video writer
open(writerObj);
% write the frames to the video
for u=1:length(images)
% convert the image to a frame
frame = im2frame(images{u});
end
% close the writer object
close(writerObj);
Error:
Brace indexing is not supported for variables of this type.
Error in videowriter (line 16)
frame = im2frame(images{u});

Accepted Answer

Walter Roberson
Walter Roberson on 23 Jul 2020
for m=2:10
images =imread(sprintf('frame%d.jpg',m));%name of files are frame2.jpg till frame190.jpg so on
end
That loop overwrites all of images each time.
for m=2:10
images{m-1} =imread(sprintf('frame%d.jpg',m));%name of files are frame2.jpg till frame190.jpg so on
end
  3 Comments
muhammad choudhry
muhammad choudhry on 23 Jul 2020
Thanks alot for the explanation!
I actually extracted the frames from the video hence did converted to greyscale images then did the backgroud substraction to see the movement of object in the frames. Your code worked and now I can only see the object moving in the video.
I will try to avoid .jpg format. Thanks alot once again!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by