Is there a way to speed up video writing in matlab? - MATLAB Answers - MATLAB Central

Is there a way to speed up video writing in matlab?

48 views (last 30 days)
I'm having trouble with the performance of video writing. Each frame takes 0.7 seconds to write (considering only the writeVideo function). Is there a way to speed up this process?
v = VideoWriter('video.avi');
v.FrameRate = 4;
open(v)
set(gcf,'units','normalized','outerposition',[0 0 1 1])
for i = 1:100
imshow(I)
frame = getframe(figHand);
writeVideo(v,frame);
end

Answers (1)

Walter Roberson
Walter Roberson on 18 Jan 2018
imshow() is slow. Avoid continually calling it.
v = VideoWriter('video.avi');
v.FrameRate = 4;
open(v)
set(gcf,'units','normalized','outerposition',[0 0 1 1])
for i = 1:100
if i == 1;
h = imshow(I);
else
set(h, 'CData', I);
end
frame = getframe(figHand);
writeVideo(v,frame);
end
  2 Comments
rafael iriya
rafael iriya on 19 Jan 2018
Edited: rafael iriya on 19 Jan 2018
Hi Walter thanks for replying. Imshow is not the bottleneck it takes around 0.2 seconds, while the writevideo function takes 0.7 seconds.
My code was actually a lot longer, I posted a simplified version but I measured the time for each step and found out the bottleneck is the writeVideo function.
However your solution for imshow is something I've been struggling with for a long time and I'm glad I finally have a solution for it! Thank you very much!
Walter Roberson
Walter Roberson on 19 Jan 2018
I wonder if it would be more efficient to batch the write calls? Gather several frames into a structure array and writeVideo that ?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!