function [srcFolder, imageName] = video2Image(videoFile,note,date_now)
%*******************************************************************
%This function reads in video file and break it down to frames.
%Input variables: video file with property extension
%Output variables: srcFolder--directory for breakdown images
%                  imageName--a cell array contain names for individual
%                             frame.
%**************************************************************************
% Modified by Kaichang CHENG in Mar. 6, 2019.
% 1. Add a parameter,note,making the procedure to be compatible with system
%    operation (Windows or Linux).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
idx = 1;
%Get the total number for frame using frame rate and duration to
%pre-allocate a cell array for image names.
vidTemp = VideoReader(videoFile);
numFrames = ceil(vidTemp.FrameRate*vidTemp.Duration);
imageName = cell(1, numFrames);

%Get the directory, filename for video file.
%The directory name and file name will be used create a new folder for
%individual frames.
[videoFolder, tempName, ~] = fileparts(videoFile);
srcFolder = strcat(videoFolder, [note tempName '_Frames_' date_now]);
if ~exist(srcFolder,'dir')
    mkdir(srcFolder);
end

%Break down and save individual frame.
while hasFrame(vidTemp)
    img = readFrame(vidTemp);
    fileName = [tempName sprintf('_%05d', idx) '.bmp'];
    fullName = fullfile(srcFolder, fileName);
    imwrite(img,fullName)% Write out to a JPEG file (img1.jpg, img2.jpg, etc.)
    imageName{idx} = fileName;
    idx = idx+1;
end
end