expyriment.stimuli.Video

class expyriment.stimuli.Video(filename, position=None)

A class implementing a general video stimulus.

This class uses a background thread for playing the video! According to the Pygame documentation MPEG-1 movies are supported. However, it seems that Pygame’s video support is quite limited and poor.

When the audio from the video should be played as well, the audiosystem has to be stopped (by calling expyriment.control.stop_audiosystem() ) BEFORE the video stimulus is preloaded! After the stimulus has been played the audiosystem can be started again (by calling expyriment.control.start_audiosystem() ).

When showing videos in large dimensions, and your computer is not fast enough, frames might be dropped! When using Video.wait_frame() or Video.wait_end(), dropped video frames will be reported and logged.

This module will be exchanged with a more capable one in the long run.

Methods

__init__(filename, position=None)

Create a video stimulus.

Parameters :

filename : str

filename (incl. path) of the video

position : (int, int), optional

position of the stimulus

copy()

Return a deep copy of the stimulus.

filename

Getter for filename.

forward(seconds)

Advance playback position.

This will not forward immediately, but play a short period of the beginning of the file! This is a Pygame issue which we cannot fix right now.

Parameters :

seconds : int

amount to advance (in seconds)

frame

Property to get the current frame.

has_audio

Property to check if movie has audio.

has_video

Property to check if movie has video.

id

Getter for id.

is_playing

Property to check if movie is playing.

is_preloaded

Getter for is_preloaded.

length

Property to get the length of the movie.

pause()

Pause the video stimulus.

play()

Play the video stimulus from the current position.

position

Getter for position.

preload()

Preload stimulus to memory.

present()

Play the video and present current frame.

This method starts video playback and presents a single frame (the current one). When using OpenGL, the method blocks until this frame is actually being written to the screen.

rewind()

Rewind to start of video stimulus.

size

Property to get the resolution of the movie.

stop()

Stop the video stimulus.

time

Property to get the current playback time.

unload()

Unload stimulus from memory.

This removes the reference to the object in memory. It is up to the garbage collector to actually remove it from memory.

update()

Update the screen on each new frame.

wait_end(last_frame=None)

Wait until video has ended and constantly update screen.

Notes

This will also check for control keys (quit and pause). Thus, keyboard events will be cleared from the cue and cannot be received by a Keyboard().check() anymore! If keybaord events should not be cleared, a loop has to be created manually like:

movie.present()
while movie.is_playing:
    movie.update()
    key = exp.keyboard.check()
    if key == ...
wait_frame(frame)

Wait until certain frame was shown and constantly update screen.

Parameters :

frame : int

number of the frame to stop after

Notes

This function will also check for control keys (quit and pause). Thus, keyboard events will be cleared from the cue and cannot be received by a Keyboard().check() anymore! If keybaord events should not be cleared, a loop has to be created manually like:

movie.present()
    while movie.is_playing:
    movie.update()
    key = exp.keyboard.check()
    if key == ...

Previous topic

expyriment.stimuli.Tone

Next topic

Useful Expyriment tools and helper functions

This Page