Drawing both a polygon and movie frames

Hello everyone,

I’m trying to present a movie and simultaneously indicate in some way when a button has been pressed (ideally I would like to indicate this with a sound). Using sound simultaneously with the movie causes unstable behaviour, so I am trying to briefly change the color of the background. If anyone has ideas on how to resolve the issue below (or, conversely, indicate the keypress has been logged in another way), I would greatly appreciate it.

I am running PsychoPy 1.84.2 on Windows 7. I have tried writing the code in multiple ways, and have encountered two primary types of problems. For example, when I try the following code:

background_start = -1
while movie.status != FINISHED:
    theseKeys = event.getKeys(keyList=['space'])
    if len(theseKeys) > 0:  # at least one key was pressed
        background.fillColor =  [1, 0, 0]
        background_start = t
        background.draw()

    if (background_start>-1 and t-background_start>=1):
        background.fillColor =  [0,0,0]
        background_start = -1
        background.draw()

    movie.draw()
    win.flip()

Until the first button press the movie plays well. When pressing space, the background changes to red only for a moment (perhaps one frame) before returning to grey. And in addition sometimes the movie will become dark after a key press (sometimes it will stay dark, sometimes become light again after another keypress).

I tried also to draw the background before every flip:

background_start = -1
while movie.status != FINISHED:
    theseKeys = event.getKeys(keyList=['space'])
    if len(theseKeys) > 0:  # at least one key was pressed
        background.fillColor =  [1, 0, 0]
        background_start = t

    if (background_start>-1 and t-background_start>=1):
        background.fillColor =  [0,0,0]
        background_start = -1
        
    background.draw()
    movie.draw()
    win.flip()

In this version, a button press does cause the background to switch to red for a second, but there’s constant flickering (between the light and dark versions of the screen and movie) throughout.

The definitions of the window, rectangle and movie are:

win = visual.Window(
    size=(1680, 1050), fullscr=True, screen=0,
    allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True)

movie = visual.MovieStim2(
    win=win, name='movie',
    noAudio = False,
    filename=u'X:\\stimuli\\movie.mp4',
    ori=0, pos=(0, 0), opacity=1,
    )

background = visual.Rect(
    win=win, name='background',
    width=1680, height=1050,
    ori=0, pos=(0, 0),
    lineWidth=1, lineColor=[0,0,0], lineColorSpace='rgb',
    fillColor=[0,0,0], fillColorSpace='rgb',
    opacity=1, interpolate=False)

When using MovieStim instead of MovieStim2 it works well, but then I have no option to log when exactly relative to the movie (frameTime, frameNumber). I could use the routine clock, but would prefer to use MovieStim2 if possible. And MovieStim3 runs out of memory.

Thanks!

Your second version of the code is the correct one: you definitely need to be drawing the background and the movie before each flip. In the first code, the background drawing was conditional and it would not always actually be drawn to the screen on each refresh.

I’m not sure how to help diagnose the flickering issue without seeing it in person, but start by manipulating each line to isolate the problem. e.g. make both lines that set the fillColor set it to the same colour value, and so on.

PS I’m going to guess that the movie is on a network drive (‘X:’). You might get better performance by loading it from a local drive (but unlikely unrelated to any problems you are describing).

Thank you very much!
I will try to move the movie to a local drive, even if it doesn’t help with the flickering, perhaps it could help with the original problem (using both sound and a movie).