expyriment.stimuli.Video

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

A class implementing a general video stimulus.

This class uses a background thread for playing the video!

__init__(filename, backend=None, position=None)

Create a video stimulus.

Parameters:

filename : str

filename (incl. path) of the video

backend : str, optional

‘mediadecoder’ or ‘pygame’

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.

Parameters:

seconds : int

amount to advance (in seconds)

frame

Property to get the current available video frame.

has_audio

Property to check if video file has audio information.

has_video

Property to check if video fifle has video information.

id

Getter for id.

is_paused

Property to check if video is paused.

is_playing

Property to check if video is playing.

is_preloaded

Getter for is_preloaded.

length

Property to get the length of the video.

logging

Getter for logging.

new_frame_available

Property to check if new video frame is available to render.

pause()

Pause the video stimulus.

play(loop=False, log_event_tag=None)

Play the video stimulus from the current position.

Parameters:

loop : bool, optional

loop video playback (will be ignored when using play to unpause!)

log_event_tag : numeral or string, optional

if log_event_tag is defined and if logging is switched on for this stimulus (default), a summary of the inter-event-intervalls are appended at the end of the event file

position

Getter for position.

preload()

Preload stimulus to memory.

present()

Present current frame.

This method waits for the next frame and presents it on the screen. When using OpenGL, the method blocks until this frame is actually being written to the screen.

rewind()

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

stop()

Stop the video stimulus.

time

Property to get the current playback time.

unload(**kwargs)

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.

wait_end(callback_function=None, process_control_events=True)

Wait until video has ended and constantly update screen.

Parameters:

callback_function : function, optional

function to repeatedly execute during waiting loop

process_control_events : bool, optional

process io.Keyboard.process_control_keys() and io.Mouse.process_quit_event() (default = True)

Notes

This will also by default process control events (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:

video.present()
while video.is_playing and video.frame < frame:
    while not video.new_frame_available:
        key = exp.keyboard.check()
        if key == ...
    video.update()
video.stop()
wait_frame(frame, callback_function=None, process_control_events=True)

Wait until certain frame was shown and constantly update screen.

Parameters:

frame : int

number of the frame to stop after

callback_function : function, optional

function to repeatedly execute during waiting loop

process_control_events : bool, optional

process io.Keyboard.process_control_keys() and io.Mouse.process_quit_event() (default = True)

Notes

This will also by default process control events (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:

video.present()
while video.is_playing and video.frame < frame:
    while not video.new_frame_available:
        key = exp.keyboard.check()
        if key == ...
    video.update()
video.stop()