expyriment.stimuli.Video

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

A class implementing a general video stimulus.

This class uses a background thread for playing the video!

Only MPEG-1 movies with MP3 audio are supported. You can use ffmpeg (www.ffmpeg.org) to convert from other formats:

ffmpeg -i <inputfile> -vcodec mpeg1video -acodec libmp3lame -intra -qscale 2 <outputfile.mpg>

The -qscale option is the quality setting. It can take values from 1 to 31. 1 is the best quality, but big file size. 31 is the worst quality, but small file size. Play around with this setting to get a good balance between quality and file size.

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.

Methods

__init__(filename, position=None)[source]

Create a video stimulus.

Parameters:

filename : str

filename (incl. path) of the video

position : (int, int), optional

position of the stimulus

Notes

Only MPEG-1 movies with MP3 audio are supported. You can use ffmpeg (www.ffmpeg.org) to convert from other formats:

ffmpeg -i <inputfile> -vcodec mpeg1video -acodec libmp3lame -intra -qscale 2 <outputfile.mpg>

The -qscale option is the quality setting. It can take values from 1 to 31. 1 is the best quality, but big file size. 31 is the worst quality, but small file size. Play around with this setting to get a good balance between quality and file size.

copy()

Return a deep copy of the stimulus.

filename

Getter for filename.

forward(seconds)[source]

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.

logging

Getter for logging.

pause()[source]

Pause the video stimulus.

play()[source]

Play the video stimulus from the current position.

Notes

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.

position

Getter for position.

preload()[source]

Preload stimulus to memory.

Notes

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() ).

present()[source]

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.

Notes

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.

rewind()[source]

Rewind to start of video stimulus.

set_logging(onoff)

Set logging of this object on or off

Parameters:

onoff : bool

set logging on (True) or off (False)

Notes

See also design.experiment.set_log_level fur further information about event logging.

size

Property to get the resolution of the movie.

stop()[source]

Stop the video stimulus.

time

Property to get the current playback time.

unload(**kwargs)[source]

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()[source]

Update the screen on each new frame.

wait_end(last_frame=None)[source]

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)[source]

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 == ...