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

4 ビュー (過去 30 日間)
% 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);

採用された回答

Stephen23
Stephen23 2016 年 2 月 19 日
編集済み: Stephen23 2016 年 2 月 19 日
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.
  2 件のコメント
Benjamin Dempsey
Benjamin Dempsey 2016 年 2 月 19 日
編集済み: Benjamin Dempsey 2016 年 2 月 19 日
Thanks, im very new to matlab so struggle - it seems to be working, do you know if there is a way to stop it displaying the images as it is running?
Stephen23
Stephen23 2016 年 2 月 19 日
編集済み: Stephen23 2016 年 2 月 19 日
Have a close look at your loop, and these lines of code:
% Display image in an axes control.
imageArray = imread(fullFileName);
imshow(imageArray) % Display image.
This is why code comments are useful: they tell you what the code is supposed to do (and it is why beginners need to learn to write code comments). So, what do you think happens in those lines? Hint: the function imshow only does one thing: it display an image. Try putting a % at the start of that line to stop it from being called (this is called "commenting" a line, because it turns the code line into a comment that does not run).
There is nothing wrong starting to learn something new! The biggest tip I can give you is "always read the documentation!". You can search MATLAB's documentation using your favorite internet search engine. This might be helpful too:

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by