How to speed up a script writing frames using a 'VideoWriter' object?

조회 수: 10 (최근 30일)
I am writing a script involving capturing frames of a figure window using the 'getframe' function, and writing each frame using a 'VideoWriter' object to a file.
However, this is quite a slow process if I have many frames to acquire and write. How can I speed it up?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 3월 15일
If many calls to 'getframe' are occurring in succession, it is more efficient to avoid calling the 'writeVideo' function every time a new frame is to be written.
Instead, try using the 'repmat' function to pre-initialize a data structure containing a series of video frame structs returned by 'getframe', and write them all to the file at once using 'writeVideo', like so:
 
>> frameArray = repmat(getframe(figure), 100, 1)
frameArray =
100×1 struct array with fields:
cdata
colormap
This will minimize the amount of calls to the 'writeVideo' function, as well pre-allocate as much space as is needed to store the frames.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by