Borrar filtros
Borrar filtros

Using VideoWriter for imagesc

85 visualizaciones (últimos 30 días)
Frederik Faye
Frederik Faye el 2 de Feb. de 2016
Comentada: Walter Roberson el 19 de Sept. de 2019
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 comentario
Varshini Guddanti
Varshini Guddanti el 7 de Jul. de 2016
Editada: Walter Roberson el 7 de Jul. de 2016
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)

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Jul. de 2016
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 comentarios
Daniele Bernardo Panaro
Daniele Bernardo Panaro el 19 de Sept. de 2019
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 el 19 de Sept. de 2019
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?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by