% This function takes the avi filename as input and detect hard cuts.

function []=shot_detection(aviFileName)
% extact frames from video and output them as bmp files
movieObj = aviread(aviFileName);
noOfFrameImages = size(movieObj,2);

for count=1:1:noOfFrameImages
    imageFileNamePrefix = 'framedump_';
    
    fileName = strcat(imageFileNamePrefix,num2str(count),'.bmp');
    imwrite(movieObj(count).cdata,fileName,'bmp');    
end

% calculate fetures values based on histogram dissimilarity
featureHist = getHistogramFeature(imageFileNamePrefix, noOfFrameImages);

% calculate fetures values based on ECR
featureEucli = getEucFeature(imageFileNamePrefix, noOfFrameImages);

% detect hard cuts use adaptive threshold
cutHist = cutDetect(featureHist);
cutEucli = cutDetect(featureEucli);

% plot the result
figure; plot(featureHist(:,1),featureHist(:,2)); 
xlabel('Frame Number'); ylabel('Histogram Feature Value'); 


figure; plot(featureEucli(:,1),featureEucli(:,2)); 
xlabel('Frame Number'); ylabel('Euclidean Feature Value'); 


save result.mat
return;
