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!

Notes

When the backend is set to "pygame", only MPEG-1 videos 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.

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

Create a video stimulus.

Parameters:
filenamestr

filename (incl. path) of the video

backendstr, optional

‘mediadecoder’ or ‘pygame’

position(int, int), optional

position of the stimulus

Notes

When the backend is set to "pygame", only MPEG-1 videos 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.

property filename

Getter for filename.

forward(seconds)

Advance playback position.

Parameters:
secondsint

amount to advance (in seconds)

Notes

When the backend is set to "pygame", 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.

property frame

Property to get the current available video frame.

property has_audio

Property to check if video file has audio information.

property has_video

Property to check if video fifle has video information.

property id

Getter for id.

property is_paused

Property to check if video is paused.

property is_playing

Property to check if video is playing.

property is_preloaded

Getter for is_preloaded.

property length

Property to get the length of the video.

property logging

Getter for logging.

property 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, audio=True)

Play the video stimulus from the current position.

Parameters:
loopbool, optional

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

log_event_tagnumeral 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

audiobool, optional

whether audio of video (if present) should be played (default=True)

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.

property position

Getter for position.

preload()

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

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.

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

Rewind to start of video stimulus.

set_logging(onoff)

Set logging of this object on or off

Parameters:
onoffbool

set logging on (True) or off (False)

property size

Property to get the resolution of the video.

stop()

Stop the video stimulus.

property 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_functionfunction, optional

function to repeatedly execute during waiting loop

process_control_eventsbool, 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 keyboard 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:
frameint

number of the frame to stop after

callback_functionfunction, optional

function to repeatedly execute during waiting loop

process_control_eventsbool, 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 keyboard 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()