# How to upload and play an avi video in MATLAB

**URL:** <https://psychtoolbox.discourse.group/t/how-to-upload-and-play-an-avi-video-in-matlab/380>\
**Category:** Uncategorized\
**Created:** [December 18, 2012, 4:49pm UTC](https://psychtoolbox.discourse.group/t/how-to-upload-and-play-an-avi-video-in-matlab/380 "2012-12-18T16:49:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [December 18, 2012, 4:49pm UTC](https://psychtoolbox.discourse.group/t/how-to-upload-and-play-an-avi-video-in-matlab/380/1 "2012-12-18T16:49:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![flickrfusionfrequenc](https://avatars.discourse-cdn.com/v4/letter/f/8e7dd6/32.png) [@flickrfusionfrequenc](https://psychtoolbox.discourse.group/u/flickrfusionfrequenc)\
**Post date:** [December 18, 2012, 11:39pm UTC](https://psychtoolbox.discourse.group/t/how-to-upload-and-play-an-avi-video-in-matlab/380/2 "2012-12-18T23:39:36Z")

</div>

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](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](https://github.com/Psychtoolbox-3/Psychtoolbox-3/blob/master/Psychtoolbox/PsychDemos/MovieDemos/SimpleMovieDemo.m)  
  
Proceed analogously.  
  
  

> --- In [psychtoolbox@yahoogroups.com](mailto: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
