Permalink
Cannot retrieve contributors at this time
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?
VisualStimulationAle/scriptPlaybackMovieMaker.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
158 lines (86 sloc)
2.89 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Make videos for playback | |
%% INPUT DATA | |
start_path = '\\storage.laur.corp.brain.mpg.de\Data_3\CoattiAlex'; %'/storage/laur/Data3/CoattiAlex'; | |
disp('GO TO FOLDER WITH VIDEOS FOR PLAYBACK: '); | |
data_folder = uigetdir(start_path); | |
cd(data_folder) | |
myVid = 'Video 9.mp4'; | |
myReader = video.FFmpegVideoReader(myVid, false); | |
%% FIND START FRAME AND READ FIRST n FRAMES; MAKE ANIMATION | |
startTime = 1.25 % seconds from start of video | |
startTime = minToSeconds(startTime); | |
startFrame = floor(startTime * myReader.fps*2); | |
% startFrame = 0.41; | |
endTime = 4.00; % seconds from start of video | |
endTime = minToSeconds(endTime); | |
endFrame = ceil(endTime * myReader.fps*2); | |
% endFrame = myReader.numFrames | |
format = 'uint8'; % format of input video data | |
nFrames = round(endFrame-startFrame); %endFrame-startFrame; | |
if myReader.isGreyscale | |
videoData = zeros([myReader.rows myReader.cols nFrames],format); | |
else | |
videoData = zeros([myReader.rows myReader.cols 3 nFrames],format); | |
end | |
% seek starting frame | |
close all, figure, | |
[frame, success] = myReader.seekFrame( startFrame ); | |
success | |
videoData(:,:,:,1) = frame; | |
image(frame),pause(0.01) | |
% check format conversion | |
switch class(frame) | |
case format | |
otherwise | |
videoData = cast(videoData,'like',frame); | |
end | |
for k = 2:nFrames %myReader.numFrames | |
frame = myReader.readFrame(); | |
videoData(:,:,:,k) = frame; | |
pause(0.001) | |
image(frame) | |
k | |
end | |
%% Manually crop video | |
close all | |
figure, image(videoData(:,:,:,1)) | |
figure, image(videoData(:,:,:,2480)) | |
close all | |
videoData1 = videoData(200:1080,1:1600,:,1:2500); | |
szVideo = size(videoData1) | |
videoData1 = videoData1(200:1080,1:1600,:,1:2500); | |
szVideo = size(videoData1) | |
% | |
% videoData1 = cat(4,videoData1,repmat(videoData1(:,:,:,end),1,1,1,30)); | |
% szVideo = size(videoData1) | |
% play it | |
close all, figure; | |
for k = 1:szVideo(end) | |
frame = videoData1(:,:,:,k); | |
pause(0.0005) | |
image(frame) | |
k | |
end | |
% get pixel distance from image | |
close, figure, image(videoData1(:,:,:,50)) | |
h = imdistline(gca); | |
api = iptgetapi(h); | |
%% GET SCALING FACTOR FOR IMAGES | |
sizeImagePxl = 8/59; % mm/pxl (8 mm ear hole length for males, 7.5 mm for females) | |
sizeScreenPxl = 0.5; % mm/pxl | |
rescaleFactor = sizeImagePxl/sizeScreenPxl %0.5 for lizard 176(male); 0.68 for lizard female1 (2016/06/29) | |
%% CREATE NEW VIDEO FILE FOR PLAYBACK | |
close all | |
movName = 'DisplayMale008.avi'; | |
destinationFolder = '\\storage.laur.corp.brain.mpg.de\Data_3\CoattiAlex\Lizard_behavior\Videos\conspecifics'; | |
dataIn = videoData1; | |
fps = myReader.fps; | |
rows = 1080; | |
cols = 1920; | |
percentage = 0.01; % percentage of still frames saved | |
% cropRegion = [181 size(videoData2,1); 367 size(videoData2,2) ]'; %(deltaY,deltaX) | |
cropRegion = [ ]; %(deltaY,deltaX) | |
playbackMovieFFmpegMaker(dataIn,rescaleFactor,cropRegion,movName,destinationFolder,fps,rows,cols,percentage); | |
%% clear videoData | |
clear videoData1 videoData2 videoData | |
clear myReader | |