Introduction

Since version 3.1.0 you can play videos within experiment.

You can also play videos in surveys.

Here are some important tips:

  • You should not upload your video clips to PsyToolkit, but to the Google or Dropbox drive (or somewhere else), see below for howto.

  • Before the experiment starts, the video clips are loaded into the participant’s computer — they should ideally not be too big

  • Make sure the videos are of a reasonable size. You can resize them, but smaller videos load quicker

  • Videos can be shown similarly to other stimuli

The details

Telling PsyToolkit where the video is stored

You need to create a videos section. In there, you need to specify the name of your video and an Internet link. In this case, I have uploaded two clips via Dropbox and shared the uploaded file with anyone with the link. I just got the link and added it to the scrip.

The video link you get can be just copied. In reality, PsyToolkit will itself change ending dl=0 with raw=1
Loading the video
videos
  clip1 https://www.dropbox.com/s/kzo7sx7hkdai16i/beetle.mp4?dl=0
  clip2 https://www.dropbox.com/s/bzbs6qpk7ht9yyu/frog.mp4?dl=0

Making a video smaller makes sense

You can use video editing software to make your video smaller. For example, the default resolution for experiments is only 800x600, while videos often come in a much larger resolution. Even short videos can be big files. But you can make them much smaller. For example, Kdenlive and Openshot are free video editors. Load in your video clip and render it on a smaller resolution (e.g., 500x300 pixels). That makes a huge difference.

The video clips in the demonstration below were taken on a mobile phone and edited with Kdenlive. They are both quite small files, which means participants do not need to wait long before they are loaded.

Starting to play the video in a trial

In your task, you use show video to show the video similar to showing, for example, a bitmap or a rectangle.

In the example below, without further parameters, it simply plays the video

Simplest example of video play in task
task my_task
  show video clip1

You can give show video all sorts of parameters to resize the video, and to show it on different locations. Here is an example that resizes the video to 50% of its normal size.

Simplest example of video play in task
task my_task
  show video clip2 0 0 50

Play sound or not

Use the videocontrol instruction

Example of how to mute your video
task my_task
  videocontrol clip1 mute

Rewind and pause

Example of how to mute your video
task my_task
  videocontrol clip1 rewind
Example of how to pause your video
task my_task
  videocontrol clip1 pause

Stop and clear a video from screen

For this, you simply use the clear instruction as for other stimuli (see the demonstration code below)

Keep looping or not

You can keep repeating your video once it reached the end.

Example of how to keep your video playing forever
task my_task
  videocontrol clip1 loop

Demonstration

In the demonstration, you see how two video clips are being loaded and played

The PsyToolkit code

videos (1)
  clip1 https://www.dropbox.com/s/kzo7sx7hkdai16i/beetle.mp4?dl=0 (2)
  clip2 https://www.dropbox.com/s/bzbs6qpk7ht9yyu/frog.mp4?dl=0 (3)

task videoplay (4)
  keys b (5)
  videocontrol clip2 mute (6)
  videocontrol clip1 loop (7)
  videocontrol clip2 loop (8)
  show video clip1 -200 0 50 (9)
  show video clip2  200 0 50 (10)
  delay 2000 (11)
  show text "now click the B key to end" 0 -250  (12)
  readkey 1 10000  (13)
  clear -1 -2  (14)

block vi   (15)
  tasklist   (16)
     videoplay 1   (17)
  end   (18)
1 We need a videos section to tell PsyToolkit where the videos are
2 You can choose a name, followed by an Internet URL. In this case, it is the shared link you get from Dropbox. Internally, PsyToolkit will replace the dl=0 with raw=1 to make sure it is downloadable
3 Same for a separate video clip. You can give any name to these clips, just as for bitmap stimuli
4 Now you have a task section, we create a simple demo task
5 We will use one keyboard button for this demo, the b
6 We set clip2, which has sound, to mute, so that we do not need to listen to it. Clip1 just happens to have no sound anyway
7 We make sure the clip keeps repeating (loop)
8 Smae for clip2
9 Now we show clip1 200 pixels left from screen center. The 50 means that the video is scaled to 50% of its original size.
10 Now we show clip1 200 pixels right from screen center.
11 Do nothing for 2 seconds (2000 milliseconds)
12 Now we show a text giving an instruction to the participant
13 We wait for the key press
14 Now we clear the two last showed stimuli (we could also have written clear 1 2)
15 Now we start a block
16 We tell PsyToolkit what the tasks are
17 We have only one task and we use it 1 trial
18 End of tasklist