From e975c33d722f5223021ee8b276ed38c574e70980 Mon Sep 17 00:00:00 2001 From: olakiril Date: Tue, 31 May 2016 13:05:10 -0500 Subject: [PATCH] Added movieclip table --- schemas/+psy/MovieClipStore.m | 54 +++++++++++++++++++++++++++++++++++ schemas/+psy/MovieInfo.m | 5 ++-- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 schemas/+psy/MovieClipStore.m diff --git a/schemas/+psy/MovieClipStore.m b/schemas/+psy/MovieClipStore.m new file mode 100644 index 0000000..89efe60 --- /dev/null +++ b/schemas/+psy/MovieClipStore.m @@ -0,0 +1,54 @@ +%{ +psy.MovieClipStore (imported) # clips from movies +-> psy.MovieInfo +clip_number : int # clip index +----- +file_name : varchar(255) # full file name +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 + + 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 diff --git a/schemas/+psy/MovieInfo.m b/schemas/+psy/MovieInfo.m index ad37613..456bc06 100644 --- a/schemas/+psy/MovieInfo.m +++ b/schemas/+psy/MovieInfo.m @@ -3,7 +3,8 @@ movie_name : char(8) # short movie title ----- movie_title : varchar(255) # full movie title -path_template : varchar(255) # filename template with full path +path : varchar(255) # path for movies +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) @@ -15,7 +16,7 @@ methods function fill(self) self.inserti({ - 'MadMax' 'Mad Max: Fury Road (2015)' '~/stimuli/movies/madmax/madmax_%03u.avi' 60 30 255 144 + 'MadMax' 'Mad Max: Fury Road (2015)' '~/stimuli/movies' 'madmax_%03u.avi' 60 30 255 144 }) end end