Skip to content

Commit d88e9e4

Browse files
authored
Merge pull request #156 from fedefalag/fede-play_videos_from_frames
Presenting frames as videos + demo
2 parents b9d8bb7 + c5a78c1 commit d88e9e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+152
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
% (C) Copyright 2021 CPP_PTB developers
2+
3+
%% Demo showing how to use the createFramesTextureStructure and playVideoFrames functions
4+
5+
% as it is, it presents two example videos in succession
6+
7+
8+
% add parent directory to matlab path (so we can access the CPP_PTB functions)
9+
addpath(fullfile(pwd, '..'));
10+
11+
%% start with a clean slate
12+
clear;
13+
clc;
14+
15+
16+
%% initialize PTB % This can def be improved by using other CPP_PTB functions%
17+
18+
% Skip the PTB sync test
19+
Screen('Preference', 'SkipSyncTests', 2);
20+
21+
% Get the screen numbers and draw to the external screen if avaliable
22+
cfg.screen.idx = max(Screen('Screens'));
23+
24+
% Set the PTB window background manually
25+
cfg.color.background = [127 127 127];
26+
27+
% Get the screen numbers and draw to the external screen if avaliable
28+
cfg.screen.idx = max(Screen('Screens'));
29+
30+
% Open an on screen window
31+
[cfg.screen.win, cfg.screen.winRect] = Screen('OpenWindow', cfg.screen.idx, cfg.color.background);
32+
33+
34+
%% Strcuture for video related info
35+
36+
% The name of your "video" and its images format
37+
video.names = {'coffee','leaves'};
38+
39+
% The number of frames of your video you want to present
40+
% If left empty, all available frames are taken
41+
video.frame.numbers = [];
42+
% video.frame.numbers = 30;
43+
% video.frame.numbers = [30,15];
44+
45+
% The format fo the images
46+
video.frame.format = '.jpeg'; % can be any img format compatible with the "imread" function
47+
48+
% the folder where the images are (from the current folder)
49+
video.stimuli.folder = 'stimuli/';
50+
51+
% The frame rate at which you want to present your video
52+
video.frame.rate = 29.97;
53+
54+
% Time bw videos in s
55+
video.isi = 1;
56+
57+
58+
%% present the videos in a loop
59+
60+
for trial = 1:length(video.names)
61+
62+
% select name and folder where current video is
63+
video.name = video.names{trial};
64+
video.path = fullfile(video.stimuli.folder,video.name);
65+
66+
67+
% how many frames are going to be presented
68+
if numel(video.frame.numbers) < 1
69+
video.frame.number = size(dir([video.path,'/*',video.frame.format]),1);
70+
71+
elseif numel(video.frame.numbers) > 1
72+
video.frame.number = video.frame.numbers(trial);
73+
74+
else
75+
video.frame.number = video.frame.numbers;
76+
end
77+
78+
79+
% Read the images and create the stucture with their textures
80+
[video, cfg] = createFramesTextureStructure(video, cfg);
81+
82+
% Play the video
83+
playVideoFrames(video, cfg);
84+
85+
% ISI (better would be to use Flip)
86+
WaitSecs(video.isi);
87+
88+
end
89+
90+
91+
% The end
92+
sca;
14 KB
14.1 KB
14.1 KB
14.1 KB
14.2 KB
14.2 KB
14.2 KB
14.2 KB
14.2 KB

0 commit comments

Comments
 (0)