playing movies with Screen commands

Hi.
I'm trying to play short movies (one or two seconds long) in the
psychtoolbox window as stimuli that participants will watch but I'm
having problems. I'm using a Windows PC and it has Quicktime installed
on it (in case that matters).
At the moment, I can get only a '.mov' movie to work, and I'm
using 'OpenMovie', 'GetMovieIMage' and 'DrawTexture' to work my way
through the short movie. However, the speed with which the textures are
displayed doesn't appear constant. Can this be solved?
Also, there must be a simpler way using 'PlayMovie'? However, I can't
get this to work. It doesn't come up with errors, but it fails to play
the movie. Is this because I'm not on a Mac? It looks like some things
won't work on PCs.
Also, I came across mentions of 'Showtime'. What is this? Can I use
this on a PC? If so, where can I get it?
Thanks in advance for any help you can give me,
Robin.
Showtime was only for MacOS/9. Quicktime movie playback should
work well on MS-Windows, there are only a few specialities that
aren't supported on Win vs. OS/X.

Do your movie(s) work with our Quicktime demos? If yes -> Check
your code. If no, then you're probably trying to play a movie format
that is not supported by your Quicktime installation. Codecs widely
differ in performance, accuracy and speed...

I think the H.263/264 codecs performed very well when we used
them. H.264 e.g. can play two high quality 768x576 or 640x480
PAL/NTSC color movies in parallel at 30 fps without losing sync
or dropping frames -- at least on current hardware.

-mario


--- In psychtoolbox@yahoogroups.com, "remarknibor" <remarknibor@...> wrote:
>
> Hi.
> I'm trying to play short movies (one or two seconds long) in the
> psychtoolbox window as stimuli that participants will watch but I'm
> having problems. I'm using a Windows PC and it has Quicktime installed
> on it (in case that matters).
> At the moment, I can get only a '.mov' movie to work, and I'm
> using 'OpenMovie', 'GetMovieIMage' and 'DrawTexture' to work my way
> through the short movie. However, the speed with which the textures are
> displayed doesn't appear constant. Can this be solved?
> Also, there must be a simpler way using 'PlayMovie'? However, I can't
> get this to work. It doesn't come up with errors, but it fails to play
> the movie. Is this because I'm not on a Mac? It looks like some things
> won't work on PCs.
> Also, I came across mentions of 'Showtime'. What is this? Can I use
> this on a PC? If so, where can I get it?
> Thanks in advance for any help you can give me,
> Robin.
>
Thanks for the help. The Quicktime demos work just fine and I've now
sorted my previous problem. However, I was still wondering:

1. if 'OpenMovie' and the other functions will only work with '.mov'
files. Especially given that Quicktime itself will play other file
types (such as .mp4).

2. why it appears that when I show the movies (by repeatedly drawing
textures to the screen), the speed varies during play. It seems to
start off faster and then slow to a more normal speed. This is
despite the fact that I've already created all the textures
beforehand using 'GetMovieImage'.

3. if, unrelated to the movie playing, one can ask for and record
user input from the Screen. For instance, if I wanted to ask for the
participant's name and age. If this is possible, which functions
should I look to use?

Thanks again for the help,

Robin.


--- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
<mario.kleiner@...> wrote:
>
> Showtime was only for MacOS/9. Quicktime movie playback should
> work well on MS-Windows, there are only a few specialities that
> aren't supported on Win vs. OS/X.
>
> Do your movie(s) work with our Quicktime demos? If yes -> Check
> your code. If no, then you're probably trying to play a movie format
> that is not supported by your Quicktime installation. Codecs widely
> differ in performance, accuracy and speed...
>
> I think the H.263/264 codecs performed very well when we used
> them. H.264 e.g. can play two high quality 768x576 or 640x480
> PAL/NTSC color movies in parallel at 30 fps without losing sync
> or dropping frames -- at least on current hardware.
>
> -mario
>
>
> --- In psychtoolbox@yahoogroups.com, "remarknibor" <remarknibor@>
wrote:
> >
> > Hi.
> > I'm trying to play short movies (one or two seconds long) in the
> > psychtoolbox window as stimuli that participants will watch but
I'm
> > having problems. I'm using a Windows PC and it has Quicktime
installed
> > on it (in case that matters).
> > At the moment, I can get only a '.mov' movie to work, and I'm
> > using 'OpenMovie', 'GetMovieIMage' and 'DrawTexture' to work my
way
> > through the short movie. However, the speed with which the
textures are
> > displayed doesn't appear constant. Can this be solved?
> > Also, there must be a simpler way using 'PlayMovie'? However, I
can't
> > get this to work. It doesn't come up with errors, but it fails to
play
> > the movie. Is this because I'm not on a Mac? It looks like some
things
> > won't work on PCs.
> > Also, I came across mentions of 'Showtime'. What is this? Can I
use
> > this on a PC? If so, where can I get it?
> > Thanks in advance for any help you can give me,
> > Robin.
> >
>
I've tried to follow your outline and use the demo as a basis, but
the code fails to stop at the end of a movie and continues to play it
on an infinite loop. Also, it seems to play it much too quickly.
Here's my play code:

[movie movieduration fps imgw imgh] = Screen('OpenMovie', win,
moviename);

try
start = GetSecs;
while(responseDuring == 0)

tex = Screen('GetMovieImage', win, movie);

% Valid texture returned?
if tex < 0
break;
end

% Draw the new texture immediately to screen:
Screen('DrawTexture', win, tex);

% Update display:
Screen('Flip', win);

% Release texture:
Screen('Close', tex);

[keyIsDown,secs,keyCode] = KbCheck;
if (GetSecs - start) > 0.2
[keyIsDown, secs, keyCode] = KbCheck;
if keyIsDown
if keyCode(up)|keyCode(down)
stop = GetSecs;
responseDuring = 1;
if keyCode(up), responseKey = 'up'; end
if keyCode(down), responseKey = 'down'; end
end
end
end

end % while loop
catch
% Error handling: Close all windows and movies, release all
resources.
Screen('CloseAll');
ShowCursor
end


I can't see why it's doing those things. I must be still be doing
something wrong.

Many thanks,

Robin.



--- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
<mario.kleiner@...> wrote:
>
> % Playback loop:
> while 1
> % Wait for arrival of next movieframe...
> texid = Screen('GetMovieImage', win, movie);
> if texid < 0
> % End of movie. break out of loop.
> break;
> end
>
> Screen('DrawTexture', win, texid);
> Screen('Flip', win);
> Screen('Close', texid);
>
> % Check keyboard:
> [down secs keycode] = KbCheck;
> if down && keycode(whatever)
> % Key pressed, break out of loop.
> break;
> end
> end; % of while -- next movie frame.
>
> Just the core of PlayMoviesDemoOSX.m ...
>
> 1. Wait for new movie frame.
> 2. Draw it and flip.
> 3. Check for keypresses or whatever.
> 4. Goto 1.
>
> The Quciktime engine will take care of playback timing this way.
>
> -mario
>
>
>
> --- In psychtoolbox@yahoogroups.com, "remarknibor" <remarknibor@>
wrote:
> >
> > Thanks for the comments. I thought I'd need to draw the movie one
> > texture at a time, rather than just playing it all at once, as I
> > continually need to check for keypresses while it is playing. Is
> > there any way of doing that while a movie is playing
> > using 'PlayMovie'? It looks like the demo you mention checks for
> > keypresses, but I'm a bit confused as to how it works. Compared
with
> > that demo, all I want to do is play the movie, and stop it (and
> > record the keypress) if the up or down arrows are pressed. Could
you
> > suggest the outline of the code I'd need to write?
> >
> > Thanks again,
> >
> > Robin.
> >
> >
> > --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> > <mario.kleiner@> wrote:
> > >
> > > Microsoft provides some additional free Codec-Packs for
> > > Quicktime for some of their formats. And if you google
> > > for "Perian" you'll find some Open source collection of
> > > additional codecs for OS/X.
> > >
> > > Regarding your code: You do a few weird things there.
> > >
> > > 1. keyCode(38) and such is not the way to go. KbName
> > > provides you with mappings for all keys. More convenient
> > > to use and portable across operating systems.
> > >
> > > 2. tic and toc are not a good way of timing stuff. We have
> > > GetSecs and WaitSecs for timing and timed waits -- Higher
> > > timing precision.
> > >
> > > 3. Most importantly, you use Screen('Flip', win, 0, 2, 2);
> > > The last '2' asks PTB to perform flips without any
synchronization
> > > to your display device, which means:
> > >
> > > a) Tearing / Flicker will occur.
> > > b) Playback of your preloaded textures will be as fast as
> > > the system can go, with no correlation to the timing of
> > > your movie. This means: First way too fast, then, as this
> > > overloads your system completely, the machine will slow
> > > down your Matlab script in random ways. The timing is
> > > not what you want anyway.
> > >
> > > If you preload all movie images, you'll have to control
> > > your presentation timing yourself by using the 'when'
> > > argument of Screen('Flip', window, when);
> > > e.g.
> > >
> > > vbl=Screen('Flip', window);
> > > slackvalue = Screen('GetFlipInterval', window)/2;
> > >
> > > for i=1:numFrames
> > > Screeen('Drawtexture', ...)
> > > vbl=Screen('Flip', window, vbl + 0.040 - slackvalue);
> > > end
> > >
> > > --> Wait 40 msecs between update of display...
> > >
> > > I wonder if you need to load the whole
> > > movie into textures at all or if you can't play the
> > > movie on the fly from disk, as demonstrated in
> > > PlayMoviesDemoOSX? There, Quicktime automatically
> > > takes care of playback timing (and audio-video sync).
> > >
> > > -mario
> > >
> > >
> > > --- In psychtoolbox@yahoogroups.com, "remarknibor"
<remarknibor@>
> > wrote:
> > > >
> > > > Thanks for that. I can get mp4s to work, but only certain avi
> > movies.
> > > > Probably something to do with codecs and the variety of
different
> > avi
> > > > files out there.
> > > > As for the varying speed of playback, here is my function
that
> > > > creates and draws textures from the movie files:
> > > >
> > > >
> > > > function [responseKey,responseTime] = CrossLoadPlayMovie
> > > > (win,moviename)
> > > >
> > > > KbName('UnifyKeyNames');
> > > > screenNum = 0;
> > > > white = WhiteIndex(win);
> > > > black = BlackIndex(win);
> > > > resolution = [1280 1024];
> > > > midHoriz = resolution(1) / 2;
> > > > midVert = resolution(2) / 2;
> > > > responseDuring = 0;
> > > > responseAfter = 0;
> > > > responseKey = 0;
> > > > responseTime = 0;
> > > > start = 0;
> > > > stop = 0;
> > > >
> > > > [movie movieduration fps imgw imgh] = Screen('OpenMovie',
win,
> > > > moviename);
> > > >
> > > > movietexture = 0; % Texture handle for the current movie
frame.
> > > > lastpts = -1; % Presentation timestamp of last frame.
> > > > pts = -1;
> > > > count = 0; % Number of loaded movie frames.
> > > >
> > > > % Movie to texture conversion loop:
> > > > while movietexture >= 0 & pts < 100000
> > > > [movietexture pts] = Screen('GetMovieImage', win, movie,
> > > > 1);
> > > > if movietexture > 0 & pts > lastpts
> > > > count=count + 1;
> > > > texids(count)=movietexture;
> > > > texpts(count)=pts;
> > > > lastpts=pts;
> > > > else
> > > > break
> > > > end
> > > > end
> > > >
> > > > % fixation cross and left/right
> > > > Screen('FillRect',win,black);
> > > > Screen('DrawLine',win,white,midHoriz - 10,midVert,midHoriz +
> > > > 10,midVert);
> > > > Screen('DrawLine',win,white,midHoriz,midVert -
> > 10,midHoriz,midVert +
> > > > 10);
> > > > Screen('DrawText',win,'Left',midHoriz - 25,midVert +
300,white);
> > > > Screen('DrawText',win,'Right',midHoriz - 35,midVert +
350,white);
> > > > Screen('Flip',win);
> > > >
> > > > % wait before stimulus presentation of 400ms
> > > > tic
> > > > while toc < 0.4
> > > > ;
> > > > end
> > > >
> > > > currentindex = 1;
> > > > totalcount = 0;
> > > >
> > > > tic
> > > > start = GetSecs;
> > > > % Draw loop:
> > > > while count > 0 & currentindex < count & responseDuring == 0
> > > > % Draw texture 'currentindex'
> > > > Screen('DrawTexture', win, texids(currentindex));
> > > > Screen('DrawText',win,'Left',midHoriz - 25,midVert +
> > 300,white);
> > > > Screen('DrawText',win,'Right',midHoriz - 35,midVert +
> > 350,white);
> > > > Screen('Flip', win, 0, 2, 2);
> > > > totalcount = totalcount + 1;
> > > > if toc > 0.2
> > > > [keyIsDown, secs, keyCode] = KbCheck;
> > > > if keyIsDown
> > > > if keyCode(38)|keyCode(40) == 1
> > > > stop = GetSecs;
> > > > responseDuring = 1;
> > > > if keyCode(38) == 1, responseKey = 'up'; end
> > > > if keyCode(40) == 1, responseKey = 'down'; end
> > > > end
> > > > end
> > > > end
> > > > currentindex = mod(currentindex, count) + 1;
> > > > end;
> > > >
> > > > tic
> > > > while toc < 0.4 & responseDuring == 0 % 400ms response window
> > after
> > > > end of movie
> > > > [keyIsDown, secs, keyCode] = KbCheck;
> > > > if keyIsDown
> > > > if keyCode(38)|keyCode(40) == 1
> > > > stop = GetSecs;
> > > > responseAfter = 1;
> > > > if keyCode(38) == 1, responseKey = 'up'; end
> > > > if keyCode(40) == 1, responseKey = 'down'; end
> > > > end
> > > > end
> > > > end
> > > >
> > > > % if no response or too slow
> > > > if responseDuring == 0 & responseAfter == 0
> > > > responseKey = 'none'; % no response
> > > > responseTime = 0; % no response
> > > > start = 0; % no response
> > > > stop = 0; % no response
> > > > Screen('FillRect',win,black);
> > > > Screen('DrawText',win,'Too Slow',midHoriz - 55,midVert -
> > > > 35,white);
> > > > Screen('DrawText',win,'-10 Points',midHoriz - 60,midVert -

> > > > 5,white);
> > > > Screen('DrawText',win,'Left',midHoriz - 25,midVert +
> > 300,white);
> > > > Screen('DrawText',win,'Right',midHoriz - 35,midVert +
> > 350,white);
> > > > Screen('Flip',win);
> > > > tic
> > > > while toc < 0.5
> > > > ;
> > > > end
> > > > end
> > > >
> > > > % wait before next stimulus presentation of 200ms
> > > > Screen('FillRect',win,black);
> > > > Screen('DrawText',win,'Left',midHoriz - 25,midVert +
300,white);
> > > > Screen('DrawText',win,'Right',midHoriz - 35,midVert +
350,white);
> > > > Screen('Flip',win);
> > > > tic
> > > > while toc < 0.2
> > > > ;
> > > > end
> > > >
> > > > Screen('CloseMovie', movie); % Closes movie file and releases
all
> > > > textures
> > > > responseTime = stop - start;
> > > >
> > > >
> > > > I can't see why it would lead to varying speeds. Can you see
> > anything
> > > > that needs altering?
> > > >
> > > > Thanks again for all your help,
> > > >
> > > > Robin.
> > > >
> > > >
> > > >
> > > > --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> > > > <mario.kleiner@> wrote:
> > > > >
> > > > > 1. Reads anything supported by Quicktime, so it should
handle
> > > > > .mp4 or .mpg or .avi or .wav if you have the codecs
installed.
> > > > >
> > > > > 2. Probably a bug in your script. Check the demos or
> > > > > post your code.
> > > > >
> > > > > 3. Have a look at "help Ask" especially the last example
> > mentioned
> > > > > in the help: This is for text input with feedback, e.g.,
typing
> > name
> > > > > and age. Then there's GetChar and for typical response
queries
> > > > > there are KbWait and KbCheck.
> > > > >
> > > > > -mario
> > > > >
> > > > > --- In psychtoolbox@yahoogroups.com, "remarknibor"
> > <remarknibor@>
> > > > wrote:
> > > > > >
> > > > > > Thanks for the help. The Quicktime demos work just fine
and
> > I've
> > > > now
> > > > > > sorted my previous problem. However, I was still
wondering:
> > > > > >
> > > > > > 1. if 'OpenMovie' and the other functions will only work
> > > > with '.mov'
> > > > > > files. Especially given that Quicktime itself will play
other
> > > > file
> > > > > > types (such as .mp4).
> > > > > >
> > > > > > 2. why it appears that when I show the movies (by
repeatedly
> > > > drawing
> > > > > > textures to the screen), the speed varies during play. It
> > seems
> > > > to
> > > > > > start off faster and then slow to a more normal speed.
This
> > is
> > > > > > despite the fact that I've already created all the
textures
> > > > > > beforehand using 'GetMovieImage'.
> > > > > >
> > > > > > 3. if, unrelated to the movie playing, one can ask for
and
> > record
> > > > > > user input from the Screen. For instance, if I wanted to
ask
> > for
> > > > the
> > > > > > participant's name and age. If this is possible, which
> > functions
> > > > > > should I look to use?
> > > > > >
> > > > > > Thanks again for the help,
> > > > > >
> > > > > > Robin.
> > > > > >
> > > > > >
> > > > > > --- In psychtoolbox@yahoogroups.com, "Mario Kleiner"
> > > > > > <mario.kleiner@> wrote:
> > > > > > >
> > > > > > > Showtime was only for MacOS/9. Quicktime movie playback
> > should
> > > > > > > work well on MS-Windows, there are only a few
specialities
> > that
> > > > > > > aren't supported on Win vs. OS/X.
> > > > > > >
> > > > > > > Do your movie(s) work with our Quicktime demos? If yes -
>
> > Check
> > > > > > > your code. If no, then you're probably trying to play a
> > movie
> > > > format
> > > > > > > that is not supported by your Quicktime installation.
> > Codecs
> > > > widely
> > > > > > > differ in performance, accuracy and speed...
> > > > > > >
> > > > > > > I think the H.263/264 codecs performed very well when
we
> > used
> > > > > > > them. H.264 e.g. can play two high quality 768x576 or
> > 640x480
> > > > > > > PAL/NTSC color movies in parallel at 30 fps without
losing
> > sync
> > > > > > > or dropping frames -- at least on current hardware.
> > > > > > >
> > > > > > > -mario
> > > > > > >
> > > > > > >
> > > > > > > --- In psychtoolbox@yahoogroups.com, "remarknibor"
> > > > <remarknibor@>
> > > > > > wrote:
> > > > > > > >
> > > > > > > > Hi.
> > > > > > > > I'm trying to play short movies (one or two seconds
long)
> > in
> > > > the
> > > > > > > > psychtoolbox window as stimuli that participants will
> > watch
> > > > but
> > > > > > I'm
> > > > > > > > having problems. I'm using a Windows PC and it has
> > Quicktime
> > > > > > installed
> > > > > > > > on it (in case that matters).
> > > > > > > > At the moment, I can get only a '.mov' movie to work,
and
> > I'm
> > > > > > > > using 'OpenMovie', 'GetMovieIMage' and 'DrawTexture'
to
> > work
> > > > my
> > > > > > way
> > > > > > > > through the short movie. However, the speed with
which
> > the
> > > > > > textures are
> > > > > > > > displayed doesn't appear constant. Can this be solved?
> > > > > > > > Also, there must be a simpler way using 'PlayMovie'?
> > However,
> > > > I
> > > > > > can't
> > > > > > > > get this to work. It doesn't come up with errors, but
it
> > > > fails to
> > > > > > play
> > > > > > > > the movie. Is this because I'm not on a Mac? It looks
> > like
> > > > some
> > > > > > things
> > > > > > > > won't work on PCs.
> > > > > > > > Also, I came across mentions of 'Showtime'. What is
this?
> > Can
> > > > I
> > > > > > use
> > > > > > > > this on a PC? If so, where can I get it?
> > > > > > > > Thanks in advance for any help you can give me,
> > > > > > > > Robin.
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>