MATLAB Answers

Appending image frames to existing avi file

22 views (last 30 days)
JohnDylon
JohnDylon on 8 Aug 2016
Answered: JohnDylon on 8 Aug 2016
Can anyone suggest how to append frames to an existing video file? I tried the code below in a for loop, however what I get is it can only create a new file only from given frames and doesn't append to the existing file.
outvid=VideoWriter([vidoutpath, name_vidout]);
outvid.FrameRate=mov.FrameRate;
open(outvid)
for pgc=1:length(RGBbin(1,1,1,:))
writeVideo(outvid, RGBbin(:,:,:,pgc));
end
close(outvid)
Thnx.

Accepted Answer

JohnDylon
JohnDylon on 8 Aug 2016
I found a workaround. Since writeVideo can't append frames to a closed video file, (in my case) closing video in an appropriate step solves the problem. For example,
open(outvid);
for bin=1:n % An individual bin contains a number of frames say 1K
start=some calculation;
finish=some other calculation;
for frame=start:finish
writeVideo(outvid, framesource(frame));
end
% Video object is not closed here
end
close(outvid);
Thank for help.
JD

More Answers (1)

Walter Roberson
Walter Roberson on 8 Aug 2016
VideoWriter cannot append frames.
You might be able to edit the C++ code given in http://www.mathworks.com/matlabcentral/fileexchange/280-aviwrite . Or possibly you could make use of the 'Continue' and 'Initialized' options of https://www.mathworks.com/matlabcentral/fileexchange/15881-mmwrite

Community Treasure Hunt

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

Start Hunting!

Translated by