Used getframe command to create video, but get empty file
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ruming Zhen
el 21 de Oct. de 2016
Editada: Gowtham Uma M Jaganathan
el 27 de Oct. de 2016
Hi,
I am using getframe command to create a video, but got an empty file in the end.
Could anyone help me with this?
Thanks! Ruming
Here attached is the matlab script that I used:
for j = 1:a_w
for i = 1:b_w
array_2_with_diff(1, i) = Data_with_diff(j, i);
end
p = scatter(array_x_axis(1,:),array_2_with_diff(1,:),'o');
h = plot(array_x_axis(1,:),array_2_with_diff(1,:),'g');
drawnow;
F(i) = getframe(gcf);
pause(0.01);
delete(p);
delete(h);
end
video = VideoWriter('With_diff_movie.avi', 'Uncompressed AVI');
video.FrameRate = 60;
open(video);
writeVideo(video, F);
close(video);
0 comentarios
Respuesta aceptada
Gowtham Uma M Jaganathan
el 26 de Oct. de 2016
Editada: Gowtham Uma M Jaganathan
el 27 de Oct. de 2016
I understand that you are getting an empty video file after using “VideoWriter” function.
You can try opening the file within MATLAB and check if the file has any data in it? If it has, then try opening the video with some other media player that you have installed in your system.
If you are not able to view the video in media player, you can use MATLAB’s in-built “implay” function to play the video. Refer to the documentation link below for more details on “implay”.
The issue that you are facing could be because of codec not being installed. You can check if you have one installed in your machine.
You can also try saving your file in a different format other than AVI, such as MPEG and check if that works.
Since, the code you have provided has dependency on other variables, I have created a sample snippet (similar to your code) and executed it in MATLAB. An AVI file was created successfully.
Here is the code snippet that I have used:
for k = 1:100;
p = scatter(rand(5,1), rand(5,1));
h = plot(rand(4));
drawnow;
frame(k) = getframe(gcf);
delete(h);
delete(p);
end
video = VideoWriter('teset.avi', 'Uncompressed AVI');
video.FrameRate = 60;
open(video)
writeVideo(video, frame);
close(video);
Note: I have tested this code in MATLAB R2012b, R2014b, R2016a and R2016b
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!