writeVideo records double the first frame and doesn't play last frame in VLS

6 ビュー (過去 30 日間)
Vitek Stepien
Vitek Stepien 2024 年 12 月 16 日
コメント済み: Vitek Stepien 2024 年 12 月 30 日
Hi everyone,
I'm using writeVideo to save a simple animation. However I encounter two annoying problems: for one, the first frame is shown for two seconds in VLC, for a frame rate of 1 which works properly for other frames. Secondly, VLC stops playback at the second-to-last frame. I can manually drag it to the last frame, but that's not the point. Any ideas? See code below.
vidcounter = counter();
vid = VideoWriter("visualization test.mp4","MPEG-4");
vid.FrameRate = 1;
open(vid)
fig = figure;
fig.Position = [0 60 800 600];
tlo = tiledlayout(2,2,"TileSpacing","compact",Parent=fig);
set(fig,"Visible","on")
for CN = 1:5 % Loop through folders (Linewidths)
p1 = nexttile(tlo, 1);
surf(rand(5),'EdgeColor','none')
p2 = nexttile(tlo, 2);
surf(rand(5),'EdgeColor','none')
p3 = nexttile(tlo, 3);
surf(rand(5),'EdgeColor','none')
p4 = nexttile(tlo, 4);
surf(rand(5),'EdgeColor','none')
frame = getframe(fig)
writeVideo(vid, frame)
vidcounter.countUp;
end
% writeVideo(vid, frame) % I can circumvent the second issue by duplicating
% the last frame, but it's not a real solution
close(vid)
  2 件のコメント
Gayathri
Gayathri 2024 年 12 月 23 日
The video plays correctly in other video players, so the provided code appears to be fine.
Vitek Stepien
Vitek Stepien 2024 年 12 月 30 日
Thanks for the feedback @Gayathri, I confess I didn't check any other players.

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

回答 (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