MATLAB: Convert frames into video. Previous code i took frames from video, edited them and now i want to put them back. I got code from previous answer but it isnt working. Thanks

image analysisvideo processingwritevideo

% Make an avi movie from a collection of PNG images in a folder.
% Specify the folder.
myFolder = 'C:\Users\bende\Documents\MATLAB\ppframes';
% Get a directory listing.
filePattern = fullfile(myFolder, '*.PNG');
pngFiles = dir(filePattern);
% Open the video writer object.
writerObj = VideoWriter('YourAVI.avi');
% Go through image by image writing it out to the AVI file.
for frameNumber = 1 : length(pngFiles)
% Construct the full filename.
baseFileName = pngFiles(frameNumber).name;
fullFileName = fullfile(myFolder, baseFileName);
% Display image name in the command window.
fprintf(1, 'Now reading %s\n', fullFileName);
% Display image in an axes control.
imageArray = imread(fullFileName);
imshow(imageArray) % Display image.
% Write this frame out to the AVI file.
writeVideo(writerObj, imageArray);
end
% Close down the video writer object to finish the file.
close(writerObj);
*I get this error***
Error using VideoWriter/writeVideo (line 338)
OBJ must be open before writing video. Call open(obj) before calling writeVideo.
Error in Frame_2_vid (line 22)
writeVideo(writerObj, imageArray);

Best Answer

Why not read the error message and do exactly what it tells you to do? The message is quite helpful: "Call open(obj) before calling writeVideo" means you need to put this before your for-loop:
open(writerObj)
There is also a big clue that you close the object, but never open it.
The videowriter documentation also clearly shows that the video object is opened before being written. The documentation is there for everyone to read.