How to speed up a script writing frames using a 'VideoWriter' object?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 15 de Mzo. de 2023
Respondida: MathWorks Support Team
el 15 de Mzo. de 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?
Respuesta aceptada
MathWorks Support Team
el 15 de Mzo. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Audio and Video Data en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!