MovieStim3

To import MovieStim3, you can either use:

from psychopy_legacy.visual.movie3 import MovieStim3

or, any time after psychopy.plugins.activatePlugins has been called:

from psychopy.visual import MovieStim3
class psychopy_legacy.visual.movie3.MovieStim3(win, filename='', units='pix', size=None, pos=(0.0, 0.0), anchor='center', ori=0.0, flipVert=False, flipHoriz=False, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, volume=1.0, name='', loop=False, autoLog=True, depth=0.0, noAudio=False, vframe_callback=None, fps=None, interpolate=True)[source]

A stimulus class for playing movies. This is a lazy-imported class, therefore import using full path from psychopy.visual.movie3 import MovieStim3 when inheriting from it.

This class uses MoviePy and FFMPEG as a backend for loading and decoding video data from files.

Parameters:
  • filename (str) – A string giving the relative or absolute path to the movie.

  • flipVert (True or False) – If True then the movie will be top-bottom flipped

  • flipHoriz (True or False) – If True then the movie will be right-left flipped

  • volume – The nominal level is 100, and 0 is silence.

  • loop (bool, optional) – Whether to start the movie over from the beginning if draw is called and the movie is done.

Examples

See Movie2Stim.py for demo.

property anchor
autoDraw

Determines whether the stimulus should be automatically drawn on every frame flip.

Value should be: True or False. You do NOT need to set this on every frame flip!

autoLog

Whether every change in this stimulus should be auto logged.

Value should be: True or False. Set to False if your stimulus is updating frequently (e.g. updating its position every frame) and you want to avoid swamping the log file with messages that aren’t likely to be useful.

clearTextures()

Clear all textures associated with the stimulus.

As of v1.61.00 this is called automatically during garbage collection of your stimulus, so doesn’t need calling explicitly by the user.

contains(x, y=None, units=None)

Returns True if a point x,y is inside the stimulus’ border.

Can accept variety of input options:
  • two separate args, x and y

  • one arg (list, tuple or array) containing two vals (x,y)

  • an object with a getPos() method that returns x,y, such

    as a Mouse.

Returns True if the point is within the area defined either by its border attribute (if one defined), or its vertices attribute if there is no .border. This method handles complex shapes, including concavities and self-crossings.

Note that, if your stimulus uses a mask (such as a Gaussian) then this is not accounted for by the contains method; the extent of the stimulus is determined purely by the size, position (pos), and orientation (ori) settings (and by the vertices for shape stimuli).

See Coder demos: shapeContains.py See Coder demos: shapeContains.py

depth

DEPRECATED, depth is now controlled simply by drawing order.

draw(win=None)[source]

Draw the current frame to a particular visual.Window (or to the default win for this object if not specified). The current position in the movie will be determined automatically.

This method should be called on every frame that the movie is meant to appear.

Parameters:

win (Window or None) – Window the video is being drawn to. If None, the window specified by property win will be used. Default is None.

property duration

Duration of the video clip in seconds (float). Only valid after loading a clip, always returning 0.0 if not.

property flip

1x2 array for flipping vertices along each axis; set as True to flip or False to not flip. If set as a single value, will duplicate across both axes. Accessing the protected attribute (._flip) will give an array of 1s and -1s with which to multiply vertices.

property flipHoriz
property flipVert
property frameInterval

Time in seconds each frame is to be presented on screen (float). Value is 0.0 if no movie is loaded.

getAnchor()
getAutoDraw()
getAutoLog()
getCurrentFrameTime()[source]

Get the time that the movie file specified the current video frame as having.

getDepth()
getDuration()
getFPS()[source]

Get the movie frames per second.

Returns:

Frames per second.

Return type:

float

getFlip()
getFlipHoriz()
getFlipVert()
getFrameInterval()
getHeight()
getInterpolate()
getMask()
getMaskParams()
getName()
getOpacity()
getOri()
getPos()
getSize()
getTexRes()
getUnits()
getVertices()
getVerticesPix()
getWidth()
getWin()
get_borderPix()
property height
property interpolate

