How can we save the output of psychtoolbox code in a video file?

Hi everybody. I’ve just created a simple task for my project but I need to save it as a video file to use it in another app. Is it possible at all?! I would appreciate it a lot if you could guide me.
Here is my code:

window=Screen('OpenWindow',0);
Screen('FillOval',window,[0,200,200],[260,290,310,340]);
onsetTime1=Screen('Flip',window);
WaitSecs(0.5);

Screen('FillOval',window,[0,200,200],[1000,290,1050,340]); 
onsetTime2=Screen('Flip',window);
WaitSecs(0.5);

The commands you need are Screen('CreateMovie', some-settings) before your displayloop, Screen('AddFrameToMovie', some-settings) after each flip, and Screen('Finalizemovie', some-settings) after the display loop (read the docs for each one). There are quite a few details about which codec to use etc. and I can’t remember off the top of my head if there is a demo for this…

http://psychtoolbox.org/docs/Screen-CreateMovie

Thank you for your help. I included the three code lines you mentioned in my code but it doesn’t work! The error refers to the third line which contains ‘CreateMovie’ code. I’ve put my code here. Do you know what would be the problem with it?

Screen('Preference','SkipSyncTests',1);
window=Screen('OpenWindow',0);
movie = Screen('CreateMovie', windowPtr, 'MyTestMovie.mov');

Screen('FillOval',window,[0,200,200],[260,290,310,340]);
onsetTime1=Screen('Flip',window);
WaitSecs(2);

Screen('AddFrameToMovie', windowPtr, CenterRect);
Screen('FinalizeMovie', movie);
sca

Sometimes you use ‘window’ sometimes ‘windowPtr’. Obviously it always needs to be ‘window’. Also, if you don’t post error messages, how would anybody guess what’s wrong in less obvious cases??

ImagingStereoDemo has some working demo code for movie writing.

However, things like onsetTime1… and WaitSecs(2) will not translate to the movie, as AddFrameToMovie would add exactly 1 frame to the video, so in your example the movie would consist of 1 video frame that quickly flashes, and then the movie is over. See the optional ‘frameduration’ parameter for ‘AddFrameToMovie’ to understand how you define stimulus duration in a recorded movie as opposed to live presentation.

And of course, visual timing in general will not be as robust in the movie. That’s the job of the presentation software if you use something else than PTB. If you just play the movie in some player, that’s good enough for documenting your stimuli, e.g., for some talk, website, supplemental material etc., if display timing or calibration or such doesn’t matter.