Filter löschen
Filter löschen

How to fast process conversion of .tif image sequence to an .avi video

34 Ansichten (letzte 30 Tage)
I wrote a code to automatically convert a large sequence of .tif files to .avi videos across multiple folders. In general I have 110000 tif files per folder and 11 folders that go through the processing. The result is 5 videos per folder in which each video consist of 110000/5=22000 frames.
So far so good, however, for this to happen it takes almost 48 hours (2 DAYS) of matlab running continuously!
Any recommendation on how to make this faster? The tif file size is small about 200x200, I use for loops and imread to read the tif files and VideoWriter to convert it. Here is a sample of my code
for SubSession=1:number_of_frames/5:number_of_frames
%%Process File
MovieFrame_Order=1;
for FrameID=SubSession:SubSession+(number_of_frames/5)-1
fullFileName=fullfile(thisFolder,baseFileNames{FrameID}); %fullfile(thisFolder, baseFileNames(Trials));
AllOtherFrames = imread(strcat(fullFileName)); % load images from tif and convert to double
EBC_Frame_movie(:,:,MovieFrame_Order)=AllOtherFrames;
MovieFrame_Order=MovieFrame_Order+1;
end
%% Create Sub_Session video
newVid = VideoWriter([strcat(pwd,'/DATAfolder/',Title_movie,'.avi')]); % save new movie
newVid.FrameRate = 200;
newVid.Quality = 100;
open(newVid)
for t = 1:size(EBC_Frame_movie,3)
figure(1)
imshow(EBC_Frame_movie(:,:,t),'Border','tight');
axis off;
axis equal
EBC_movie_Output = getframe(figure(1));
writeVideo(newVid,EBC_movie_Output) % saving one frame at a time to make the movie
end
close(newVid)

Akzeptierte Antwort

Image Analyst
Image Analyst am 19 Nov. 2021
It will be a lot faster if you don't display anything. So don't call imshow(), figure(), axis(), etc.
Also I don't see any advantage to storing all the frames in a structure first. Just call imread() and then writeVideo immediately.
Looks like your code is missing an "end" statement. Also the indenting is messed up. You can type control-a (to select all) then control-i (to fix indenting) in the MATLAB editor. Then copy and paste here and the indenting should be okay then.
  3 Kommentare
Image Analyst
Image Analyst am 19 Nov. 2021
Probably because you were still calling getframe() which requires an image.
I'm attaching a similar (I think) demo that may help. In the demo it reads files from disk and writes a video.
Lina Koronfel
Lina Koronfel am 9 Feb. 2022
Thanks alot for the answer. I removed the object display and the storage matrix as you suggested and now it is running much faster!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by