Clear Filters
Clear Filters

Stretch movie size with Screen('OpenMovie')

5 views (last 30 days)
LG
LG on 17 Dec 2021
I'm using psychtoolbox to open and play a movie, however I want to stretch the movie to be full screen.
[movie, movieduration, fps, width, height] = Screen('OpenMovie', window, movietitle)
On playing the movie I can see that the original file's width and height are smaller than my screen dimensions (1280x720 movie and 1920x1080 screen) - is there a way to stretch the movie on opening it to fit my desired screen dimensions?
Thanks

Answers (1)

prabhat kumar sharma
prabhat kumar sharma on 15 Feb 2024
Hi LG,
I understand that you want to stretch your movie to fill the entire screen while playing it. There are two possible solutions you could try:
1. Use the Screen('DrawTexture') function:
This method involves drawing the movie texture on the screen and specifying the scaling parameters. This way, you can stretch the movie to fit the screen dimensions.
You can refer the below psuedocode for understanding:
% Get movie texture after opening
movieTex = Screen('GetMovieTexture', window, movie);
% Define target dimensions (full screen in this case)
[screenX, screenY] = Screen('WindowSize', window);
% Calculate scaling factors to maintain aspect ratio
scaleX = screenX / width;
scaleY = screenY / height;
% Choose the smaller scaling factor to avoid stretching in one dimension
scaleFactor = min(scaleX, scaleY);
% Draw the movie texture with scaling
while Screen('Flip', window) && Screen('MovieState', movieTex) == 1
Screen('DrawTexture', window, movieTex, [], [0 0 width height] * scaleFactor);
end
% Close the movie texture and movie
Screen('CloseMovie', movie);
Screen('Close');
2. Using the Screen('SetMovieDrawParams') function:
This function allows you to set drawing parameters for the movie. You can define a scaling factor that will be applied automatically during playback
% Open the movie with the desired scaling
[movie, movieduration, fps, width, height] = Screen('OpenMovie', window, movietitle, [], [], [], [1920 1080] / [width height]);
% Play the movie (no further scaling needed)
while Screen('Flip', window) && Screen('MovieState', movie) == 1
end
% Close the movie and screen
Screen('CloseMovie', movie);
Screen('Close');
I hope it helps to resolve your issue!

Products

Community Treasure Hunt

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

Start Hunting!