-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetFrames.m
46 lines (38 loc) · 1.31 KB
/
GetFrames.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function GetFrames(inputPath,outputPath)
%-------------------------------------------------------------------------
%
% GetFrames(inputPath,outputPath)
%
% Description: Function to deconstruct .avi files into composite frames.
%
% Inputs:
% inputPath - location of .avi files e.g. ('X:\user\Video_data')
% outputPath - location to save output .jpg files e.g. ('X:\user\Frames')
%
% Outputs:
% Frames stored in outputPath.
%
% Author:
% Louise Wilson
% Leigh Marine Lab, University of Auckland
% Auckland, New Zealand
%--------------------------------------------------------------------------
d=dir(fullfile(inputPath, '*.avi'));
fileCount=length(d);
for j=1:fileCount
vidfile=d(j).name;
getdate=strsplit(d(j).date);
thedate=getdate(1);
formatOut='yyyymmdd';
filedate=datestr(thedate, formatOut);
videoObject=VideoReader(fullfile(inputPath,vidfile));
numberOfFrames = videoObject.NumberOfFrames;
vidHeight = videoObject.Height;
vidWidth = videoObject.Width;
for x=1 : numberOfFrames
frame = read(videoObject,x);
outputBaseFileName = sprintf('-%4.4d.jpg', x);
outputFullFileName = fullfile(outputPath, strcat(filedate, outputBaseFileName));
imwrite(frame, outputFullFileName, 'jpg');
end
end