I'm trying to write images within a loop to an AVI file. Right now, I'm using VideoWriter and getframe to achieve that goal. The code generally goes something like this:
FoodVideo = VideoWriter('tempp.avi');
FoodVideo.FrameRate = 25;
open(FoodVideo);
hh=figure('Visible','off');
for i=1:20
imshow(example_image{i});
hold on;
text(100,100,sprintf('Frame Number: %d',i));
hold off;
currFrame = getframe(hh);
writeVideo(FoodVideo,currFrame);
end
close(FoodVideo);
The problem is that getframe displays the image before writing it. I can't think of a way of incorporating the text into the image data, so I eliminated that way of handling the matter (using im2frame...). I know I can use avifile and addframe, but I want to use VideoWriter because matlab says avifile will be removed... Is there any way to write the images using VideoWriter without displaying first?
Another related question: When I run my code, it seems like I capture my screen instead of the figure; I recently switched a computer, and this started happening only in the new computer. Does anyone have a clue as to why that might be?
Thanks, Aviram
Even if this is not answering your question with respect to VideoWriter, maybe it is of help.
When creating a video with matlab, I usually export a series of jpeg's or png's. I do not even touch video functions in matlab. Then, I use MEncoder (which is part of the MPlayer project) for turning the image series into a video. By doing so, you can circumvent a lot of matlab related issues and receive much better video files.
I managed to find a solution after some searching. I am using the hardcopy function to incorporate the text into the image data and then using im2frame I can change it into a format fit to be used with VideoWriter. This seems to work perfectly: