Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

movie2struct.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. function movie2struct(vo, stime, etime, varargin)
  2. % movie2struct(vo, stime, etime, [inc_t,save_str])
  3. % Inputs:
  4. % vo a video reader object (from output of VideoReader)
  5. % stime a list of times in seconds from beginning of video
  6. % etime a list of times in seconds from beginning of video (same length
  7. % as stime
  8. % Optional Inputs
  9. % inc_t a logical vector the same length as stime which indicates that
  10. % the trial should be extracted. Default: All Trials
  11. % save_str the file name prefix to append to each file. Default the movie
  12. % file name
  13. %
  14. % Output:
  15. % Writes n files to disk (where n is sum of inc_t). The ith file contains
  16. % the frames from stime(i) to etime(i) as a single uint8 matrix of size [height width n_frames 3].
  17. pairs={'save_str',[];...
  18. 'inc_t',[];...
  19. };
  20. parseargs(varargin, pairs);
  21. if isempty(save_str)
  22. save_str=vo.Name;
  23. di=find(save_str=='.');
  24. save_str=save_str(1:di-1);
  25. end
  26. if isempty(inc_t)
  27. inc_t=ones(size(stime));
  28. end
  29. fr=vo.FrameRate;
  30. tot_f=vo.NumberOfFrames;
  31. %get an extra 100 ms at the beginning and end
  32. for tx=1:numel(stime)
  33. t_s_str=sprintf('%s_%d.mat',save_str,tx);
  34. if ~inc_t(tx)
  35. continue;
  36. end
  37. if exist(t_s_str,'file')
  38. fprintf('File exists for trial %d, skipping\n',tx);
  39. end
  40. % This is the right thing to do, but it gives the wrong answer. GRR
  41. f_s=floor(stime(tx)*fr);
  42. f_e=ceil(etime(tx)*fr);
  43. if f_e>tot_f
  44. fprintf('Video is shorten than session. Written first %d trials\n',tx);
  45. return;
  46. end
  47. % f_s=floor(stime(tx)*30);
  48. % f_e=ceil(etime(tx)*30);
  49. fprintf('Reading %d frames for trial %d\n',f_e-f_s,tx);
  50. m=read(vo, [f_s f_e]);
  51. start_time=stime(tx);
  52. end_time=etime(tx);
  53. save(t_s_str,'m','start_time','end_time','f_s','f_e');
  54. fprintf('\tTrial %d/%d done\n',tx,numel(stime));
  55. clear m t_m
  56. end