Onset and offset timestamps for videos

OS: macOS Catalina 10.15.4
PsychoPy version: 2020.1.2
Standard Standalone: YES

What are you trying to achieve?:
In an experiment I have videos of different lengths. I need to know at what moment a video started playing and at what moment it ended. I need this infomration to calculate its duration and adjust RTs accordingly. How can I get these two timestamps?

Best,
Miguel

Isn’t this automatic when you have “Save onset/offset times” ticked?

Thank you for your message.

When save onset/offset times times is ticked in the options of the video component, only onset times of the videos are saved in the CSV file under the header myVideoComponent.started. However, the values for the offset times of the videos are not saved. The values for the header myVideoComponent.stopped are always equal to “none” even though the videos finish playing and disappear from the screen. How can I make the offet time to appear in the CSV file?

Nevertheless, getting those values in a CSV is not my specific goal. I need to use the onset/offset times within the experiment to calculate RTs as they are taking place in each trial (not after people had finished taking the test).

Furthermore, I compared the onset time of the video saved in the CSV file to the onset of the trial and I found an important difference. While the time of globalClock.getTime() at the beginning of the trial is 19.466, the value of the onset of the video in the CSV file is 21.133. That’s around 1.5 seconds of delay, which is ok in the case of my experiment. I only need to know during the experiment at what exact moment the video started playing and and what time it ended so that I can calculate the RTs when each trial ends.

Is there a way to get the onset/offest times of videos using a code component in the builder?

I tried using the names of the columns in the CSV file but this resulted in an error because those attributes are not defined for the video components.

print(myVideoComponent.started)
print(myVideoComponent.stopped)

Best,
Miguel

Try putting the following into Each Frame

if logged == 0:
     print('TrialStart: '+globalClock.getTime())
     logged = 1
elif myVideoComponent.status == STARTED and logged == 1:
     print('Started: '+globalClock.getTime())
     logged = 2
elif myVideoComponent.status == FINISHED and logged == 2:
     print('Stopped: '+globalClock.getTime())
     logged = 3
   

It throws an error because “logged” is not defined.

You need logged = 0 in Begin Experiment

Indeed, getting the onset/offset times by using the code you suggested works well. I confronted the length of the video using the printed timestamps and the length of that specif video in a movie editor software ad it pretty much similar :slight_smile:

I only had to convert the time stamps to strings to be able to print them.

TrialStart: 8.145263690967113
Started: 8.172083146171644
Stopped: 14.235821316950023

I also compared these numbers with the onset time in the CSV file. The onset time there is quite different: 17.9475. Here is a screenshot of the relevant part of the CSV file. Each row in it refers to a different video played. I think there is something to fix here?

Thank you for the help!

Miguel

I assume they must be from different clocks. Perhaps use a stopwatch to try to work out what the start points for each one are…e.g. resources starting to download, starting experiment, first routine started.

I think that’s very possible. People using the onset/offset times of the CSV file should be aware that those time stamps do not correspond to the time of the Global Clock.

Not knowing it may produce some serious problems in their analysis of the data. I think the onset/offset times in the CVS should be all taken from the Global Clock, as it is the one that people can rely on for getting time stamps (as you did in your suggestion).

Hi!

I followed this thread with interest as I’m having a similar issue with the Builder. My experiment also contains movie stimuli (around 2 to 4 min) and although I’ve ticked the ‘Save onset/offset times’ option, this does not appear in the data file (all the other onset/offset times of stimuli save so it might be an issue with the movie stim?).
Has anyone come across this issue for Builder? I’m happy to try other code component to get the start/stop time of the movies but would like to understand why the ‘save onset/offset times’ doesn’t work automatically for the movie stimuli, as this would be the easiest option…

I’m running the latest version of Psychopy on Windows.
Thank you!

1 Like

@alicealbertinidrew No idea why the onset and offset times do not appear in the data file. However, you need to keep in mind that using onset and offset times are not reliable methods to do calculations related to the length of the video. This is because sometimes, for some reason I do not know, videos get played at a lower speed than the normal one. In these case, if you use the onset and offset times to calculate the length of the video, the length of the video would seem to be longer than it really is.

Only use onset and offset times when you are interested in clocking things that happened before or after the video. For things time-locked to the video while it is playing use the timestamps. More information about it can be found in this thread: Onset/offset times of the video stimuli are not saving - #2 by miguel_santin

Cheers!

Hi @miguel_santin

Thanks very much for your much appreciated response! I tried to use the timestamps but did not see the corresponding times… maybe I used it wrong or am not looking for the resulting stamps in the right place? My movie stimuli is called Clip_0 and my routine is called block_0, I used the routine clock rather than the global clock since it is more relevant for me.

logged = 0
Each Frame
if logged == 0:
print('TrialStart: ',block_0Clock.getTime())
logged = 1
elif Clip_0.status == PLAYING and logged == 1:
print('Start: ', int(block_0Clock.getTime()))
logged = 2
elif Clip_0.status == STOPPED and logged == 2:
print('Stop: ', int(block_0Clock.getTime()))
logged = 3

In my experiment I have RTs during the movie stimuli, so it’s important that I know if the movie the participants see is in fact longer than the actual movie length so that I can adjust RTs, I understand this can sometimes happen with dropped frames etc…

About myVideo.getCurrentFrameTime() can this be used to save the start/stop time? I tried it as shown below but was once again unsuccessful as I get the error: ‘Clip_0_Start’ is not defined…

if Clip_0.status==PLAYING:
    Clip_0_Start = Clip_0.getCurrentFrameTime()
thisExp.addData("Clip_0_Start",Clip_0_Start);

if Clip_0.status==STOPPED:
    Clip_0_Stop = Clip_0.getCurrentFrameTime()
thisExp.addData("Clip_0_Stop",Clip_0_Stop);

Thanks again for your valuable help,
Alice

Hi, sorry if I’m annoying with this but actually, I have a more general concern about the accumulated lag in movie stimuli and instead of finding a way to control for it, I think I’m more interested in trying to get rid of it or have information about what is happening when a movie stimulus accumulates delay. I’ve seen some discussions topics about this but all are more concerned with controlling for the delay rather than getting rid of it (which makes sense of course since it’s probably hard to get rid of the delay completely).

Even locally, my movie stimuli seem to be playing at a lower speed and are therefore resulting as about 0.4 seconds longer than their actual length. This delay is of course invisible to the naked eye. Is it possible to know where the delay is being accumulated? Since my task involves free response during the movie, I want to know that the mouse timestamp corresponds to the same time stamp in the movie (0.4 s doesn’t seem like much but it can throw off my results, as it’s RT).

@Jon do you know why longish movie stimuli accumulate lags? Is there any way to know where these lags happen? I don’t know much about this but say, for instance the lag is of 0.4 s, is it realistic to assume that the lag is distributed evenly throughout the movie time? or is it incremental? Could there be a way to, a posteriori (knowing the lag for every movie) go back and adjust the RTs accordingly?

Thanks for any insight,
Best,
Alice

1 Like