Movie Playing + Keyboard Press detection

I’ve been developing a code where I need to play a video of a letter sequence presentation while recording key presses, in the most accurate way possible. For that, I created movies with Screen(‘createmovie’) and would try to play the movie, then while the movie was playing, register the keyboard presses with KbWait/KbCheck.
This has turned into a problem as I can’t seem to play the movies without a loop to get the textures and draw them (I wanted to just let them play with a simple instruction and then place a loop for keyboard check).
Another problem I got is when a usage error in Screen(‘OpenMovie’):
Usage:

[ moviePtr [duration] [fps] [width] [height] [count] [aspectRatio] [hdrStaticMetaData]]=Screen(‘OpenMovie’, windowPtr,
moviefile [, async=0] [, preloadSecs=1] [, specialFlags1=0][, pixelFormat=4][, maxNumberThreads=-1][, movieOptions]);

Error in SimpleMovieDemo (line 43)
movie = Screen(‘OpenMovie’, win, moviename);

I realized this as to be about the moviefile. But I don’t understand why is the moviefile broken, as I can play it outside of matlab.

Hi,

You would indeed have to check for keypresses in that presentation loop, you can’t get around that using videos. If you also generate the videos using matlab+PTB, can’t you run the stimulus live (that is, no intermediate step of creating and then playing videos)?

Regarding the error message, i think some information is missing, is there an actual error message a bit earlier on the command line output?

The error message is the following:
PTB-ERROR: Statechange failed with GST_STATE_CHANGE_FAILURE!
PTB-ERROR: Could not open movie file [C:\Users\joaop\OneDrive - Universidade do Porto\Erasmus\Internship\Combined-EEG-fNIRS-system\LetterPresentation\LetterPresentation1.mov] for playback! No such moviefile with the given absolute path and filename.
PTB-ERROR: Please note that you must provide an absolute path and filename for your movie file, filename alone won’t work.
PTB-ERROR: The specific file URI of the missing movie was: file:///C:\Users\joaop\OneDrive - Universidade do Porto\Erasmus\Internship\Combined-EEG-fNIRS-system\LetterPresentation\LetterPresentation1.mov.
PTB-ERROR: GStreamer movie playback engine reports this error:
Error from element source: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
Additional debug info: …/libs/gst/base/gstbasesrc.c(3557): gst_base_src_start (): /GstPlayBin:ptbmovieplaybackpipeline/GstURIDecodeBin:uridecodebin0/GstFileSrc:source:
Failed to start.

But this might be useless if I can’t check for keypresses while playing the movie.The other version of my code, I run the stimulus live and check the keyboard presses after with KbQueueCheck but the timings I get from that might not be precise enough.
DetectionRTInVideoDemo records keypress, but only one. I need to record a sequence of keypresses along with the presentation of the stimulus.

Looks like you made a typo in the filename, or the file is not were you specified it → File not found.

KbQueues are the right approach for what you want to do, but you’d use KbEventFlush, KbEventGet and KbEventAvail to collect all key input with timestamps at the end of your movie playback. E.g., KbQueueDemo.m for that approach.

If you need further assistance from myself, please get your lab to buy priority support.

-mario

You can also buffer a video to allow it to play while also drawing other things. For example, say you have a 30fps video but use a 120Hz display and want to draw other stuff/check keypresses etc, then you turn off waiting for a new fram, use two textures e.g. tex and buf, and draw tex if there is a new image available and buf otherwise, rough pseudocode:

waitForImage = false;
tex = Screen('GetMovieImage',win, mov, waitForImage);
if tex > 0
    try Screen('Close', buf); end
    Screen('DrawTexture', win, tex);
    buf = tex;
else
    Screen('DrawTexture', win, buf);
end

This is one solutions to keep a video playing at the nominal framerate even if the experiment loop is not synchronous with that frame rate…