How to write a video from png files and/or matlab figures

8 ビュー (過去 30 日間)
Anna Clouvel-Gervaiseau
Anna Clouvel-Gervaiseau 2020 年 9 月 23 日
コメント済み: Bjorn Gustavsson 2020 年 9 月 23 日
Hello,
I've been trying to write a simple code that takes a sequence of images and makes a video from them. However, the video file always ends up empty or unreadable, and I have no idea why the code isn't working. This is the code :
video23 = VideoWriter('video23.avi');
%video23.FrameRate = 1;
open(video23);
baseN = 'VectorOverlay';
d = '_';
e = 'Individual.png';
f = '-';
for i = 1:87
file_name = [baseN,d,num2str(i),f,num2str(i+1),d,e];
%VectorOverlay_1-2_Individual.png from PIV analysis
im = imread(file_name);
figure(1)
image(im)
writeVideo(video23, im);
end
close(video23)
implay(video23);
Can someone help me? I also have the images saved as Matlab figures, but matlab won't recognize the file format when I try and get it to read the files.
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 9 月 23 日
Have you tried without Archival option?
Anna Clouvel-Gervaiseau
Anna Clouvel-Gervaiseau 2020 年 9 月 23 日
yes, still doesn't work

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

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2020 年 9 月 23 日
Try modifying your call to writeVideo to this:
currFrame = getframe(gcf);
writeVideo(vidObj,currFrame);
HTH
  2 件のコメント
Anna Clouvel-Gervaiseau
Anna Clouvel-Gervaiseau 2020 年 9 月 23 日
Thanks for the answer! I get the following error message :
"Error using VideoWriter/writeVideo (line 368)
Frame must be 1120 by 840"
Also, for some reason the currFrame cdata has dimensions of 840x1120x3, and that seems strange - its been the same whenever I read the images previously.
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 9 月 23 日
That is strange. (unless you happened to resize your figure-window, since in this version the getframe call captures the entire figure and then you try to write that frame to the avi-file. That must not change size from frame to frame...)
You can try to simply check the sizes of all frames:
for i1 = 1:87
file_name = [baseN,d,num2str(i1),f,num2str(i1+1),d,e];
%VectorOverlay_1-2_Individual.png from PIV analysis
im = imread(file_name);
figure(1)
image(im)
currFrame = getframe(gcf);
% writeVideo(vidObj,currFrame);
szCF = size(currFrame);
frame_sz(i1,1:numel(szCF)) = szCF;
end
Then you can check that the frame-size doesn't change through the loop.
HTH

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by