How to speed up a script writing frames using a 'VideoWriter' object?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 15 Mar 2023
Réponse apportée : MathWorks Support Team
le 15 Mar 2023
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?
Réponse acceptée
MathWorks Support Team
le 15 Mar 2023
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!