Substantial audio lag using MovieStim3

I am trying to present mp4 files (about 10 minutes in length) for a fMRI experiment. The code that I have is working, and the movie stimulus successfully comes up and is played. However, the video lags about 3 seconds behind the audio. Is there a way to fix this? I’m not sure what is causing the delay, and can’t seem to find a solution online. For reference, I’m using MovieStim3 with psychopy v2023.2.0. The FrameRate is 60 (which matches my graphics card). Thank you for your help!

What OS are you using, and how are the movie files encoded?

MovieStim3 isn’t particularly efficient as a movie player, unfortunately. It’s good for short clips but when it has to load a longer clip into memory it can introduce some weird behavior. You could try switching to MovieStim or vlcMovieStim and see if either of them work better, or see if there’s any media encoding that runs better (e.g., .h264 encoding, lower resolution or framerate, lower audio sample rate, etc.)

Thank you, that is helpful information! I will try those suggestions. I primarily chose MovieStim3 because it gives more accurate timing information compared to MovieStim. Do you know of any potential work-arounds to get more accurate frame timing information using MovieStim? Sorry for asking a potentially basic question, it’s my first time using PsychoPy to present movie stimuli in an fMRI experiment.

The ffpyplayer engine for MovieStim is the recommended approach and the only one the core team are now working on. It has by far the best performance so please use that and let us know if there are any issues we need to fix with that solution

thanks

Hey, I am running into the same problem as Lex1, even with very short mp4 videos where the audio lags a lot.
Having seen your comment, I tried to use movieStim, which helps reduce the lagging issue, but PsychoPy freezes after the video played (still showing the last frame on the screen).
Would you have any idea how to fix this?

I am working on Windows 10, PsychoPy3 v2023.1.2, Python 3.8.10

movie = visual.MovieStim(win, filename=“vids/test.mp4”, size=(720, 480), pos=(0, 0), volume=1.0)
movie.play()
while movie.status != visual.FINISHED:
movie.draw()
win.flip()
movie.stop()

@l_b in the code that you’ve got here the movie.draw() is what causes the movie to carry on being visible. If you call win.flip() without movie.draw() after the movie has finished then you’ll get a screen without drawing the final frame of the movie. It’s by design that if you choose to draw the movie after it’s finished you see the final frame still

Hi Jon,

I’m having a slightly different issue. I have my event coded (I think) like you described, with a subsequent win.flip() following the stimulus ending:

# Initializing keyboard
kb = keyboard.Keyboard()

# Defining our video object
# Forgive the undefined variables; part of a larger script
Stimulus = visual.MovieStim(win=win, units = units, 
                            filename=video, name=video_name)
  
# Starting the video
Stimulus.play()

# If the stimulus is still playing
while Stimulus.status != visual.FINISHED:
 
    # Draw the next frame
    Stimulus.draw()

    # Flip the frame
    win.flip()

    # if the escape key is pressed ...
    if kb.getKeys(keyList=["escape"]):

        # Quit the task
        core.quit()
  
# Flip the window
win.flip()

# Stop the stimulus  
Stimulus.stop()

and I am not getting the freezing on the final frame. However, I am getting the last tiny audio clip of the video playing repeatedly (about 6 times in a row), before the task actually closes. This occurs regardless of which video I play. I’ve been trying to debug this with 10 to 90 second .mp4 formatted videos, all < 4000KB in size, but haven’t had any luck. Any ideas? If it’s just a side effect with no current solution, I can live with it. MovieStim seems to be a big improvment over MovieStim3 and is still the best performing player for my purposes, so I really appreciate the hard work on it, but figured I’d ask since I came across this thread. Thanks again for your time !