Response time during video display
Hi there,
I'm currently converting an old e-prime experiment to Opensesame and I'm struggling to handle response times during video presentations. I'm using the media_player_mpy plugin as suggested here. I found similar threads on the forum but I couldn't make it work.
The trial sequence is as follows: Fixation (keypress) - Video (1100ms; response with a keyrelease) - Blank screen (1000ms).
The video clips are exactly 1100 ms long and in each of these clips, one of two events (let's call them 'event A' and 'event B') can occur precisely at 500 ms. Participants are asked to release '1' or '2' in response to 'event A' or 'event B', respectively.
So, I'd like to record participants' response times to these events (with a timeout of 1500 ms from the 'event' onset); so responses should be possible as soon as the video starts with a timeout that overlaps with the blank screen (hope that's clear). I tried several things (e.g., setting the duration to keypress doesn't seem to record anything). Any hints on this ?
Then, I don't exactly know how to handle this 'keypress'/'keyrelease' issue ... I found this on an existing thread but I don't really know how to implement it properly in the experimental sequence ...
import pygame key = None start_time = self.time() while key == None: time = self.time() for event in pygame.event.get(): if event.type == pygame.KEYUP: key = event.key rt = time - start_time exp.set('keyreleaseRT', rt) print '%s was released after %d ms' % (key, rt)
Any advice would be greatly appreciated ! Thanks a lot !
CL
Comments
EDIT:
Some progress have been made based on this thread
By adding this in the python code section of the video object, responses are collected as long as they are given during the video playback.
if event: key = event[1] if var.correct_response == key: correct=1 else: correct=0 responses.add(response=key, correct=correct, response_time=clock.time()-var.time_video) continue_playback = True
The problem is that responses should also be possible once the video has stopped playing (during the 1000 ms blank screen). As it is, 'nothing' is collected and for those trials where responses are given after the end of the video, the same response times as the trial before are collected. Any ideas ?
Thanks
Hi Cletess,
Can you print the rest of the code that you use? In general, extending the response collection period, requires only to loop a little longer before proceding with the next trial. And optionally, change the stuff that is presented on the screen during this interval. Once I know how you present everything, I can probably also give you more specific suggestions how you could implement it.
Eduard
Hi again and sorry for the delay !
We made some changes on the paradigm and I took some time to read different threads on this forum. It appears (maybe I'm wrong) that for what I need, I'll have to use openCV to deal with the video presentation. Let me explain:
pygame.draw.rect
command in opencv.I saw that this code was suggested in a previous post:
For now, the screen just goes black for each trial and I can't display the videos. No specific error message. It seems that the value of 'Success' is always False therefore breaking the loop for some reasons. Also, I'm not sure on how to initiate the loop with a key press and to record the reaction time until it is released (the videos must not be stopped once the key is released). I tried something but I'm not really sure it's even correct ...
Thanks a lot for your advice
Hi,
First, I haven't worked much with videos and not at all with OpenCV, so I can't help you with that. However, I think some of your questions are more general in nature. So, let's see whether I can help you.
This is rather simple. Basically, when a key is pressed you have something like
video.start()
which should also give a time stamp for when exactly this happened. If there is not time stamp sent automatically by calling 'video.start', you can add a line likestart_time = clock.time()
right before you start the video. Importantly, releasing the key shouldn't stop the video, which won't happen unless you write something like "if key is released, stop video playback". So, whenever the key is actually released, you can take a second time stamp. Later, when the trial is over (after all theloop
s), you can stop the video, by something like "video.stop()". Below the part of the code that would accomplish that (pretty much the same as what you already have had):The other issue, I don't know what is happening exactly. If you provide a working example (Opensesame file, incl. an example video), I'll gladly look into to it.
Eduard
Hi Eduard,
Many thanks for the prompt response ! This makes perfect sense. However, I noticed two things with this:
It requires a key to be pressed to initiate the video (which is what I want) but in order to get the release time, I have to press and release it again during the video playback otherwise I get the following error:
I'm assuming that the keydown command has to be within the video playback loop right ?
I'll look more into that !
EDIT:
Ok, so it seems to be related to how certain videos are encoded. Using the Xvid video codec package (https://www.xvid.com/) seems to solve the problem. The thing now is to figure out how to adapt the frame rate (videos are way too quick). I've read in another thread that it could be possible to achieve something like that using the self.sleep() thingy somewhere in the loop.
My question would be then: How accurate can we be in setting the frame rate using that option ? The videos I'm using have a framerate of exactly 20fps (I made them from different pictures using VirtualDub). This allows me to control the timing of specific events in the videos and to relate that to participants' response time. Any advice ?
EDIT 2:
Well, after some violent battles with the script, I think I managed to write something that fulfills my needs.
I think it could potentially be useful for others having similar problems so I post it here (any comments are greatly appreciated)
This script deals with video presentation using opencv (as suggested elsewhere on this forum).
This script will wait for a keypress before playing the video and record participants' reaction time when they release the key. Also, depending on participants' responses, we change the background color during video presentation (as a feedback). As the video playback script did not respect the video files 20Hz frame rate (they were way faster), we used the tick_busy_loop(20) to fix the frame rate at 20 fps. It seems to work that way !
Any comments are greatly appreciated (there might be errors :>) and I hope this will help others
Hi cletess,
Thanks for sharing!
Using video in an experiment can be (always is) very challenging. The website www.videohelp.com can be informative. And the tool XMedia Recode could be handy to convert all videos to the same format.
Best,
Jarik