Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function [] = playbackMovieFFmpegMaker(data,rescaleFactor,cropRegion, movName,destinationFolder,fps,rows,cols,percentage)
% playbackMovieMaker The function imports a 3/4D data matrix, it
% down/upsamples the frame images of original video and saves them into a
% new video file. It uses the videoWriter method of the FFmpegVideoWriter
% object made by Stefano.
% It also automatically saves as images in destination folder a random subset of
% 10% of the frames as still images
iptsetpref('ImshowBorder','tight');
cd(destinationFolder)
sz = size(data);
stillFrames = randi(sz(end),[1 round(percentage*sz(end))]);
stillFrames = unique(stillFrames);
stillCounter = 0;
VW = video.FFmpegVideoWriter(movName, fps, rows, cols, 'quality', 2);
f=figure,
for i = 1:sz(end)
currF = data(:,:,:,i);
if ~isempty(cropRegion)
currF = currF(cropRegion(1,1):cropRegion(2,1),cropRegion(1,2):cropRegion(2,2),:);
end
newF=imresize(currF,rescaleFactor);
% newF = imresize(currF, [rows nan]);
szNew = size(newF);
if rescaleFactor < 1
blank = uint8(zeros(VW.rows, VW.cols,3));
midH = (VW.rows/2 - round(size(newF,1)/2)+300);
midW = (VW.cols/2 - round(size(newF,2)/2));
blank( midH:midH+size(newF,1)-1 , midW:midW+size(newF,2)-1 , :) = newF;
figure(f), imshow(blank)
currFrame = blank;
elseif szNew(1)> rows
newF = imresize(newF, [rows cols]);
currFrame = newF;
figure(f), imshow(currFrame)
elseif rescaleFactor > 1 && szNew(1)< rows-50
blank = uint8(zeros(VW.rows, VW.cols,3));
midH = VW.rows-50-szNew(1);
midW = (VW.cols/2 - round(size(newF,2)/2));
blank( midH:midH+size(newF,1)-1 , midW:midW+size(newF,2)-1 , :) = newF;
figure(f), imshow(blank)
currFrame = blank;
else
blank = uint8(zeros(VW.rows, VW.cols,3));
midH = (VW.rows/2 - round(size(newF,1)/2));
midW = (VW.cols/2 - round(size(newF,2)/2));
blank( midH:midH+size(newF,1)-1 , midW:midW+size(newF,2)-1 , :) = newF;
figure(f), currFrame = blank;
imshow(currFrame)
end
VW.writeFrame(currFrame);
if ismember(i,stillFrames)
stillCounter = stillCounter+1;
IName = movName;
IName = [IName(1:end-4) '_' num2str(stillCounter) '.jpg'];
imwrite(currFrame,IName,'jpg','Mode','lossless','Quality',100,'BitDepth',8)
figure, image(currFrame), title(sprintf('%s_%d',IName,i), 'Interpreter', 'none');
end
end
VW.reset()
end