How to upload and play an avi video in MATLAB

Hi everyone!

I am very new to coding and have not done it in a while so I am struggling with the code to upload and play an avi movie. So far I have tried these two codes but I don't even know if I'm on the right track. Any help would be greatly appreciated!

Code 1:

readerobj=mmreader('video.avi')
vidFrames=read(readerobj);
numFrames=get(readerobj,'numberOfFrames');

for k=1:numFrames
mov(k).cdata=vidFrames(:,:,:,k);
mov(k).colormap=[];
end

hf=figure

set(hf,'position', [150 150 readerobj.Width readerobj.Height])
movie(hf, mov, 1, readerobj.FrameRate)

Code 2:

[movie movieduration fps] = Screen('OpenMovie', win,'C:/Documents and Settings/Student/My Documents/MATLAB/Claire code/video.avi' );

framecount = movieduration * fps;

Screen('PlayMovie', movie, 1, 0 , 1.0);

[movietexture pts] = Screen('GetMovieImage', win, movie, 1);

tsize=40;

Screen('TextSize', win, tsize);


Thanks for your help in advance!
Claire
Your first thing has nothing to do with Psychtoolbox and is something that is pure Matlab only.

Your second thing is odd but one would have to cry "warmer" if we were playing this game: http://commons.wikimedia.org/wiki/File:Pietro_Longhi_061.jpg


This is the simplest example of how to play movies:

https://github.com/Psychtoolbox-3/Psychtoolbox-3/blob/master/Psychtoolbox/PsychDemos/MovieDemos/SimpleMovieDemo.m

Proceed analogously.


--- In psychtoolbox@yahoogroups.com, "claire.stewart2010" wrote:

Hi everyone!

I am very new to coding and have not done it in a while so I am struggling with the code to upload and play an avi movie. So far I have tried these two codes but I don't even know if I'm on the right track. Any help would be greatly appreciated!

Code 1:

readerobj=mmreader('video.avi')
vidFrames=read(readerobj);
numFrames=get(readerobj,'numberOfFrames');

for k=1:numFrames
mov(k).cdata=vidFrames(:,:,:,k);
mov(k).colormap=[];
end

hf=figure

set(hf,'position', [150 150 readerobj.Width readerobj.Height])
movie(hf, mov, 1, readerobj.FrameRate)

Code 2:

[movie movieduration fps] = Screen('OpenMovie', win,'C:/Documents and Settings/Student/My Documents/MATLAB/Claire code/video.avi' );

framecount = movieduration * fps;

Screen('PlayMovie', movie, 1, 0 , 1.0);

[movietexture pts] = Screen('GetMovieImage', win, movie, 1);

tsize=40;

Screen('TextSize', win, tsize);


Thanks for your help in advance!
Claire