Fitting video playback on screen

MacOS, MatLab R2021b, Display Size: 13.3-inch (2560 × 1600)

Hi,

I have written a script to play a video file using PsychToolbox. The video plays and works exactly how I need it, however, the video appears slightly zoomed in and wont fit the screen.

Can anyone help me set the size of the video to how I need it?

I have attached that section of my code.

Thanks,
Kyle

Clip_1 = [PsychtoolboxRoot 'PsychDemos/MovieDemos/8.1.mov'];

% Wait until user releases keys on keyboard:
KbStrokeWait;

% Select screen for display of movie:
screenid = max(Screen('Screens'));

    % Open movie file:
    [movie] = Screen('OpenMovie', scrn, Clip_1);
    if imgw > w || imgh > h
            % Video frames too big to fit into window, so define size to be window size:
            dstRect = CenterRect((w / imgw) * [0, 0, imgw, imgh], Screen('Rect', win));
        else
            dstRect = [];
    end
    
    % Start playback engine:
    Screen('PlayMovie', movie, 1);
    
    % Playback loop: Runs until end of movie or keypress:
   while ~KbCheck
        % Wait for next movie frame, retrieve texture handle to it
        tex = Screen('GetMovieImage', scrn, movie);
        
        % Valid texture returned? A negative value means end of movie reached:
        if tex<=0
            % We're done, break out of loop:
           break;
        end
        
        % Draw the new texture immediately to screen:
        Screen('DrawTexture', scrn, tex);
        
        % Update display:
        Screen('Flip', scrn);
        
        % Release texture:
        Screen('Close', tex);
   end
    
    % Stop playback:
    Screen('PlayMovie', movie, 0);
    
    % Close movie:
    Screen('CloseMovie', movie);

dstRect determines how big (and where) the video is drawn, perhaps this is not set right for your video? Your code snippet does not show how both w and imgw are set, so guess something is wrong there (perhaps stale values)?

Thanks for your reply, I am pretty new to this so I don’t really know.

I’ve attached my full code below, it isn’t too long.

Any ideas from this would be appreciated.

Thanks,
Kyle

ListenChar(2); %stop input into MATLAB window

