/usr/share/psychtoolbox-3/PsychDemos/MovieDemos/PlayDualMoviesDemo.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | function PlayDualMoviesDemo(moviename)
%
% PlayDualMoviesDemo(moviename)
%
% This demo accepts a pattern for a valid moviename, e.g.,
% moviename='*.mpg', then it plays all movies in the current working
% directory whose names match the provided pattern, e.g., the '*.mpg'
% pattern would play all MPEG files in the current directory.
%
% This demo uses automatic asynchronous playback for synchronized playback
% of video and sound. Each movie plays until end, then rewinds and plays
% again from the start. Pressing the Cursor-Up/Down key pauses/unpauses the
% movie and increases/decreases playback rate.
% The left- right arrow keys jump in 1 seconds steps. SPACE jumps to the
% next movie in the list. ESC ends the demo.
%
% History:
% 10/30/05 mk Wrote it.
% 06/17/13 mk Cleanup.
if nargin < 1
moviename = '*.mov';
end;
% Switch KbName into unified mode: It will use the names of the OS-X
% platform on all platforms in order to make this script portable:
KbName('UnifyKeyNames');
space=KbName('SPACE');
esc=KbName('ESCAPE');
right=KbName('RightArrow');
left=KbName('LeftArrow');
up=KbName('UpArrow');
down=KbName('DownArrow');
shift=KbName('RightShift');
try
% Child protection
AssertOpenGL;
% Grey background:
background=[128, 128, 128];
% Open onscreen window:
screen=max(Screen('Screens'));
win = Screen('OpenWindow', screen, background);
% Initial display and sync retrace:
Screen('Flip',win);
iteration=0;
abortit=0;
% Return full list of movie files from directory+pattern:
moviefiles=dir(moviename);
for i=1:size(moviefiles,1)
moviefiles(i).name = [ pwd filesep moviefiles(i).name ];
end
% Endless loop, runs until ESC key pressed:
while (abortit<2)
iteration=iteration + 1;
moviename=moviefiles(mod(iteration, size(moviefiles,1))+1).name;
moviename2=moviefiles(mod(iteration+1, size(moviefiles,1))+1).name;
% Open movie file and retrieve basic info about movie:
[movie movieduration fps imgw imgh] = Screen('OpenMovie', win, moviename);
fprintf('Movie1: %s : %f seconds duration, %f fps...\n', moviename, movieduration, fps);
rect1=SetRect(1,1,imgw,imgh);
% Open 2nd movie file and retrieve basic info about movie:
[movie2 movieduration fps imgw imgh] = Screen('OpenMovie', win, moviename2);
fprintf('Movie2: %s : %f seconds duration, %f fps...\n', moviename2, movieduration, fps);
rect2=SetRect(1,1,imgw,imgh);
rect2=AdjoinRect(rect2, rect1, RectRight);
i=0;
% Seek to start of movies (timeindex 0):
Screen('SetMovieTimeIndex', movie, 0);
Screen('SetMovieTimeIndex', movie2, 0);
rate=1;
% Start playback of movies. This will start
% the realtime playback clock and playback of audio tracks, if any.
% Play 'movie', at a playbackrate = 1, with endless loop=1 and
% 1.0 == 100% audio volume.
Screen('PlayMovie', movie, rate, 1, 1.0);
Screen('PlayMovie', movie2, rate, 1, 1.0);
t1 = GetSecs;
% Infinite playback loop: Fetch video frames and display them...
while(1)
i=i+1;
if (abs(rate)>0)
% Return next frame in movie, in sync with current playback
% time and sound.
% tex either the texture handle or zero if no new frame is
% ready yet.
tex = Screen('GetMovieImage', win, movie, 1);
tex2 = Screen('GetMovieImage', win, movie2, 1);
% Valid texture returned?
if tex>0
% Draw the new texture immediately to screen:
Screen('DrawTexture', win, tex, [], rect1);
% Release texture:
Screen('Close', tex);
end;
% Valid 2nd texture returned?
if tex2>0
% Draw the new texture immediately to screen:
Screen('DrawTexture', win, tex2, [], rect2);
% Release texture:
Screen('Close', tex2);
end;
% Update display if there is anything to update:
if (tex>0 || tex2>0)
% We use clearmode=1, aka don't clear on flip. This is
% needed to avoid flicker...
Screen('Flip', win, 0, 1);
end;
end;
% Check for abortion:
abortit=0;
[keyIsDown,secs,keyCode]=KbCheck; %#ok<ASGLU>
if (keyIsDown==1 && keyCode(esc))
% Set the abort-demo flag.
abortit=2;
break;
end;
if (keyIsDown==1 && keyCode(space))
% Exit while-loop: This will load the next movie...
break;
end;
if (keyIsDown==1 && keyCode(right))
% Advance movietime by one second:
Screen('SetMovieTimeIndex', movie, Screen('GetMovieTimeIndex', movie) + 1);
Screen('SetMovieTimeIndex', movie2, Screen('GetMovieTimeIndex', movie2) + 1);
end;
if (keyIsDown==1 && keyCode(left))
% Rewind movietime by one second:
Screen('SetMovieTimeIndex', movie, Screen('GetMovieTimeIndex', movie) - 1);
Screen('SetMovieTimeIndex', movie2, Screen('GetMovieTimeIndex', movie2) - 1);
end;
if (keyIsDown==1 && keyCode(up))
% Increase playback rate by 1 unit.
KbReleaseWait;
if (keyCode(shift))
rate=rate+0.1;
else
rate=round(rate+1);
end;
Screen('PlayMovie', movie, rate, 1, 1.0);
Screen('PlayMovie', movie2, rate, 1, 1.0);
end;
if (keyIsDown==1 && keyCode(down))
% Decrease playback rate by 1 unit.
KbReleaseWait;
if (keyCode(shift))
rate=rate-0.1;
else
rate=round(rate-1);
end;
Screen('PlayMovie', movie, rate, 1, 1.0);
Screen('PlayMovie', movie2, rate, 1, 1.0);
end;
end;
fprintf('Elapsed time %f secs, count %i.\n', GetSecs - t1, i);
Screen('Flip', win);
Screen('Flip', win);
% Wait for all keys released:
KbReleaseWait;
% Done. Stop playback:
Screen('PlayMovie', movie, 0);
Screen('PlayMovie', movie2, 0);
% Close movie objects:
Screen('CloseMovie', movie);
Screen('CloseMovie', movie2);
end;
% Close screens.
Screen('CloseAll');
% Done.
return;
catch %#ok<CTCH>
% Error handling: Close all windows and movies, release all ressources.
Screen('CloseAll');
end
|