Video example

23 views
Skip to first unread message

Finn Årup Nielsen

unread,
Jun 12, 2015, 10:50:07 AM6/12/15
to expyrime...@googlegroups.com


Are there any examples or tutorials with the use of video? I have a 10 second video. It should be played like [video, fixation cross, video, fixation cross, ...]. I see no video and am unsure about the way to use the present, play and update methods.

best regards
Finn Årup Nielsen
http://people.compute.dtu.dk/faan/

Florian Krause

unread,
Jun 15, 2015, 4:49:32 AM6/15/15
to expyrime...@googlegroups.com
Dear Finn,

The new version of Expyriment (which will be released very soon) will have some more information about using video in the documentation.

Here is a quick introduction into the topic:

1) The first thing to understand is that Expyriment only plays MPEG1 videos with MP3 audio right now (and unfortunately, the Pygame backend that is responsible for video playback seems to be very picky on the details of this).
To encode any video into the correct format, you can use ffmpeg (https://www.ffmpeg.org) and convert in the following way:

    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.
    
2) Once you have the video in the correct format, you can create a video object:

    my_video = expyriment.stimuli.Video("filename")

3) If the video has sound, too, then you need to (temporarily) stop the audio system (such that the video system can play sound):

    expyriment.control.stop_audiosystem()

4) Preload the video into memory, before playing it back:

    my_video.preload()

5) Understanding the various methods of the video object:

play() will simply start video playback in the background. This has no effect on the screen, no frames from the video are presented automatically. Use this, if you want to get each frame from the video manually and present them at your liking (using the update() method, see below).

present() will do a bit more. It will start video playback and it will present the very first frame of the video onto the screen for you. Just like present method of other visual stimuli in Expyriment, the method will only return, once the stimulus (in that case the first video frame) has actually been presented on the screen, giving you important information about when the participants are actually starting to see your video.

update() will take the current frame (from a playing video) and present it to the screen. As with present(), the method blocks until the frame is actually visible on the screen.

wait_end() will basically do, what update does, but continuously, for each frame, until the end of the video.

wait_frame() is the same as wait_end, but up to a specified frame only, instead until the end of the video.

Taken together, what you usually want is a combination of present() and wait_end().

Coming back to your example, the code would look something like this:

    fixcross = expyriment.stimuli.FixCross()
    videos = [expyriment.stimuli.Video("file1"),
              expyriment.stimuli.Video("file2"),
              ...]
    
    expyriment.control.stop_audiosystem()
    
    for v in videos:
        v.preload()

    for v in videos:
        fixcross.present()
        exp.clock.wait(1000)
        v.present()
        v.wait_end()


I hope this little introduction helped. Let me know if you have any further questions.

All the best,
Florian



--
You received this message because you are subscribed to the Google Groups "expyriment-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to expyriment-use...@googlegroups.com.
To post to this group, send email to expyrime...@googlegroups.com.
Visit this group at http://groups.google.com/group/expyriment-users.
For more options, visit https://groups.google.com/d/optout.



--
www.fladd.de - Homepage of Florian Krause

Oliver Lindemann

unread,
Jun 16, 2015, 11:00:34 AM6/16/15
to expyrime...@googlegroups.com
Thanks for the nice tutorial!

Oliver
--
Dr. Oliver Lindemann
Division of Cognitive Science
University of Potsdam


Karl - Liebknecht Str. 24/25, Building 14, 14476 Potsdam, Germany
Tel: +49 - 331 - 977 2915, Fax: +49 - 331 - 977 2794
Room: 6.24, Building 14, http://www.cognitive-psychology.eu/lindemann
Reply all
Reply to author
Forward
0 new messages