Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Building experiment with videos

Hey everyone,

Following a recent mail exchange with Florian, I tranfer my issues to the forum to get some insight from the community.

For my first experiment I need to design an experiment using moving stimuli and I have to implement an expending or concentric movement on a circle (increase and decreasing the diameter of the circle in a way) and on annular gratings (Gabor Patch). So we conclude that it would be easier to just create videos of the stimuli and to present them.

So i went over the begginer's tutorial and tried to follow this example to create a very simple, 1 block, 4 stimuli experiment. I also follow the instruction about playing videos but I'm unsure on how to build and on how to code this efficiently. I coded the following experiment this morning but only return an error during the preloading of the video.

Anyway, I'll join what I coded so we can share thoughts and ways to improve things so that I can learn to efficiently code experiments in the future.

`import expyriment

exp ="First Experiment")

block_one ="Block_1")

trial_one =
trial_two =
trial_three =
trial_four =

circle_s = expyriment.stimuli.Video('Circle_S.mp4')
video_presentation_time = exp.clock.time

circle_e = expyriment.stimuli.Video('Circle_E.mp4')
video_presentation_time = exp.clock.time

gabor_s = expyriment.stimuli.Video('Gabor_S.mp4')
video_presentation_time = exp.clock.time

gabor_e = expyriment.stimuli.Video('Gabor_E.mp4')
video_presentation_time = exp.clock.time




for block in exp.blocks:
for trial in block.trials:


Also; the error I get looks like :

Traceback (most recent call last): File "", line 20, in <module> circle_s.preload() File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/", line 303, in preload videorenderfunc=self._update_surface) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/mediadecoder/", line 73, in __init__ if not self.load_media(mediafile, play_audio): File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/mediadecoder/", line 162, in load_media self.clip = VideoFileClip(mediafile, audio=play_audio) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/moviepy/video/io/", line 91, in __init__ fps_source=fps_source) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/moviepy/video/io/", line 33, in __init__ fps_source) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/moviepy/video/io/", line 243, in ffmpeg_parse_infos is_GIF = filename.endswith('.gif') TypeError: endswith first arg must be bytes or a tuple of bytes, not str

thanks again for your time,


  • The error is related to a bug. This has been fixed, but no official new version of Expyriment has been released yet.

    You can either use the development snapshot directly from the repository ( or you can install a beta version of Expyriment (

    The new official release of Expyriment (0.9.1) will include this fix.

    Florian Krause (Developer)

  • Hi !

    Thanks for that, switching to the beta version fixed the problem.
    Now during the preparation of the experiment I get this error message :

    Traceback (most recent call last):
      File "", line 24, in <module>
      File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/", line 496, in present
      File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/", line 514, in update
        self._surface, quadDims=(1,1,1,1), position=self._position)
      File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/", line 62, in __init__
        surface_size = surface.get_size()
    AttributeError: 'numpy.ndarray' object has no attribute 'get_size'

    The video file is in .mp4, so the experiment video module should be able to launch it.
    Is it because of a mistake in the experiment coding ? Should I specify the size of the screen/canvas to presents the video on ?

    Thanks again,

  • Ah, now you ironically ran into another bug. This bug, however, is also fixed already, but not in the beta yet. We will release a new beta with the fix soon, but for now, you can install Expyriment directly from the repository. That should work.

    Florian Krause (Developer)

  • Hi !
    Is installing from the repository = git clone from the git hub page in my environment ? Because if yes it still really doesn't work (now I return the error that design isn't a module in expyriment). If not there's no real documentation on how to do that in the installation docs pages. Can you help/guide through it ?

  • Hi,

    easiest is to just download the zip ( file. You install it then in the standard way to install Python packages: pip install (assuming you are in the directory wherethat file is located).

    Florian Krause (Developer)

  • Hi ! Thanks for that !

    It's now working, the videos are loading and are presented so I can go back to my experiment design.
    One question now would be : how do I get a smooth rendering of the videos ? Because it keeps on dropping frames resulting in a non smooth video and poor quality.

  • What resolution are the videos in? On the machines I tested it on (Windows, Mac, Linux) I could play full HD videos without dropping any frames.

    How exactly are you showing the videos? Can you post your code?

    Florian Krause (Developer)

  • The videos were created in 4K res.

    For now I just tested out the basic way of preload, play, present, stop & unload. Now I'm trying to create trials that will present 100+ the videos to present in one a block.

  • Since the videos are played without hardware acceleration, 4K can indeed lead to dropped frames, I am not too surprised by this. It's a very high resolution. You might consider recoding to full HD (or try with a more powerful machine; i.e. with a more powerful CPU). Maybe changing the video format can also help (to something uncrompressed), but I am not sure about this.

    Florian Krause (Developer)

Sign In or Register to comment.