From 2cf553035e672da2963ec5c3220777df950ab96a Mon Sep 17 00:00:00 2001 From: olakiril Date: Tue, 31 May 2016 23:36:26 -0500 Subject: [PATCH] New table contains specific movie information & clips are computed within matlab --- schemas/+psy/MovieClipStore.m | 26 +--------- schemas/+psy/MovieInfo.m | 14 +++--- schemas/+psy/MovieParams.m | 91 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 schemas/+psy/MovieParams.m diff --git a/schemas/+psy/MovieClipStore.m b/schemas/+psy/MovieClipStore.m index 89efe60..4bfbf23 100644 --- a/schemas/+psy/MovieClipStore.m +++ b/schemas/+psy/MovieClipStore.m @@ -4,32 +4,10 @@ clip_number : int # clip index ----- file_name : varchar(255) # full file name -clip : longblob # +clip : longblob # %} - -classdef MovieClipStore < dj.Relvar & dj.AutoPopulate - properties - popRel = psy.MovieInfo - end - - methods (Access=protected) - function makeTuples(self,key) - [path,file_temp] = fetch1(psy.MovieInfo & key,'path','file_template'); - clips = dir(fullfile(getLocalPath(path),['*.' file_temp(end-2:end)])); - for iclip = 1:length(clips); - clip_number = sscanf(clips(iclip).name,file_temp); - if isempty(clip_number);continue;end - tuple = key; - tuple.clip_number = clip_number; - tuple.file_name = clips(iclip).name; - fid = fopen(getLocalPath(fullfile(path,tuple.file_name))); - tuple.clip = fread(fid,'*int8'); - fclose(fid); - self.insert(tuple) - end - end - end +classdef MovieClipStore < dj.Relvar methods function filenames = export(obj) diff --git a/schemas/+psy/MovieInfo.m b/schemas/+psy/MovieInfo.m index 456bc06..a4b2165 100644 --- a/schemas/+psy/MovieInfo.m +++ b/schemas/+psy/MovieInfo.m @@ -2,21 +2,23 @@ psy.MovieInfo (manual) # movies used for generating clips and stills movie_name : char(8) # short movie title ----- -movie_title : varchar(255) # full movie title +movie_class : enum('madmax','object3d','mousecam') # movie type path : varchar(255) # path for movies +original_file : varchar(255) # original long movie clip file_template : varchar(255) # filename template with full path file_duration : float # (s) duration of each file (must be equal) -frame_rate : float # frames per second -frame_width : int # (pixels) -frame_height : int # (pixels) +codec : varchar(255) # codec parameters for ffmpeg compression +movie_description : varchar(255) %} - classdef MovieInfo < dj.Relvar methods function fill(self) self.inserti({ - 'MadMax' 'Mad Max: Fury Road (2015)' '~/stimuli/movies' 'madmax_%03u.avi' 60 30 255 144 + 'MadMax' 'madmax' '~/stimuli/movies' ... + 'madmax.avi' 'madmax_%03u.mov' 60 ... + '-c:v libx264 -preset slow -crf 5' ... + 'Mad Max: Fury Road (2015)' }) end end diff --git a/schemas/+psy/MovieParams.m b/schemas/+psy/MovieParams.m new file mode 100644 index 0000000..2c70e1f --- /dev/null +++ b/schemas/+psy/MovieParams.m @@ -0,0 +1,91 @@ +%{ +psy.MovieParams (imported) # clips from movies +-> psy.MovieInfo +----- +frame_rate : float # frames per second +frame_width : int # (pixels) +frame_height : int # (pixels) +params : longblob # movie parameters +%} + + +classdef MovieParams < dj.Relvar & dj.AutoPopulate + properties + popRel = psy.MovieInfo + end + + methods (Access=protected) + function makeTuples(self,key) + [path,file,file_temp,dur,codec] = fetch1(psy.MovieInfo & key,'path','original_file','file_template','file_duration','codec'); + + infile = getLocalPath(fullfile(path,file)); + info = ffmpeginfo(infile); + clip_number = floor(info.duration/dur); + tuple = key; + + % read data file + csvname = [infile(1:end-3) 'csv']; + if exist(csvname,'file') + data = csvread(csvname,1,0); + fileID = fopen(csvname,'r'); + names = textscan(fileID, '%s', 1, 'delimiter', '\n', 'headerlines', 0); + fclose(fileID); + names = textscan(names{1}{1},'%s','delimiter',','); + names = names{1}; + tuple.params = []; + for iname = 1:length(names) + eval(['tuple.params.' names{iname} '=data(:,iname);']); + end + end + + % insert movie info + tuple.frame_rate = info.streams.codec.fps; + tuple.frame_width = info.streams.codec.size(1); + tuple.frame_height = info.streams.codec.size(2); + self.insert(tuple) + + % process & insert clips + for iclip = 1:clip_number + tuple = key; + tuple.clip_number = iclip; + tuple.file_name = sprintf(file_temp,iclip); + if exists(psy.MovieClipStore & tuple);continue;end + + % create file + start = (iclip-1)*dur; + outfile = getLocalPath(fullfile(path,tuple.file_name)); + if ~exist(outfile,'file') + argstr = sprintf('-i %s -ss %d -t %d %s %s',infile,start,dur,codec,outfile); + ffmpegexec(argstr) + end + + % load file & insert + fid = fopen(getLocalPath(fullfile(path,tuple.file_name))); + tuple.clip = fread(fid,'*int8'); + fclose(fid); + insert(psy.MovieClipStore,tuple) + end + end + end + + methods + function filenames = export(obj) + + [file_names,clips] = fetchn(obj,'file_name','clip'); + path = getLocalPath(fetch1(psy.MovieInfo & obj,'path')); + if ~exist(path,'dir');mkdir(path);end + + filenames = cell(length(file_names),1); + for ifile = 1:length(file_names) + filenames{ifile} = fullfile(path,file_names{ifile}); + if exist(filenames{ifile}, 'file');delete(filenames{ifile});end + fid = fopen(filenames{ifile},'w'); + fwrite(fid,clips{ifile},'int8'); + fclose(fid); + end + + if length(filenames)==1; filenames = filenames{1};end + + end + end +end \ No newline at end of file