Avi produced using writeVideo is clipped.

10 ビュー (過去 30 日間)
David
David 2025 年 3 月 13 日
コメント済み: David 2025 年 3 月 14 日
A structure generated with multiple getframe commands within a for loop displays correctly when using a movie command within Matlab, The avi produced using writeVideo is clipped outside the axes of the 2D plot.
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 3 月 13 日
Do you happen to be using MATLAB on a Mac Silicon ?
David
David 2025 年 3 月 13 日
移動済み: Voss 2025 年 3 月 13 日
No, just a windows PC

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

採用された回答

DGM
DGM 2025 年 3 月 14 日
編集済み: DGM 2025 年 3 月 14 日
I think I see what's going on here, and it is easily misleading. I assume that this example will replicate the effect you're seeing.
You capture some frames and then you view the result using movie():
nframes = 10;
x = linspace(100,200,10); % note the span of x and y are 100-200
for k = 1:nframes
y = 100*rand(10,1) + 100; % some fake data
if k == 1
hp = plot(x,y);
else
hp.YData = y;
end
S(k) = getframe(gca);
end
movie(S)
Obviously, I can't really run movie() here, but at least this static frame should be what you'd expect from the call to movie -- it looks just like it did when the frames were being plotted and captured. You then write the captured frames to disk, and all of a sudden, the plot box and ticklabels are gone.
vidObj = VideoWriter('blah.avi');
open(vidObj);
for k = 1:numel(S)
thisframe = S(k);
writeVideo(vidObj,thisframe);
end
close(vidObj);
In order to see what's going on, we can make one simple change. Before calling movie(), let's clear the figure.
clf
movie(S)
Notice that the x and y axes now only span the unit interval. What's happening is that movie() is simply inheriting whatever the prior XLim, YLim are from when the axes was last used. If we clear the figure, it just uses [0 1] as the default. So when you run movie(), you actually are seeing that the frames are cropped as the AVI file shows. The tick labels aren't part of the captured frames. They're just left over from plotting.
The way to fix the issue should be to capture the parent figure instead of just the axes in the call to getframe(), something like:
S(k) = getframe(gcf); % capture the figure, not just the axes
... or whatever figure handle refers to the intended target.
  1 件のコメント
David
David 2025 年 3 月 14 日
This worked. Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by