フィルターのクリア

Using VideoWriter for imagesc

84 ビュー (過去 30 日間)
Frederik Faye
Frederik Faye 2016 年 2 月 2 日
コメント済み: Walter Roberson 2019 年 9 月 19 日
I would like to make a movie based on imagesc(M), where M is a matrix that changes with t in a loop. Of course, any other solution that outputs a video file with the frames of what is shown by imagesc would also be fine. Here's what I have:
%looping over t
h = imagesc(M);
axis off
refreshdata(h,'caller')
drawnow
F(t) = getframe(gcf);
%outside loop
v = VideoWriter('newfile.avi','Archival');
v.FrameRate = 60;
open(v)
writeVideo(v,F)
close(v)
However, I get the warning:
Warning: No video frames were written to this file. The file may be invalid.
> In VideoWriter/close (line 267)
In VideoWriter/delete (line 202)
In Untitled (line 44)
Error using VideoWriter/writeVideo (line 369)
The 'cdata' field of FRAME must not be empty
Error in Untitled (line 47)
writeVideo(v,F)
Thanks!
  1 件のコメント
Varshini Guddanti
Varshini Guddanti 2016 年 7 月 7 日
編集済み: Walter Roberson 2016 年 7 月 7 日
I tried to change the order of your code. Please try this:
% outside loop
v = VideoWriter('newfile.avi','Archival');
v.FrameRate = 60;
open(v)
.
% inside loop
.
%looping over t
h = imagesc(M);
axis off
refreshdata(h,'caller')
drawnow
F(t) = getframe(gcf);
writeVideo(v,F)
% close loop
.
% outside loop
close(v)

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 7 月 7 日
Is it possible that you store one final frame after the end of the t loop, and that final frame is empty? Or alternately, that you store an empty initial frame?
For debugging, add this before the VideoWriter:
all_valid = true;
flen = length(F);
for K = 1 : flen
if isempty(F(K).cdata)
all_valid = false;
fprint('Empty frame occurred at frame #%d of %d\n', K, flen);
end
end
if ~all_valid
error('Did not write movie because of empty frames')
end
  2 件のコメント
Daniele Bernardo Panaro
Daniele Bernardo Panaro 2019 年 9 月 19 日
Hello I have a similar problem. Using your debugging code (adapting it to my code) it gives me the message
'Empty frame occurred at frame #1 of 1139
Error using UP_MGL_1_2 (line 239)
Did not write movie because of empty frames'
How do I fix the empty frame?
Thank you
Walter Roberson
Walter Roberson 2019 年 9 月 19 日
I notice that only the first frame is empty, not the others. That hints that you might have an off-by-one error in the logic of how you store the frames. Could you show us the code you use to initialize your frame array, and how you update it?

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by