Movie presentation using for loop

Hi all,

I have an issue with movie presentation in PTB. I am using Matlab R2021a and PTB 3.0.17 on a Windows 10 operating system.

What I want to do is the following:

  1. I start a video with the duration of several minutes.
  2. I want to squeeze a number of x trials into this video. During the trials I overlay the currently running video with additional images.
  3. Each trial has the same structure. So I am wondering if I could iterate through trial 1:x while I continue presenting the video.

My current approach is to make a dummy variable that counts the number of texture I am currently at (so the textures increase while the video plays). Then I define ranges for my single trials in which my additional actions should happen. However, triggering the trials using a for loop results in error messages.

This is the structure of my code:

movie = Screen(‘OpenMovie’, win, movname);
rate = 1;
Screen(‘PlayMovie’, movie, rate);

tex_num = 0

while ~KbCheck

tex = Screen(‘GetMovieImage’, win, movie);

if tex<=0
break;
end

tex_num = tex_num + 1;

if tex_num < 100

  Screen('PlayMovie', movie, rate);
  Screen('DrawTexture', win, tex);
  Screen('Flip', win);
  Screen('Close', tex);

  temp_low = tex_num;
  temp_high= tex_num + 15;

  if tex<=0
      break;
  end

%%% trial 1

elseif tex_num > temp_low && tex_num < temp_high

  additional.image = Screen('MakeTexture', win, myimage);
  Screen('DrawTexture', win, tex);
  Screen('DrawTexture',  win, additional.image);
  Screen('Flip', parm.exp.scr.w);
  Screen('Close', tex);     

  temp_low_1 = tex_num;
  temp_high_1 = tex_num + 15;
 
  if tex<=0
            break;
  end

%%% trial 2

elseif tex_num > temp_low_1 && tex_num < temp_high_1

  additional.image = Screen('MakeTexture', win, myimage);
  Screen('DrawTexture', win, tex);
  Screen('DrawTexture',  win, additional.image);
  Screen('Flip', parm.exp.scr.w);
  Screen('Close', tex);     

  temp_low = tex_num;
  temp_high= tex_num + 15;
 
  if tex<=0
            break;
  end

etc.etc.

This is of course comletely unelegant. I don’t want to hard code every single trial but repeat the process over x trials.

I’m kind of stuck so I would really appreciate your advise!

Thanks a lot!

I did not go over your sample code carefully, but here is something I would suggest:

  1. If possible, you can MakeTextures for myimage before video starts. DrawTexture is fast, while MakeTexture can be slow, which can cause movie frames delay.

  2. Rather than counting movie tex number, it may be better to use GetSecs timestamps to start your image. You can plan your image onset in advance, relative to frame 1 of the movie.

  3. You may not need the multiple if-elseif block for trials, but just DrawTexture in the movie loop before Screen(‘Flip’). Of course you will need to decide how many frames you want myimage on the screen.

-Xiangrui

help PsychPaidSupportAndServices if you need up to one hour of professional help.
-mario