-1

I want to convert 95 tiffs to an avi.

this is the code I'm using:

 v = VideoWriter('newfile.avi','Uncompressed AVI');
 open(v);
 %95 images
 for k=1:95      
     yr=2005;
     icnt=yr+1;
frame = sprintf('scale%dRCP2.6.tif', icnt);
     input = imread(frame);

     writeVideo(v,input);
 end
 close(v);

It creates the avi file, but it only seems to pull in one image? I think it's probably a problem with when the frame is being read in within the loop but I can't figure out what's going wrong.

I have also tried this approach:

    % Create a video writer object
writerObj = VideoWriter('Video.avi');

% Set frame rate
writerObj.FrameRate = 10;

% Open video writer object and write frames sequentially
open(writerObj)
yr=2005;
for i=1:95;
icnt=yr+1;
frame = sprintf('scale%dRCP2.6.tif', icnt);
     input = imread(frame);

     % Write frame now
     writeVideo(writerObj, input);
end

% Close the video writer object
close(writerObj);

But the avi does not work at all using this code. There are no images being pulled in to it.

matlabcat
  • 172
  • 2
  • 12
  • Please consider changing the title of your question, as this is not a problem related to tiff sequence conversion to avi. This is just "_Why my code converting image sequence to avi video is not working as expected?_" – Muttley Oct 18 '18 at 10:40
  • In future, try debugging - for example by printing out the file names before you read them or viewing each image loaded before adding them to the video. – nkjt Oct 18 '18 at 17:36

1 Answers1

0

Your problem is not related to the source image format (tiff), you are just adding always the same image scale2006RCP2.6.tif.

Taking into account the first code, the mistake is icnt=yr+1, which I guess it should be icnt=yr+i instead;

Fixed that, it worked correctly on my Matlab2016b with ten images on my Windows pc. Some remarks:

  • specify the framerate (as you did in your second code), but consider that watching 10 figures per second is too much: v.FrameRate = 1 sounds better;

  • verify all the images have the same size. If not, consider rescaling all of them to the same size.

Muttley
  • 502
  • 2
  • 10