我尝试使用此代码提取某些视频的所有帧(每个帧包含大约13000帧),但是提取所有帧需要太长时间。还有更快捷的方法吗?
filename = 'S.avi';
mov = VideoReader(filename);
% Output folder
outputFolder = fullfile(cd, 'S');
mkdir(outputFolder);
%getting no of frames
framee=100000;
numberOfFrames = mov.NumberOfFrames;
numberOfFramesWritten = 0;
for frame = 1:12525
thisFrame = read(mov, frame);
framee=framee+1;
outputBaseFileName = sprintf('%3.3d.png', framee);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite(thisFrame, outputFullFileName, 'png');
% progressIndication = sprintf('Wrote frame %4d of %d.', frame,numberOfFrames);
% disp(progressIndication);
numberOfFramesWritten = numberOfFramesWritten + 1;
end
progressIndication = sprintf('Wrote %d frames to folder "%s"',numberOfFramesWritten, outputFolder);
disp(progressIndication);
答案 0 :(得分:0)
从概念上讲,这与你正在做的事情并没有太大的不同,但你的代码中有许多迂回的步骤。
大概你可以这样做:
mov = VideoReader(filename);
vidFrames = read(mov);
要将电影收集为4D阵列,然后执行
for frame = 1 : size(vidFrames, 4)
outputBaseFileName = sprintf('%3.3d.png', frame);
outputFullFileName = fullfile(outputFolder, outputBaseFileName);
imwrite( vidFrames(:,:,:,frame), outputFullFileName, 'png');
end
它可能会更快。此外,您可以使用parfor
(或spmd
代替计数器函数句柄)来进一步并行化