user7715
user7715

Reputation: 21

Converting image files to AVI video in MATLAB

Here, I'm trying to convert image frames to video. The image frames are contained in the folder 'folder_1'. Whenever I'm trying to run it, I'm getting the error: ''RIFF' did not appear as expected'. Below is the code. What might be wrong in here? And yes, the images are on high dynamic range format.

files = dir('folder_1');
aviobj = avifile('a.avi'); %creating a movie object
for i=1:numel(files) %number of images to be read
    a = hdrread(file(i));  
    a = uint8(a);%convert the images into unit8 type
    M = im2frame(a);%convert the images into frames
    aviobj = addframe(aviobj,M);%add the frames to the avi object created previously
    fprintf('adding frame = %i\n', i);
end
disp('Closing movie file...')
aviobj = close(aviobj);
disp('Playing movie file...')
implay('a.avi');

Upvotes: 2

Views: 12306

Answers (2)

Channabasappa Konin
Channabasappa Konin

Reputation: 31

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

% Set frame rate
writerObj.FrameRate = 30;

% Open video writer object and write frames sequentially
open(writerObj)

for i = 1:30                   % Some number of frames
     % Read frame
     frame = sprintf('frame %d.jpg', i);
     input = imread(frame);

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

% Close the video writer object
close(writerObj);

% 'Video.avi' will be created in the folder that contains the code.

This code will work.

Upvotes: 3

wcoool
wcoool

Reputation: 21

files = dir('folder_1');
N=10;
nframe=3000;
writerObj = VideoWriter( 'MINALIVE .avi' );
writerObj.FrameRate = N;
open(writerObj);
figure;
for i=1:numel(files) %number of images to be read
    a = hdrread(file(i));  
    a = uint8(a);%convert the images into unit8 type
    f.cdata = a;
    f.colormap = [];
    writeVideo(writerObj,f);
end
close(writerObj);

you can try this maybe it works!

Upvotes: 2

Related Questions