How to use a mp4 file in a PTB screen in psychtoolbox?

30 次查看(过去 30 天)
Hello everyone, I'm beginner at the world of matlab, and I just finished the foundamental course but I'm still struggling.
I want to use a mp4 image in a PTB screen in psychtoolbox but I havent being able to do it.
I'm just familiar with the function "DrawFormattedText" but I dont want to show text in the screen, I want to show an image in mp4.
Thank you in advance!
%Configuration of the screen
PsychDefaultSetup(2);
Screen('Preference', 'VisualDebugLevel',1); %for removing the psychtoolbox logo at the beginning
Screen('Preference', 'SkipSyncTests', 2);
xdisp=700;
ydisp=700;
[win screenRect]=Screen('OpenWindow',0,[200,200,250],[0 0 xdisp ydisp]); %Color of the screen
path = 'C:\Users\carme\OneDrive\Escritorio\AssFinalFiles';
fixClrs = [0 300];
scr = max(Screen('Screens'));
%Introduction (HERE IT IS WHERE i WANT TO SHOW THE mp4 image instead of using the writing function but the screen just gets black)
moviefile = 'C:\Users\carme\OneDrive\Escritorio\AssFinalFiles\WELCOME.mp4'
screenNum = 0;
[window, rect] = Screen('OpenWindow', screenNum, 1);
moviePtr = Screen('OpenMovie', window, moviefile);
Screen('PlayMovie', moviePtr, 1);
space=KbName('space'); % using spacebar to continue
[~, keyCode]=KbWait;
while keyCode(space)==0
[secs, keyCode]=KbWait;
end

回答(1 个)

Nithin Kumar
Nithin Kumar 2023-9-8
编辑:Nithin Kumar 2023-9-8
Hi Maria,
I understand that you are facing an issue while trying to use an mp4 image on a PTB screen in Psychtoolbox of MATLAB.
The issue with the provided code is that you are opening two windows using the “Screen('OpenWindow', ..)” function. The first window is opened at the beginning with the configuration settings, and the second window is opened when you try to display the movie.
To display the MP4 video on the PTB screen, kindly modify the code as shown in the following code snippet –
% Configuration of the screen
PsychDefaultSetup(2);
Screen('Preference', 'VisualDebugLevel', 1); % For removing the Psychtoolbox logo at the beginning
Screen('Preference', 'SkipSyncTests', 2);
xdisp = 700;
ydisp = 700;
[win, screenRect] = Screen('OpenWindow', 0, [200, 200, 250], [0 0 xdisp ydisp]); % Color of the screen
moviefile = 'C:\Users\carme\OneDrive\Escritorio\AssFinalFiles\WELCOME.mp4';
moviePtr = Screen('OpenMovie', win, moviefile); % Use the existing window 'win' instead of opening a new one
Screen('PlayMovie', moviePtr, 1);
% Display the video until the spacebar is pressed
space = KbName('space');
keyCode = 0;
while keyCode(space) == 0
[~, keyCode] = KbWait;
end
% Close all the screens
Screen('CloseMovie', moviePtr);
Screen('CloseAll');
I hope this provides you with the required information regarding your query.
Regards,
Nithin Kumar.

类别

Help CenterFile Exchange 中查找有关 Image display and manipulation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by