Why does MPEG-4 video generated by VideoWriter have flickered frames?
조회 수: 50 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 10월 16일
답변: MathWorks Support Team
2020년 10월 16일
I create an animation which uses "xline" command.
When I generated the video(.mp4), the "xline" line flickered in Window Media Player.
figure
t = linspace(0,10,1000);
y = randn(size(t));
plot(t,y)
hold on
h_x = xline(t(1),'--r');
v = VideoWriter('newfile.mp4','MPEG-4');
v.Quality = 100;
v.FrameRate = 10;
open(v)
for n = 1:length(t)
h_x.Value = t(n);
drawnow limitrate
frame = getframe(gcf);
writeVideo(v,frame);
end
close(v)
채택된 답변
MathWorks Support Team
2020년 10월 16일
The issue was with the resolution of the generated image. As the compression increases from AVI to MPEG-4, the quality drops.
You can see the AVI has better quality than MPEG-4.
v = VideoWriter('newfile.avi','Uncompressed AVI');
% v = VideoWriter('newfile.mp4','MPEG-4');
% v.Quality = 100;
% v.FrameRate = 10;
This drop in quality due to increased compression needs to be compensated by increasing the resolution of the generated figures (or frames).\n
close all, clear all
figure('units','pixels','position',[0 0 1000 800]) % set figure's size
t = linspace(0,10,1000);
y = randn(size(t));
plot(t,y)
hold on
h_x = xline(t(1),'--r');
v = VideoWriter('newfile.mp4', 'MPEG-4');
v.Quality = 100;
v.FrameRate = 10;
open(v)
for n = 1:length(t)
h_x.Value = t(n);
drawnow limitrate
frame = getframe(gcf);
f = imresize(frame.cdata,4); % resize the image
writeVideo(v,f);
end
close(v)
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!