Enable linear interpolation (`bool’).

If True linear filtering will be applied to the video making the image less pixelated if scaled.

loadMovie(filename, log=True)[source]

Load a movie from file.

After the file is loaded MovieStim.duration is updated with the movie duration (in seconds).

Parameters:
  • filename (str) – The name of the file, including path if necessary.

  • log (bool) – Log this event.

mask

The alpha mask (forming the shape of the image).

This can be one of various options:
  • ‘circle’, ‘gauss’, ‘raisedCos’, ‘cross’

  • None (resets to default)

  • the name of an image file (most formats supported)

  • a numpy array (1xN or NxN) ranging -1:1

maskParams

Various types of input. Default to None.

This is used to pass additional parameters to the mask if those are needed.

  • For ‘gauss’ mask, pass dict {‘sd’: 5} to control

    standard deviation.

  • For the ‘raisedCos’ mask, pass a dict: {‘fringeWidth’:0.2},

    where ‘fringeWidth’ is a parameter (float, 0-1), determining the proportion of the patch that will be blurred by the raised cosine edge.

name

The name (str) of the object to be using during logged messages about this stim. If you have multiple stimuli in your experiment this really helps to make sense of log files!

If name = None your stimulus will be called “unnamed <type>”, e.g. visual.TextStim(win) will be called “unnamed TextStim” in the logs.

property opacity

Determines how visible the stimulus is relative to background.

The value should be a single float ranging 1.0 (opaque) to 0.0 (transparent). Operations are supported. Precisely how this is used depends on the blendMode.

ori

The orientation of the stimulus (in degrees).

Should be a single value (scalar). Operations are supported.

Orientation convention is like a clock: 0 is vertical, and positive values rotate clockwise. Beyond 360 and below zero values wrap appropriately.

overlaps(polygon)

Returns True if this stimulus intersects another one.

If polygon is another stimulus instance, then the vertices and location of that stimulus will be used as the polygon. Overlap detection is typically very good, but it can fail with very pointy shapes in a crossed-swords configuration.

Note that, if your stimulus uses a mask (such as a Gaussian blob) then this is not accounted for by the overlaps method; the extent of the stimulus is determined purely by the size, pos, and orientation settings (and by the vertices for shape stimuli).

See coder demo, shapeContains.py

pause(log=True)[source]

Pause the current point in the movie (sound will stop, current frame will not advance). If play() is called again both will restart.

play(log=True)[source]

Continue a paused movie from current position.

property pos

The position of the center of the stimulus in the stimulus units

value should be an x,y-pair. Operations are also supported.

Example:

stim.pos = (0.5, 0)  # Set slightly to the right of center
stim.pos += (0.5, -1)  # Increment pos rightwards and upwards.
    Is now (1.0, -1.0)
stim.pos *= 0.2  # Move stim towards the center.
    Is now (0.2, -0.2)

Tip: If you need the position of stim in pixels, you can obtain it like this:

from psychopy.tools.monitorunittools import posToPix
posPix = posToPix(stim)
reset()[source]
seek(t)[source]

Go to a specific point in time for both the audio and video streams

setAnchor(value, log=None)
setAutoDraw(val, log=None)[source]

Add or remove a stimulus from the list of stimuli that will be automatically drawn on each flip.

Parameters:

val (bool) – True to add the stimulus to the draw list, False to remove it.

setAutoLog(value=True, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setDepth(newDepth, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setFlip(value, log=None, operation=False, stealth=False)
setFlipHoriz(newVal=True, log=True)[source]

If set to True then the movie will be flipped horizontally (left-to-right). Note that this is relative to the original, not relative to the current state.

setFlipVert(newVal=True, log=True)[source]

If set to True then the movie will be flipped vertically (top-to-bottom). Note that this is relative to the original, not relative to the current state.

setHeight(value, log=None, operation=False, stealth=False)
setInterpolate(value, log=None, operation=False, stealth=False)
setMask(value, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setMaskParams(value, log=None, operation=False, stealth=False)
setMovie(filename, log=True)[source]

See ~MovieStim.loadMovie (the functions are identical).

This form is provided for syntactic consistency with other visual stimuli.

Parameters:
  • filename (str) – The name of the file, including path if necessary.

  • log (bool) – Log this event.

setName(value, log=None, operation=False, stealth=False)
setOpacity(newOpacity, operation='', log=None)

Hard setter for opacity, allows the suppression of log messages and calls the update method

setOri(newOri, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setPos(newPos, operation='', log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message.

setSize(newSize, operation='', units=None, log=None)

Usually you can use ‘stim.attribute = value’ syntax instead, but use this method if you need to suppress the log message

setTexRes(value, log=None, operation=False, stealth=False)
setUnits(value, log=None, operation=False, stealth=False)
setVertices(value, log=None, operation=False, stealth=False)
setVolume(volume)[source]
setWidth(value, log=None, operation=False, stealth=False)
setWin(value, log=None, operation=False, stealth=False)
property size

The size (width, height) of the stimulus in the stimulus units

Value should be x,y-pair, scalar (applies to both dimensions) or None (resets to default). Operations are supported.

Sizes can be negative (causing a mirror-image reversal) and can extend beyond the window.

Example:

stim.size = 0.8  # Set size to (xsize, ysize) = (0.8, 0.8)
print(stim.size)  # Outputs array([0.8, 0.8])
stim.size += (0.5, -0.5)  # make wider and flatter: (1.3, 0.3)

Tip: if you can see the actual pixel range this corresponds to by looking at stim._sizeRendered

stop(log=True)[source]

Stop the current point in the movie (sound will stop, current frame will not advance). Once stopped the movie cannot be restarted - it must be loaded again. Use pause() if you may need to restart the movie.

texRes

Power-of-two int. Sets the resolution of the mask and texture. texRes is overridden if an array or image is provided as mask.

Operations supported.

property units
updateOpacity()

Placeholder method to update colours when set externally, for example updating the pallette attribute of a textbox.

property vertices
property verticesPix

This determines the coordinates of the vertices for the current stimulus in pixels, accounting for size, ori, pos and units

property width
property win

The Window object in which the stimulus will be rendered by default. (required)

Example, drawing same stimulus in two different windows and display simultaneously. Assuming that you have two windows and a stimulus (win1, win2 and stim):

stim.win = win1  # stimulus will be drawn in win1
stim.draw()  # stimulus is now drawn to win1
stim.win = win2  # stimulus will be drawn in win2
stim.draw()  # it is now drawn in win2
win1.flip(waitBlanking=False)  # do not wait for next
             # monitor update
win2.flip()  # wait for vertical blanking.

Note that this just changes default window for stimulus.

You could also specify window-to-draw-to when drawing:

stim.draw(win1)
stim.draw(win2)

Back to top