Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I'm extracting frames of selected events from an avi file (5 GB). The way I did it is saving all frames as images, creating avi after that. Worked with few events, more events now. Can I store frames in workspace (as array), then create avi?

1 回表示 (過去 30 日間)
S.Wijn
S.Wijn 2015 年 8 月 19 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
numArrays = numel(FrameNumbersEvents); %assign variable to different green water events
A = cell(numArrays,1);
for n = 1:numArrays;
A{n} =FrameNumbersEvents(n);
end
for k = (cell2mat(A(1))-15) : (cell2mat(A(1))+15);
this_frame = read(obj, k);
thisfig = figure();
thisax = axes('Parent', thisfig);
image(this_frame, 'Parent', thisax);
title(thisax, sprintf('Frame #%d', k));
end
for i=1:2
saveas(figure(i),fullfile('C:\Users\syward.vanwijnbergen\Desktop\Model test analysis\Frames from videos\Video 003_001',['EventFrame' num2str((i-1)) '.jpg']));
end
clear this_frame
clear thisax
for i=4:30
saveas(figure(i),fullfile('C:\Users\syward.vanwijnbergen\Desktop\Model test analysis\Frames from videos\Video 003_001',['EventFrame' num2str((i-1)) '.jpg']));
end

回答 (2 件)

Dasharath Gulvady
Dasharath Gulvady 2015 年 8 月 21 日
I assume you are using "VideoWriter" to create an avi file from the images. I understand that you would like to not convert the frames to the image files, instead use the frames directly to create an avi file.
You can achieve this by using "getframe" function first to get the frames, store them in the workspace and then pass it to "writeVideo" function. Refer to the below documentation page example which shows this:

Image Analyst
Image Analyst 2015 年 8 月 21 日
See my attached demo. It starts with an avi file, then writes out all the individual frames to disk. The it preallocates a cell array for all the frames (like you want). Then it writes out the individual frames to a new video in the loop over frames. If you want, you could move the writeVideo() out of the loop and write the whole video in one shot. Feel free to adapt this demo.

Community Treasure Hunt

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

Start Hunting!

Translated by