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 = expyriment.design.Experiment(name="First Experiment")
expyriment.control.initialize(exp)

block_one = expyriment.design.Block(name="Block_1")

trial_one = expyriment.design.Trial()
trial_two = expyriment.design.Trial()
trial_three = expyriment.design.Trial()
trial_four = expyriment.design.Trial()

circle_s = expyriment.stimuli.Video('Circle_S.mp4')
circle_s.preload()
circle_s.play()
circle_s.present()
video_presentation_time = exp.clock.time
circle_s.wait_end()
circle_s.stop()

circle_e = expyriment.stimuli.Video('Circle_E.mp4')
circle_e.preload()
circle_e.play()
circle_e.present()
video_presentation_time = exp.clock.time
circle_e.wait_end()
circle_e.stop()

gabor_s = expyriment.stimuli.Video('Gabor_S.mp4')
gabor_s.preload()
gabor_s.play()
gabor_s.present()
video_presentation_time = exp.clock.time
gabor_s.wait_end()
gabor_s.stop()

gabor_e = expyriment.stimuli.Video('Gabor_E.mp4')
gabor_e.preloas()
gabor_e.play()
gabor_e.present()
video_presentation_time = exp.clock.time
gabor_e.wait_end()
gabor_e.stop()

trial_one.add_stimulus(circle_s)
trial_two.add_stimulus(circle_e)
trial_three.add_stimulus(gabor_s)
trial_four.add_stimulus(gabor_e)

block_one.add_trial(trial_one)
block_one.add_trial(trial_two)
block_one.add_trial(trial_three)
block_one.add_trial(trial_four)

exp.add_block(block_one)

expyriment.control.start()
for block in exp.blocks:
for trial in block.trials:
trial.stimuli[0].present()
exp.clock.wait(1000)

expyriment.control.end()`

Also; the error I get looks like :

Traceback (most recent call last): File "test.py", line 20, in <module> circle_s.preload() File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/_video.py", line 303, in preload videorenderfunc=self._update_surface) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/mediadecoder/decoder.py", line 73, in __init__ if not self.load_media(mediafile, play_audio): File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/mediadecoder/decoder.py", 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/VideoFileClip.py", line 91, in __init__ fps_source=fps_source) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/moviepy/video/io/ffmpeg_reader.py", line 33, in __init__ fps_source) File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/moviepy/video/io/ffmpeg_reader.py", 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,

Comments

  • 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 (github.com/expyriment/expyriment/) or you can install a beta version of Expyriment (https://github.com/expyriment/expyriment/releases/tag/v0.9.1b2).

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

    Florian Krause (Developer)
    http://www.expyriment.org

  • 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 "Pilot_test.py", line 24, in <module>
        circle_s.present()
      File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/_video.py", line 496, in present
        self.update()
      File "/home/jrdnalvs/anaconda3/envs/expyriment/lib/python3.4/site-packages/expyriment/stimuli/_video.py", 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/_visual.py", 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)
    http://www.expyriment.org

  • 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 (expyriment-master.zip) file. You install it then in the standard way to install Python packages: pip install expyriment-master.zip (assuming you are in the directory wherethat file is located).

    Florian Krause (Developer)
    http://www.expyriment.org

  • 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)
    http://www.expyriment.org

  • 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)
    http://www.expyriment.org

Sign In or Register to comment.