psychopy.org | Reference | Downloads | Github

Video freezes shortly before animation with MovieStim3

I have a sequence of 2 mp4 videos played 4 times (4 trials), with a fixation cross that appears before each animation as shown in the code below.
In order to load, play and draw the animations, I used MovieStim3 following [this demo] made by @richard. I used the functions .play and .draw to play and draw the movies.

The movies are played, however, at the beginning of the 3rd and 4th trial, the animation freezes for 3seconds before moving. This is really problematic because it is influencing badly the effect of the animation on my participants’ perception. Any advice would be very helpful. Thanks in advance :slight_smile:

# Load optic flow and random flow movies
optic_flow_movie    = visual.MovieStim3(win, 'optic_flow.mp4',loop= False)
random_flow_movie   = visual.MovieStim3(win, 'random_flow.mp4',loop= False)

for trialcount in range(nTrials):
    
    # We start the timer for each trial
    kb.clock.reset()  
    
    # Start with fixation cross 
    fixation.draw()
    win.flip()
    core.wait(2)
    
    # Play the video for 200 frames 
    
    optic_flow_movie.seek(0)
    random_flow_movie.seek(0)
    
    for Nframes in range(200):
                
        if conditions_rand[trialcount] == 1:
            optic_flow_movie.play()
            optic_flow_movie.draw()
 
        elif conditions_rand[trialcount] == 2:
            random_flow_movie.play()
            random_flow_movie.draw()

        
        fixation.draw()
        win.flip()

Hi Kathia,

Part of the difficulty in tracking down problems with video playing is getting a reproducible example.

  • Can you edit the script so that it can be run independently (e.g. create a window, don’t refer to undefined variables like nTrials, conditions_rand, etc). i.e. distill the script down to the absolute minimum that could be run by someone else but that still shows the issue.
  • Would it be possible to provide the videos that you use with this script?
  • Also please provide details of your operating system, what graphics card your computer has, and so on.

After your questions at StackOverflow, it is clear that the problems aren’t with your programming, but with performance issues either within PsychoPy or (more likely) with the underlying third-party libraries it uses to play movies. So the only way to make progress will be to have an example that others can run and test for themselves.

Hi @Michael

Here is the piece of code as a reproducible example - i included the window and defined the variables. I also tried to keep the essential and eliminated the unnecessary details.

from psychopy import visual, event, core
import random
from random import randrange
import numpy as np
from psychopy.hardware import keyboard

# Parameters

nTrials = 4

nb_conditions = np.arange(1,3)                        # We have two conditions : Optic_flow and Random_flow

conditions = nb_conditions.repeat(nTrials/2)          # nTrials/2 times condition_1 and nTrials/2 times condition_2

conditions_rand = np.random.permutation(conditions)   # Randomize the order of the conditions

# Create a Window

win = visual.Window(
    size=(1000, 800),
    color='Black',
    colorSpace='rgb',
    units='deg',
    allowGUI=True,
    fullscr=False)    

clock = core.Clock()

# Load optic flow and random flow movies
optic_flow_movie    = visual.MovieStim3(win, 'optic_flow.mp4',loop= False)
random_flow_movie   = visual.MovieStim3(win, 'random_flow.mp4',loop= False)


kb = keyboard.Keyboard()

# Reset clock 0 sec
clock.reset()  

for trialcount in range(nTrials):
    
    # We start the timer for each trial
    kb.clock.reset()  
    
    # Play the video for 200 frames 
    
    optic_flow_movie.seek(0)
    random_flow_movie.seek(0)
    
    for Nframes in range(200):
                
        if conditions_rand[trialcount] == 1:
            optic_flow_movie.play()
            optic_flow_movie.draw()
 
        elif conditions_rand[trialcount] == 2:
            random_flow_movie.play()
            random_flow_movie.draw()     
        win.flip()
        

My computer details are:

  • macOS Catalina Version 10.15.5
  • Graphics Intel UHD Graphics 617 1536 MB
  • Processor 1,6 GHz Dual-Core Intel Core i5
  • Memory 8 GB 2133 MHz LPDDR3

I use Python 3.7.4, and Psychopy 2020.1.2

I’d be happy to attach my videos, but it doesn’t seem to be possible. How can I provide you with my videos?

I’ve just tried changing this site’s settings to allow uploading .mov or .mp4 files, so you could try that and see if it works?

Otherwise, you could share by providing a link to DropBox or Google Drive or similar.

1 Like

@Michael You can find attached the two videos that I generated in a separate code with the use of win.saveMovieFrames('video_name.mp4')

Apart from needing to change some of the import statements (have edited your code above), this task seems to run fine for me. My MacBook Pro is about three years older than your MacBook Air, although the integrated graphics on mine is apparently about 20% faster than on yours (on an Air, there is much more emphasis on keeping power consumption low).

Having said that, these videos are small and should not be stressing your system too much. So this seems like something specific to your computer set-up.

So,

  • have you checked that nothing else is running in the background other than PsychoPy? - developing on your own laptop is generally fine, but for actually running an experiment, it is best to use a dedicated computer that doesn’t run other software, and that ideally has a proper graphics card rather than Intel integrated graphics.
    • have you tried running on another computer (Mac or Windows)?

@Michael Thanks for your feedback!
I will have access to another computer (Linux) with a dedicated graphics card to check whether it is working.
I have previously generated the videos with the same size window size=(1000, 800). However, when played in the above code, the sizes of the video are different - it does not display the entire video screen. I have realized that in some of my videos, where one of the peripheral circles change the colour when it moves close to the bottom side of the video frame. When played in the above code, I do not see the change of colour because this code somehow cuts the lateral parts of the video. Is there a way to fix it?

Thanks in advance for your precious help!

Are you repeating movie files? Your issue seems similar to this one.

https://discourse.psychopy.org/t/problem-with-playing-mp4-online-moving-dots-movies/15042/7?u=wakecarter

When I look at the attributes of the videos, they are actually 2000 × 1600. I guess this might be because they were created on a Mac with a retina screen maybe, where the physical pixels can be at a higher resolution than the “logical” pixels. Depending on the system you play them back on, then this might require each frame to be downsampled, which could cause issues.

MacBook Air models released from 2018 onwards have a physical resolution of 2560 × 1600 pixels but a “logical” screen size of half of that (i.e. 1280 × 800). It can get confusing, but I think if you request a window from PsychoPy of 1280 × 800, it should fill the entire screen, but stimuli might render at twice that resolution (where individual pixels won’t be discriminable).

Also in general, PsychoPy performs best if the window you create is fullscreen: that way it is able to take over more of the computer’s resources. So try opening a full screen window, and look at what happens when you create your movie stems either by letting the size be unspecified or forced to be 1000 × 800.

1 Like