%generate random ID for ppts
a = [randperm(10,2)+47;randperm(26,2)+96];
b = char(a(:)');
c = convertCharsToStrings(b);

ScreenNumbers = Screen('Screens'); %find screens
OutScreen = max(ScreenNumbers); %output to max screen

Screen('Preference', 'SkipSyncTests', 1); %remove

[scrn, rect] = PsychImaging('OpenWindow',OutScreen, [175 175 175]);

Screen('TextSize',scrn,24); %Text Size
DrawFormattedText(scrn,['Thank you for taking part in this experiment. \n\n Please take time to read the information infront of you. \n\n Do not hesitate to ask any questions. \n\n Press any key to continue.'],'center','center');
    Screen('flip', scrn); %Show Text on Display

KbStrokeWait; %wait for any keypress, [],[0 0 800 600]
    DrawFormattedText(scrn, [b, '\n\n Your Unique Code is Displayed Above, \n\n Please Take Note of This. \n\n Press Any Key to Continue'], 'center', 'center')
    Screen('flip', scrn); %Show text

KbStrokeWait; %wait for any keypress
    DrawFormattedText(scrn,['You are about to be presented with a video. \n\n Please pay attention as you will be asked to recall events afterwards. \n\n When you are ready, press any key to play'], 'center', 'center');
    Screen('flip', scrn); %Show text

Clip_1 = [PsychtoolboxRoot 'PsychDemos/MovieDemos/8.1.mov'];

% Wait until user releases keys on keyboard:
KbStrokeWait;

% Select screen for display of movie:
screenid = max(Screen('Screens'));

    % Open movie file:
    [movie] = Screen('OpenMovie', scrn, Clip_1);
    
    % Start playback engine:
    Screen('PlayMovie', movie, 1);
    
    % Playback loop: Runs until end of movie or keypress:
   while ~KbCheck
        % Wait for next movie frame, retrieve texture handle to it
        tex = Screen('GetMovieImage', scrn, movie);
        
        % Valid texture returned? A negative value means end of movie reached:
        if tex<=0
            % We're done, break out of loop:
           break;
        end
        
        % Draw the new texture immediately to screen:
        Screen('DrawTexture', scrn, tex);
        
        % Update display:
        Screen('Flip', scrn);
        
        % Release texture:
        Screen('Close', tex);
   end
    
    % Stop playback:
    Screen('PlayMovie', movie, 0);
    
    % Close movie:
    Screen('CloseMovie', movie);

DrawFormattedText(scrn,['Please press and hold space for how long you believe the video lasted. '],'center','center');
    Screen('flip', scrn); %Show Text on Display
    KbTriggerWait(KbName(['space']));
    tic;
    KbReleaseWait;
    firstResponse = toc;
    DrawFormattedText(scrn,['+'],'center','center');
    Screen('flip', scrn); %Show Text on Display
    WaitSecs(1);
    
DrawFormattedText(scrn,['The next video will play now. '],'center','center');
    Screen('flip', scrn); %Show Text on Display
    WaitSecs(5);

Clip_2 = [PsychtoolboxRoot 'PsychDemos/MovieDemos/8.1.mov'];

% Select screen for display of movie:
screenid = max(Screen('Screens'));

    % Open movie file:
    [movie] = Screen('OpenMovie', scrn, Clip_2);
    
    % Start playback engine:
    Screen('PlayMovie', movie, 1);
    
    % Playback loop: Runs until end of movie or keypress:
    while ~KbCheck
        % Wait for next movie frame, retrieve texture handle to it
        tex = Screen('GetMovieImage', scrn, movie);
        
        % Valid texture returned? A negative value means end of movie reached:
        if tex<=0
            % We're done, break out of loop:
            break;
        end
        
        % Draw the new texture immediately to screen:
        Screen('DrawTexture', scrn, tex);
        
        % Update display:
        Screen('Flip', scrn);
        
        % Release texture:
        Screen('Close', tex);
    end
    
    % Stop playback:
    Screen('PlayMovie', movie, 0);
    
    % Close movie:
    Screen('CloseMovie', movie);

DrawFormattedText(scrn,['Please press and hold space for how long you believe the video lasted. '],'center','center');
    Screen('flip', scrn); %Show Text on Display
    KbTriggerWait(KbName(['space']));
    tic;
    KbReleaseWait;
    secondResponse = toc;
    DrawFormattedText(scrn,['+'],'center','center');
    Screen('flip', scrn); %Show Text on Displayb
   
WaitSecs(1);
    DrawFormattedText(scrn,['Thank You'],'center','center');
    Screen('flip', scrn); %Show Text on Display

T = table(c, firstResponse, secondResponse);

writetable(T,'Data.csv','WriteMode','Append','WriteRowNames',true)

KbStrokeWait;% wait for any keypress
    Screen('CloseAll');

ListenChar(1); %Reinstate ability to type in MATLAB

Hi! Has anyone found a way to change the size of the video? I have the same problem as @kylecrawshaw (the video is larger than the screen) and I’m surprised I can’t find any straightforward solution to this online.
Thanks!

I’m surprised too that you couldn’t find anything, as pointers to info about how the basics work are given in various places like the Download instructions, by the installer/updater, basic help functions about drawing, movie playback demos…

The dstRect parameter of DrawTexture takes care of placing images at certain destination rectangles, rescaling if needed, if you look at Screen DrawTexture? help.

Also read the intro PDF Psychtoolbox/PsychDocumentation/PTBTutorial-ECVP2013.pdf which explains coordinates and many other basic things. Or one of the most common movie playback demos (‘help MovieDemos’): PlayMoviesDemo.m

Oh, of course! I kept looking into PlayMovie, and it was about the DrawTexture… Seems so obvious now, thank you!