How to speed up a script writing frames using a 'VideoWriter' object?
조회 수: 10 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2023년 3월 15일
답변: MathWorks Support Team
2023년 3월 15일
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!