VideoWriter を使ってアニメーションを MPEG-4 として保存すると、画像がチカチカするのはなぜですか?
52 views (last 30 days)
Show older comments
MathWorks Support Team
on 16 Oct 2020
Answered: MathWorks Support Team
on 16 Oct 2020
VideoWriter オブジェクトを使用して、MATLAB のグラフィックスで作成したアニメーションを MPEG-4(.mp4) として保存しています。
作成した動画を Windows Media Player や VLC 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)
Accepted Answer
MathWorks Support Team
on 16 Oct 2020
この現象は、ご利用環境の解像度が getframe 関数での画像キャプチャに影響しているようです。
特に、MPEG-4 への出力では、圧縮がかかるため、影響がより大きく表れてしまうようです。
例えば、下記のように非圧縮の AVI ファイルとして保存すると、画質が改善します。
v = VideoWriter('newfile.avi','Uncompressed AVI');
% v = VideoWriter('newfile.mp4','MPEG-4');
% v.Quality = 100;
% v.FrameRate = 10;
代替案として、できるだけ Figure のサイズを大きくした上で、getframe 関数で取得した画像データを imresize 関数でサイズを大きくする方法が考えられます。
close all, clear all
figure('units','pixels','position',[0 0 1000 800]) % 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);
f = imresize(frame.cdata,4); % 4倍にリスケール
writeVideo(v,f);
end
close(v)
0 Comments
More Answers (0)
See Also
Categories
Find more on オーディオとビデオ in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!