Code covered by the BSD License  

Highlights from


4.8 | 105 ratings Rate this file 334 Downloads (last 30 days) File Size: 12.6 MB File ID: #8028




13 Jul 2005 (Updated )

Read virtually any media file in Windows, Linux, or Mac.

| Watch this File

File Information

[video, audio] = mmread(filename, frames, time, disableVideo, disableAudio, matlabCommand, trySeeking, useFFGRAB)
mmread reads virtually any media file. It now uses AVbin and FFmpeg to capture the data, this includes URLs. The code supports all major OSs and architectures that Matlab runs on.

filename input file to read (mpg, avi, wmv, asf, wav, mp3, gif, ...) frames specifies which video frames to capture, default [] for all or to specify time

time [startTime stopTime], default [] for all disableVideo disables ALL video capturing, to save memory or time disableAudio disables ALL audio capturing, to save memory or time

matlabCommand Do not return the video structure, but call the function specified by matlabCommand. The function definition must match that of processFrame.m. See processFrame.m for more information.
trySeeking [true] setting this to false makes the code slower but more precise. If the first several frames are distorted or timing information isn't accurate, set this to false.

useFFGRAB [true] Use the new version of mmread, which uses ffmpeg. However, if an audio or video stream can't be read AND you are running Windows try setting this to false (old version).

video is a struct with the following fields:
  width width of the video frames
  height height of the video frames
  rate the frame rate of the video, if it can't be determined it will be 1.

  nrFramesTotal the total number of frames in the movie regardless of how many were captured. Unfortunately, this can not always be determined. If it is negative then it is an estimate based upon the duration and rate (normally accurate to within .1%). It can be 0, in which case it could not be determined at all. If it is a possitive number then it should always be accurate.

  totalDuration the total length of the video in seconds.
  frames a struct array with the following fields:
      cdata [height X width X 3] uint8 matricies
      colormap always empty
  times the corresponding time stamps for the frames (in msec)
  skippedFrames some codecs (not mmread) will skip duplicate frames (i.e. identical to the previous) in fixed frame rate movies to save space and time. These skipped frames can be detected by looking for jumps in the "times" field. This field will be true when frames are skipped.

audio is a struct with the following fields:
  nrChannels the number of channels in the audio stream (1 or 2)
  rate sampling rate of the audio, ex. 44100. If it can't be determined then it will be 1.

  bits bit depth of the samples (8 or 16)
  data the real data of the whole audio stream. This can be played using wavplay. If time ranges are specified, the length of the data may not correspond to the total time. This normally happens with movies. The issue is that the start of the audio stream is generally counted at the END of the first frame. So, time is shifted by 1/framerate.

  nrFramesTotal Audio comes in packets or frames when captured, the division of the audio into frames may or may not make sense.

  totalDuration the total length of the audio in seconds.
  frames cell array of uint8s. Probably not of great use.
  times the corresponding time stamps for the frames (in milliseconds)

If there is no video or audio stream the corresponding structure will be empty.

Specifying frames does not effect audio capturing. If you want only a subsection of the audio use the 3rd parameter "time". Specifying time effects both audio and video. Time is specified in seconds (subsecond resolution is supported with fractional numbers ex. 1.125), starting at 0. Time is defined as startTime (inclusive) to stopTime (exclusive), or using set notation [startTime stopTime).

If there are multiple video or audio streams, then the structure will be of length > 1. For example: audio(1).data and audio(2).data.

[video, audio] = mmread('chimes.wav'); % read whole wav file

video = mmread('mymovie.mpg'); % read whole movie

video = mmread('mymovie.mpg',1:10); %get only the first 10 frames

video = mmread('mymovie.mpg',[],[0 3.5]); %read the first 3.5 seconds of the video

[video, audio] = mmread('chimes.wav',[],[0 0.25]); %read the first 0.25 seconds of the wav
[video, audio] = mmread('chimes.wav',[],[0.25 0.5]); %read 0.25 to 0.5 seconds of the wav, there is no overlap with the previous example.

read a movie directly from a URL
video = mmread('');

video = mmread('mymovie.mpg',[],[],false,true); %read all frames, disable audio

mmread('mymovie.mpg',[],[],false,false,'processFrame'); %Use inline processing for all frames in a movie using the function processFrame.m


Mpgread inspired this file.

This file inspired Mmcount.M, Mmplay, Mmwrite, and Motion Detection.

MATLAB release MATLAB 7 (R14)
Other requirements Windows, Mac or Linux systems required. 32 and 64 bit are supported.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (326)
06 Dec 2013 Maria

Hi Micah,

Thanks for your mmread, it works fine for me! I was wondering if there is an extension so that it can also read live-streams with H264 compression format. I need to read and save a video stream transmitted using RTSP protocol. Do you have any idea how that could work?

Thanks a lot!

06 Dec 2013 Maria  
13 Nov 2013 Thomas Deneux  
24 Oct 2013 Eran


The first call to mmread.m to load a five minute clip of mpg files worked great, but all calls after that crashed Matlab with the an APPCRASH-event error code e06d7363, which I believe is a compatibility problem between the mex files and my laptop (windows 7 64 bit with Matlab R2012b). This even occurs if I reboot the laptop and restore to a previous restore-point) So I'm trying to compile a new mex file. to do this, I downloaded a version of avbin and FFmpeg (not sure what version is required for this) but there also seem to be many other .h files that are needed (features.h, inttypes.h, unistd.h). So, have you encountered this problem before and if so, do you know of a solution or can you possibly upload all of the dependencies that are needed to get this and the mmwrite.m functions to compile?

Thank you

01 Sep 2013 Omry Blum  
27 Aug 2013 Ami Shah

hi micah
try to solve my problem as early as possible

14 Aug 2013 Ami Shah

please give the solution as early as possible, because i use the mmread code on my project work .
Warning: Calling MEX-file 'C:\Users\PC\Desktop\mmread\FFGrab.dll'.
MEX-files with .dll extensions will not execute in a future version

14 Aug 2013 Ami Shah

please give the solution as early as possible, because i use the mmread code on my project work .

28 May 2013 Maxim

Hello, Micah!
I love your mmread.
However recently I started to use Image Acquisition Toolbox, for which the suggested save format is motion jpeg 2000 (.mj2).
For some reason mmread crashes on them.
I would be happy if you could suggest something. (except saving it in avi =) )

23 May 2013 Yanwei Fu

Hi Micah,
Your excellent MMREAD is really good, and even better than the MATLAB built-in version. It seems that there is no support for video/x-h264 decoding format, which will make our programs crushed. Could you help add the support it?

19 Apr 2013 Theodoros Giannakopoulos

Really nice work! Though, I have the following problem. When reading frames from a large video file and the function seems to be rather slow for large frame indeces. E.g
video = mmread('/home/tyiannak/Desktop/05-10-19.avi', [10000]);
runs for several seconds. I suppose this is due to some type of file seeking. Can I avoide this?

17 Apr 2013 Alfian Abdul Halin

Hi there. I tried to type mmread (without any arguments)... then my Matlab (R2009b) shut down. Is there something in the code that causes this? Thanks!

02 Apr 2013 Mingyuan Zhou  
11 Mar 2013 Alfian Abdul Halin

Just to update. I ended up using mmreader instead :P But with a little bit of a cheat...

obj = mmreader('test.avi');

for i = 1:obj.NumberOfFrames

currFrame = read(obj, [frameCount frameCount]);
imwrite(currFrame, fileName,'jpg');
frameCount = frameCount + 1;


Yeah... I know. I suck at coding :P

11 Jan 2013 Risa  
01 Dec 2012 Alessandro

Great piece of code. I'm working on vista32 and confirm Xiaomin solution for FFGRAB.

26 Oct 2012 amin

Hi Micha,

Thanx for sharing !!!
Can I have anyone help on the following issue ?

Warning: In the directory "G:\PHD\MATLAB\code3.0.1\piotr_toolbox_V3.01\toolbox\mmread",
mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
> In seqIo>frImgs at 311
In seqIo at 70
Error using permute
Out of memory. Type HELP MEMORY for your options.

Error in mmread (line 201)
data = permute(reshape(data, 3, width, height),[3 2 1]);

04 Oct 2012 Greg


FFmpeg just released version 1.0 a few days ago and releases updates fairly often. Is it easy/possible for us as users of mmread to update the FFmpeg libraries/files that this function uses to read in files? If so, any guidance on how would be appreciated. If not, do you have any plans to update mmread with the latest FFmpeg and AVbin releases?


14 Aug 2012 Xiaomin

Dear all,

For anyone who has this error
??? Error using ==> FFGrab
Unable to open file

Put the video file(.avi) to the same fold the mmread.m is, and then it can find it easily.
Otherwise the directory of the video file(.avi) is too long for it to find the file, even the directory is correct.


13 Aug 2012 Xiaomin

Hi Micah,
I also met this error when I run your package
??? Error using ==> FFGrab
Unable to open file

Error in ==> mmread at 146

Error in ==> my_read_try at 1
[video, audio] = mmread('chimes.wav'); % read whole wav file

Hope to hear from you soon

06 Apr 2012 ju  
07 Mar 2012 Haris  
07 Mar 2012 Haris

Hi Micha,

Great work and support on the code

I am having a trouble compiling the mmread in an executable when I use the matlab Commnad option. The error that is get is
''Undefined function or method 'processFrame' for input arguments of type 'uint8'.''

04 Mar 2012 Daniel

Hi Micha,

First - great work!!!
I'm having a problem with the audio of *.wmv files:
[video, audio] = mmread('test_mov1.wmv');
Could not open audio stream

The video is being read OK, but the audio is empty...
This doesn't happens with other files.
Is this a known issue?


09 Feb 2012 Cris Luengo

Works straight out of the box. Simply fantastic, as I've had so many headaches trying to read video data in MATLAB on Linux!

06 Feb 2012 myriam robert

No its ok

06 Feb 2012 myriam robert

once we have the structure "video" how to access each of the frames?
For example if I want to work on Frame 1 then 2 etc. what is the command?
thank you

09 Jan 2012 Siddharth Baijal

i have problem in using this command...
the following error is generated when i use it:-
"??? Index exceeds matrix dimensions."
please tell me where am i wrong

18 Dec 2011 Ravi

mov = mmread('Input.wmv');clc
i got prob on on above line, what is themeaning of abve line

Error in ==> Untitled at 7
mov = mmread('Input.wmv');clc

17 Dec 2011 Ravi

mov = mmread('Input.wmv');clc
i got prob on on above line, what is themeaning of abve line

Error in ==> Untitled at 7
mov = mmread('Input.wmv');clc

23 Nov 2011 Kevin Bartlett

Hi Micah,

I hadn't realised that a negative nrFramesTotal value denoted an estimated number of frames. That makes the process of searching for the last frame much more straightforward than the method I used in mmcount.


23 Nov 2011 Micah Richert

Hi Kevin,,

Sorry for the delayed reply. I'm not sure why struct returned by mmread doesn't work for you, specifically v.nrFramesTotal. if nrFramesTotal is positive it is the number of frames in the video, if it is negative then the video doesn't report the total number of frames and nrFramesTotal is estimated from the frame rate and duration of the video. So, the following code should work for you:

v = mmread('somevideo.mpg',1);
if v.nrFramesTotal > 0
vlast = mmread('somevideo.mpg',v.nrFramesTotal);
% estimated last frame, try reading past the end of the video, after which nrFramesTotal will be accurate.
vlast = mmread('somevideo.mpg',-v.nrFramesTotal*1.01);
vlast = mmread('somevideo.mpg',v.nrFramesTotal);

Hope this helps,

23 Nov 2011 Micah Richert

Hi Jennifer,

You have a few options. One is to use 64 bit Matlab (on a 64 bit machine with lots of memory). Another option is to read the video in small chunks and down sample the images so that they take up less memory. The final option is to use the processFrame.m interface, type "help processFrame" for more information.


23 Nov 2011 Kevin Bartlett

See my comment on Nov.8, 2011.

I've written a program that uses mmread() to count the number of frames in a .asf video without reading in the whole file ( This way, it is possible to read in just the first and last frames of a file without worrying about running out of memory; it is also much faster than reading in the whole file.

I've given mmread() a rating of 4; the only reason it isn't a 5 is that it is missing this functionality. Hopefully it will be added sometime soon, and I'll be able to retire mmcount().

15 Nov 2011 Jennifer

I'm trying to read in an mpg movie that's about 24minutes long, which is obviously too big to fit into memory. However, even when I take it in chunks, say 500 frames (about 8 seconds), there's still not enough memory to do anything with the data. Does this seem right?
My main issue is that I want to be able to track a (slow) moving object so I really need more than 8 seconds to adequately differentiate between the object and the background.
Is there a way to extend how much I'm able to read in so I can average over a larger sample, or to free the memory in a better way? Thanks for your help.

14 Nov 2011 Nick

Amazing! Reads video files that MATLAB's mmreader can't, and also reads video files faster than mmreader. Good job!

08 Nov 2011 Kevin Bartlett

mmread is working perfectly, but I'm running out of memory. All I want is the first and last frame of a (very large) asf file.
video = mmread('tmp.asf',1); works for the first there a way to determine the number of the last frame so I could do
without reading in the whole file?

26 Sep 2011 Orly amsalem

Thank You !!!

26 Aug 2011 Stefan Karlsson

in case its useful for anyone. A single line that converts the frame to grayscale in your callback function (the one replacing 'ProcessFrame') could be:

grayFrame = reshape(...
3*uint16(data(1:3:end))+ ...
6*uint16(data(2:3:end))+ ...
1*uint16(data(3:3:end)) ,width,height)';

to get in proper range and precision:

grayFrame = double(grayFrame)./(3+6+1);

This can now be shown with imagesc for example.

this works for my database without errors.

25 Aug 2011 Stefan Karlsson

Problem unrelated and solved... mmread is a wonderful function!

25 Aug 2011 Stefan Karlsson

Correction:I am on a windows 7 machine

25 Aug 2011 Stefan Karlsson

I have a very serious problem. Matlab crashed twice using this function, and now it will not start at all unless i run it in nojvm mode(Other java apps run just fine). When I try to run matlab, the startup window comes up, but then just disappears without matlab being initiated, and there is no error message.

I first ran this code on a database of avi-files and it was very smooth. The problem occurred when I tried to use the very entising callback funtionality of ffgrab. When defining my own function 'ProcessFrame', I first made it extremely simple... just echoed frame number to the prompt the first 10 frames. This worked once, and then crashed. After second run, it crashed matlab, and left me in my current situation.

I am on a 64 bit machine with Vista, with (R2010b).

Any suggestions? There is a chance that this is unrelated to mmread.

15 Jul 2011 JR Archer

Got it working in minutes, great job on this code! Very user friendly. I couldn't find any good way to read mp4 files until I saw this. Awesome job!

20 Jun 2011 Matt Gardner  
20 Jun 2011 Matt Gardner

Hi Micah. Sorry, for some reason the last post I wrote posted over my previous post which contained my question. I'm using mmread to pull out specific frames from an mpeg-2 file converted from a VOB file. I have a timer embedded on the image that doesn't match the time of the video, and I'm using this time multiplied by the sampling rate to get the frame number of interest. Whats strange is that this works with mmread for the first minute or so and then gets completely off track. I've checked to make sure that the embedded time stamp is continuous, which it is. Whats strange is that the nrFramesTotal shows -683 for the video. I'm wondering if this negative value indicates a problem with decoding the frame numbers, which I think would explain my problem. I'm not sure if this will help, but I've also noticed that when I play the video in VLC or windows media player, the time resets to zero every few minutes, and infact it seems to rezero at the frame which this inconsistency starts occurring.

Thanks so much for creating mmread and answering questions, this script is perfect for the problem I'm working on!

20 Jun 2011 Matt Gardner

By the way, I have tried it with TrySeeking turned on and off, same results

27 May 2011 Ma Chao

Dear Micah
Now,I'm making a simple video player,although I have read some books about GUI,I also get no idea to begin my project.Can you give me some suggestion?

24 May 2011 Rakesh Chalasani

sorry 64-bit*

24 May 2011 Rakesh Chalasani

Awesome! Works right out of the box. But I wish to see it working on a 32-bit.
Great job! Thanks!

30 Mar 2011 abhishek sen

To follow up my previous message.

I am using Matlab R2010a on Windows 7.

30 Mar 2011 abhishek sen


I saw this question came up before, but there wasn't any conclusive solution. So, I have to ask this again.

I added the mmread directory and called

The output was :

??? Error using ==> FFGrab
Unable to open file

Error in ==> mmread at 146

What is the reason behind this error message ? How can I fix it ?

24 Mar 2011 Theodoros Giannakopoulos

I've just downloaded your code and used it for reading mpeg files in Matlab. The fact that is worked without any problems on Ubuntu is really good, so ... thank you!

17 Mar 2011 Micah Richert

Hi Chris,

640x480 uncompressed video requires 640*480*3 bytes per frame or just under 1Mb of memory. If you capture for 2 minutes at 20fps that is 640*480*3*20*120 or 2.2Gb of memory. So, it is of no wonder that you are getting out of memory errors; also 2Gb is the most memory 32-bit Matlab can allocate.

To get around these issues, either read the video in smaller chucks or use the processFrame interface. Or use mmreader since you are using a newer version of Matlab.


17 Mar 2011 Chris McGraw

I've read through the comments to verify whether I'm the only one with this problem, and it seems like I am. Is it typical not to be able to load more than about 2 minutes of a 640x480, 20fps WMV-encoded file without running out of memory with 32-bit Matlab? I'm running Student Version (32-bit) Matlab 7.10.0 R2010a on Windows 7 64-bit. Even reading in small portions at a time, I exceed my memory restrictions after 2 minutes of video.

12 Mar 2011 Juan Carlos  
20 Jan 2011 Harry

I used mmread and mmwrite some time ago to read and write .avi files but ,I really don't remember why,probably for speed and memory, I changed in mmreader lately. Nowdays I tried to experiment with mmread and came up a problem which I think you'll be aware of. For the same avi file usually mmread and mmreader doesn't return the same number of frames. For some files they both return the correct numreb but most of the times they don't. In some occasion mmread has returned half of the numFrames returned by mmreader. I noticed that mmreader returns always, in my examples, less or equal frames. When I play the files with BSplayer it shows the number of frames shown by mmreader.

Because it is a major alteration and I haven't see it mentioned maybe the fault is in my pc(codecs or Windows).
I use Windows XP SP3 and Matlab R2010b

16 Nov 2010 Tom F

OK update: just after I posted I tried again, this time with the file in question in the same directory as mmread and this worked. Maybe I was being dumb, it appears that adding the mmread directory to the path and running the function on a file elsewhere does not work. Am now experimenting to see how it copes with different codecs.


16 Nov 2010 Tom F

Hi, I was hoping that this might solve the issues that I have had getting MATLABs inbuilt functions to read any movie files on Mac OSX. However, it is not able to read most of the movies I try, giving me the following error:
??? Error using ==> FFGrab
Unable to open file

Error in ==> mmread at 146

This happens for all the local files I've tried it on thus far, all of which are playable in QuickTime and other players. For example, the 'xylophone.mpg' file that ships with my version of MATLAB gives this error. So.. has anyone got this working on Mac? Are there some other libraries or something I need to install. Interestingly, the only thing I have got it to read is the URL from nature in the example.


Mac OSX 10.5.8
MATLAB 7.6.0 (R2008a)

27 Oct 2010 wong

Hi Mic,
Great work!
But I have a problem.I am runing Windows XP with Matlab R2009b.When I try to run that "[video,audio]=mmread('handel.wav');",I get the error message:
Warning: In the directory "E:\MATLAB\work\mmread", mexDDGrab.mexw32 now shadows
Please see the MATLAB 7.1 Release Notes.
??? Error using ==> FFGrab
Unable to open file

Error in ==> mmread at 146

But when I run again,it only ruturn that
Error in ==> mmread at 146

Can you help me?
Thank you.


11 Oct 2010 Micah Richert

Hi Jimmy,

On older versions of Matlab the movie command plays the video very quickly once before actually playing it. Could this be what you are referring to as flicker? To get around that you can try my mmplay:


11 Oct 2010 Jimmy O

Cool, thanks Micah it works now.

For some reason, when I play an avi clip in matlab using the command movie, I get this flickering in the beginning of playback. I've tried playing the frames slowly, but it still happens, so the change is not occuring in between frames. I tried both aviread and mmread, but used movie() for both, and both flickers. I also tried eliminating the first few frames but it still happens. Does anyone know what the problem is?

08 Oct 2010 Micah Richert

Hi Jimmy,

To use mmread under very old versions of Matlab (your version), rename FFGrab.mexw32 to FFGrab.dll

You may also want to rename DDGrab.mexw32 to .dll as well.


08 Oct 2010 Jimmy O


I downloaded mmread and extracted the files into the current directory. I am running Windows XP with Matlab 7 R14 SP1. When I try to run mmread, I get the error message: "Undefined function FFGrab". Do I need to compile FFGrab or something?


01 Oct 2010 ahmedsalaheldin ahmed

Yeah , thank you very much it works now with mmplay ,so clever from you :).

Another thing ,yes i want to display 2 videos together to compare between something in both of them (original one, and Noise interfered one) so how can i display both of them at the same time?
thank you MIC :)

30 Sep 2010 Micah Richert

Hi Ahmed,

I assume you are asking about mmplay. No, you can not use subplot to display multiple videos on the same figure. mmplay only supports playing to one figure, and if you try playing two videos simultaneously a new window will appear to play the second video.

To play sound with video do something like this:
mmplay(v,a); % make sure you pass both the audio and video structures to mmplay in order to play video with audio

If you still are not getting audio, make sure that the audio structure "a" contains data and that you are enabling audio capture for mmread.


30 Sep 2010 ahmedsalaheldin ahmed

hey Mic, i would like to know why doesnt the sound plays during the movie being displayed??? please reply as soon as possible :) thanks

30 Sep 2010 ahmedsalaheldin ahmed

hey Mic, it finally works ,but i would like to ask another question:
can i use subplot function to display multiple videos on the same figure?

29 Sep 2010 ahmedsalaheldin ahmed

Hi Mic
I am using windows 7- and when i have a problem saying:

??? Error using ==> mexDDGrab
An object or name was not found.

Error in ==> mmread at 367
so i would like to know where exactly to put the rest of the files attached with the mmread.m file and how can i solve it please ,,,thanks in advance :)

29 Sep 2010 ahmedsalaheldin ahmed

Hi Mic
I am using windows 7- and when i have a problem saying:

??? Error using ==> mexDDGrab
An object or name was not found.

Error in ==> mmread at 367
so i would like to know where exactly to put the rest of the files attached with the mmread.m file and how can i solve it please ,,,thanks in advance :)

23 Sep 2010 Micah Richert

Hi Casandra,

Unfortunately, you don't have many options. If you are using a Windows machine you can try setting useFFGRAB to false. Aside from that, all you can do is know which 3 frames were not decoded by looking at the video.times vector.


23 Sep 2010 Casandra

Thanks for your program, it's very good! However, I have a problem when I read my video... I know that it has exactly 750 frames, but I always get only 747 of them... why am I loosing those 3 frames? What can I do to obtain all of them??
Thanks in advance.

13 Aug 2010 Eakta Jain

Thanks very much! Being able to read in frames from wmv's and mov's on a linux machine has improved my quality of life : )

16 Jul 2010 Jeremie

Hi Micah,
Firstly great program. Thanks for contributing it!!!

I tried to use it for the first time today, to split a big movie (wmv format) into several sub movies (free format). I created a loop where i retrieve the start and end time is seconds. The values created are correct. The first sub movie extraction works great, but when it comes to the second, i get the following message :

Warning: In the directory "C:\DEV\matlab\mmwrite", mmwrite.mexw32 now shadows mmwrite.dll. Please see the MATLAB 7.1 Release Notes.
> In test_sync at 32
Warning: In the directory "C:\DEV\matlab\mmread", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
> In extract_pulses_videos>extract_sub_video at 73
In extract_pulses_videos at 33
In test_sync at 32

Segmentation violation detected at Fri Jul 16 17:15:29 2010

MATLAB Version: (R2006b)
MATLAB License: 34912
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 3)
Processor ID: x86 Family 6 Model 15 Stepping 13, GenuineIntel
Virtual Machine: Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Default Charset: windows-1252

Error in ==> mmread at 195
[data, time] = FFGrab('getVideoFrame',i-1,f-1);

I use windows xp and matlab 7.3. I have installed the KLite codec pack Full on my pc. Since I can't find a driver for my sound card, I can't set useFFGRAB to false. I have replicated the bug several times.

Would you have any clue for me to solve this problem?


14 Jul 2010 Micah Richert

Hi Vineet,

Email me directly. How many times do you have to call mmread before it starts having problems? I have done stress tests and run it 10,000 times in a row without a problem.

Are you using useFFGRAB==false? If this is the case, then that can explain your memory leak. A lot of Direct Show filters have memory leaks; none of which I have any control over. And the only way to free the memory is to quit Matlab.

Also, you may consider using processFrame.m instead of calling mmread many times. This may not work for your purposes though...


14 Jul 2010 Vineet

Hi Micah,

I am trying to get vedio streaming from a network camera. And I am able to get the frames and process them successfully. However after some time the program stops may be because of buffer overflow. I am building a real time application hence the code needs to be running all the time. Please tell me how to clear the processed frames from the memory so that my code never crashes.

10 May 2010 C C

I am still in need of help and am willing to pay someone to get me up and running. I even tried on an old 2006a machine and could not get it to work either. Any qualified parties can write me. I will pay a healthy rate by the hour. Thank you.

04 May 2010 William Spicher  
02 May 2010 C C

I am currently having difficulty processing an H.264 formatted .MOV file from my camcorder using mmread. Unfortunately, every time I try to process a video from my camcorder, Matlab simply crashes. Other files process perfectly fine.

I am currently using Matlab 2009b, Windows 7 64 bit. I have tried numerous settings (useFFGrab = true/false). Additionally, I have installed the latest FFDShow for 64 bit and when that did not work, I installed the revision listed in the post above, but for 64 bit.

I have uploaded the .MOV file to the location below. If anyone could verify that this file does work on their setup, or offer any additional tips, it would be immensely helpful. Thank you.

30 Apr 2010 Tom S

Done. Upgraded matlab, got the right codecs & all seems to be working. Thanks.

Could be of interest to some people but the newest version of ffdshow didn't work for the particular H.264 .mov files I was trying to use (Casio EX-F1 HD vid). However an old build does: ffdshow_rev1936_20080413_clsid.exe

Available at:


30 Apr 2010 Risa  
27 Apr 2010 Micah Richert

Hi Tom,

That is a strange issue. Have you tried rebooting Windows/restarting Matlab? What happens when you try to play the videos in Windows Media Player?

As far as having to set useFFGRAB to false, this is because you are using a very old version of Matlab. You probably should consider upgrading...


23 Apr 2010 Tom S

Hi Micah,
Firstly great program. Thanks for contributing it.

Up until a couple of weeks ago it worked great on almost any video format I tried. Then all of a sudden it started returning empty structure arrays:
"0x0 struct array with fields:"

Still seems to be reading the file initially though (.mov in this case but I get the same result with .avi's and .wmf)

I've tried using both a slightly older and the newest version of mmread with the same result (although I do have to disable useFFGRAB in the newest version or I get a "??? Undefined command/function 'FFGrab'" message. I'm using Matlab 7.0.4 on WindowsXP)

Any thoughts you may have would be greatly appreciated.


14 Apr 2010 Micah Richert

Hi Andre,

My guess is that you are using OS X 10.4 and I compiled the code on OS X 10.5. I don't have access to a 10.4 system so your only option is to upgrade or try to compile the code yourself. If you want to compile the code yourself, definitely contact me directly and I can try to lead you through all of the steps...


02 Apr 2010 Andre


Thanks for all your work responding to queries so far. I have another...

When trying mmread('movie.avi'), I get the following error:

??? Invalid MEX-file '/Users/ ... /FFGrab.mexmaci': dlopen(/Users/ ... /FFGrab.mexmaci, 1): no suitable image found. Did find: /Users/ ... /FFGrab.mexmaci: unknown load command 0x8000001C.

All the listed file locations are the same.

I'm using Matlab 2007a on Mac OS X 10.4.11.

Thanks for any help!


22 Mar 2010 Borys Golik  
16 Mar 2010 Micah Richert

Hi Yianos,

You need to copy avbin.dll to C:\Users\a_user\AppData\Local\Temp\a_user\mcrCache7.10\estima0\toolbox\mmread.

The problem is that FFGrab.mexw32 depends upon this dll. When you compile the program using mcc the compiled program is missing this dll.

I hope this helps,

16 Mar 2010 Micah Richert

Hi Ravi,

Do you have an example file where there is a problem with the audio? If so, I might be able to take a look at what you are having a problem with.


13 Mar 2010 yianos


Excellent work (and support :-)

I am having a trouble compiling the mmread in an executable as part of a testing deployment.

Execution of the resulting exe file produces the following "catch-able" error:

??? Invalid MEX-file
The specified module could not be found.


Error in ==> mmread at 146

Error in ==> myMatlabProg at 37


Btw, the FFGrab.mexw32 *IS* located in the "C:\Users\a_user\AppData\Local\Temp\a_user\mcrCache7.10\estima0\toolbox\mmread\", contrary to the error message!

I tried with the useFFGRAB=false and everything worked. Using the useFFGRAB=true is hugely much faster, so I 'd appreciate any support on this.


10 Mar 2010 Ravi

This is very useful piece of code. I am using it to extract the audio component from AVI files, the problem I am facing is that the extracted audio has a high degree of distortion, unlike the video which is much clearer. At this point, I need to have much better quality audio. Thanks once again for this utility, and please help if you can. Bests, Ravi

26 Feb 2010 Thibaud senechal

ok i have used an older version of matlab (a 32 bits one) and mmread installed a file .lib and now the function mmread is working on both 32 bits and 64 bits matlab.

Great work, thanks.

25 Feb 2010 Thibaud senechal


I have a problem with matlab 7.9.0 on mac.
If I choose useFFGRAB=true I have the error:
??? Error using ==> FFGrab
Unable to open file
If I choose useFFGRAB=false I have the error:
??? Undefined function or method 'mexDDGrab' for input arguments of type 'char'.

I have checked the path and tried using a fullpath name.

Do you have any idea ?



20 Feb 2010 Patrick O'Keefe  
16 Feb 2010 Micah Richert

Hi Patrick,

Unfortunately, if you need the exact number of frames of the video and nrFramesTotal is not accurate, your only option is to go to the end of the file and use that to count the number of frames.

You can try something like this:
v=mmread('mymovie.mpg',abs(v.nrFramesTotal)*1.1); % nrFramesTotal will definitely be accurate to within 10%, probably much better than that...

It will generate a warning (which you should ignore) and be a little slow but it is your only option.


12 Feb 2010 Patrick Hackl


I have a problem to get the total Frame Number of a .mod video file. If I just read 1 frame with mmread, then the information about the total frame number (nrFramesTotal) is not correct. It show a negative non correct numbers. If I read the whole video it provides the right information. But it slows down the pc, the video fills up the memory. Is there any solustion to get the total frame number without reading the whole file?

.mod files were used as standard format from different camcorder manufacturers (canon, jvc)!


05 Feb 2010 Micah Richert

Hi Vikas,

Either you will have to upgrade Matlab, or with FFGrab = false add a sound card or set disableAudio = true.


04 Feb 2010 vikas bhangdiya

Hi Micah
I am using latest version of mmread and MATLAB7.0
When i used mmread with FFGrab = true , get a following error

??? Undefined command/function 'FFGrab'.

and if i changed FFGrab = false

??? Cannot play back the audio stream: no audio hardware is available, or the hardware is not responding.

my video file is clock.avi,
please help me to come out of this problem.

Best Regards

04 Jan 2010 Micah Richert

Hi Joseph,

Sorry for the delay. I don't know of what is the fastest video codec to decode; I imagine to some extent it depends on the specs of your system. If you have really fast I/O, uncompressed probably would be the fastest, but in reality this probably isn't the case.


17 Dec 2009 Joseph

Hi Micah,

Great set of tools. In my very uncontrolled tests, I'm finding that mmread is faster than read by a factor of 4!

I wanted to ask if you knew what video codecs would be fastest to decode if I needed to grab, say, 1000 frames at a time at random points in a movie.

Thanks and congratulations on the great work.


13 Dec 2009 Micah Richert

Hi Zeng,

To install a new version of mmread on a Linux system you need to either delete (and let mmread reinstall it) or unzip mmread into a new directory.

To install a new version of mmread on a OS X system you must delete ~/lib/libavbin.dylib and then let mmread reinstal it.

On Windows, just unzip to the existing directory and everything should work.


13 Dec 2009 Zeng

Dear Micah,

Sorry but I met with the FFGrab.mexa64: undefined symbol:
avbin_open_filename_with_format error again with the latest version of mmread. My OS comes with 64bit Ubuntu Linux with matlab2009b installed.

Earlier versions still work fine.

27 Nov 2009 Maurice

Great library, just what I needed. Thanks.

22 Nov 2009 Micah Richert

Hi Dino,

Almost certainly not. Contact technical support for your camera to see if there is another way to access the video stream.

If you want to try hacking, you might be able to figure out how the java code works by decompiling it. However, you are on your own if you try this.


22 Nov 2009 Dino

Yes, you are right... if i view in IE i can see only one image. To get stream i have to access in ActiveX mode or in Java mode. Is it possible to use these URL in mmread?


21 Nov 2009 Micah Richert

It would seem that your camera only provides one image per request when you access When you view this URL in IE or Firefox do you see a video or only one picture? If it is only one picture, my guess is that you need to access another URL in order to get a stream of images. Look in your camera's documentation.


21 Nov 2009 Dino

Thanks for fast reply,
mmread and mmplay function correctly for any mjpeg video from hard disk, but when i write
v = mmread({'','mjpeg'},1:10);
i can only see the first frame and Matlab answers

Warning: Frame(s) 2 3 4 5 6 7 8 9 10 exceed the number of frames in the
> In mmread at 189
In video at 1
Warning: Not all frames specified were captured. Returning what was captured, but
order may be different than specified.
> In mmread at 216
In video at 1

Thank you for your help in advance.

20 Nov 2009 Micah Richert

Hi Dino,

To use the camera you need to use an undocumented feature. The reason mmread fails is that it doesn't auto-detect the video format correctly when reading from the camera. To get around this do the following: v = mmread({''','mjpeg'},1:10); This will read 10 frames from your camera as a mjpeg stream.


20 Nov 2009 Dino

Hi Micah,
i´m using IP - camera Airlive Ovislink, which sends out only JPEG stream and can be played with web browser or some IP View software. I am wondering if it is possible to use your kit to generate stream video in Matlab and possibly to use it in real time in some advanced Blockset such Video and Image Processing. I was only succesful to get slow image stream to Matlab with use of imread('') and its cycle in time. But this is really quite slow solution and not sufficient.
I really couldn´t find solution anywhere, so i appreciate any advice. Thanks in advance!

13 Nov 2009 Micah Richert

Hi Everyone,

"The specified procedure could not be found" bug has been fixed for Win64 systems. Please download the newest version.


09 Nov 2009 Micah Richert

Hi Leigh,

What version of Windows are you using: XP, Vista or Win7? As a temporary work around run Matlab in 32 bit mode.


09 Nov 2009 Leigh

This looks like a great library, thank you for all your work on it - it seems to do everything I need.
I am, however, having a little trouble getting started.
When trying to load any files, I get the following error:

>> video = mmread('C:\Users\Public\Videos\Sample Videos\Wildlife.wmv')
??? Invalid MEX-file 'C:\Program Files\MATLAB\R2009b\toolbox\mmread\FFGrab.mexw64': The specified procedure could not be found.
Error in ==> mmread at 146 FFGrab('build',filename,fmt,double(disableVideo),double(disableAudio),double(trySeeking));

Any help much appreciated, I'm sure this is a very simple one.

28 Oct 2009 Micah Richert

Hi Vikas,

You can either ignore the warning message because it is harmless or you can delete the file mexDDGrab.dll to get rid of the warning.


28 Oct 2009 vikas bhangdiya

hi Mr Micah
i'm using matlab 7.3.0( R2OO6b)
the function of mmread doesn't operate ( downloaded new version )

Warning: In the directory "E:\Trail_Code\Histogram_plot", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
> In hist_image at 7

I checked similar post on dated 16-jun-09 (i.e. Try using the full path to the file you want to read.)
I= mmread('E:\Trail_Code\Histogram_plot\UVSS_Truck.avi');

but still gate warning message, please reply how to remove this warning.

Thanks in advance.

21 Oct 2009 Micah Richert

Hi Tony,

I don't have access to a Win64 version of Matlab right now, so I can't confirm if it is a general problem with Win64 and the newest release of mmread, or if it is specific to Windows 7 or you.

Try running the 32 bit version of Matlab and see if mmread works for you there.

Using Dependency Walker ( you might be able to (no guarantee though) find the dll that has the missing procedure. To use it open FFGrab.mexw64.


16 Oct 2009 Anthony Lock

Hi Micah,

I have a vob file to read in matlab a quick google came up with your mmread and it looked perfect. I have downloaded it and written a simple m file containing
[FileName,PathName] = uigetfile('*.vob','Select the Vob-file');
[Video, Audio] = mmread(strcat(PathName , FileName));

but get the following error when mmread is called

??? Invalid MEX-file 'c:\users\acl1\matlab\mmread\FFGrab.mexw64': The specified procedure could not be


Error in ==> mmread at 157

Error in ==> readvob at 2
[Video, Audio] = mmread(strcat(PathName , FileName));

I am using a 64 bit version of Matlab R2009b on windows 7 rtm

I would be grateful if you have any thoughts on why it is happening.

I also tried reading an avi file that I had used mmreader on in the past and got the same error.


13 Oct 2009 Micah Richert

Hi Flavien,

I have made a new version of mmread that doesn't include the isoc99 functions. It took some hacking, but I figured out a way of doing it.


13 Oct 2009 Micah Richert

Hi Drew,

Great suggestion, and thank you for including a solution. I had looked into adding this a while ago but I had never found a documented way of calling an anonymous function in a mex function.

I will add this to the next release.


13 Oct 2009 Drew Gilliam

Micah: great function!

I have a small suggestion - the "matlabCommand" input could also accept anonymous functions. Quick example - say I want to display an image in a figure of my choosing:
hfigure = figure;
fcn = @(d,w,h,f,t)processImageInFigure(d,w,h,f,t,hfigure);

In theory, this should work. "processImageInFigure" gets access to the figure handle, while the anonymous function "fcn" has only the 5 allowable inputs (d,w,h,f,t). Unfortunately, "mexCallMATLAB" cannot directly execute my anonymous function.

But there's an easy fix! "mexCallMatlab" can call "feval" with six inputs - the "matlabCommand" string/function_handle as the first input and the (d,w,h,f,t) variables as the second through sixth inputs. This would continue to work with your string input, while letting my function_handle also work. The only changes I see in FFGrab.cpp:
1) Check the "matlabCommand" input for a string OR function_handle
2) Save the "matlabCommand" value as an "mxArray" rather than a "char" array
3) use "mexCallMATLAB" to call "feval" with six inputs.

I think it would be a great addition - hope you'll consider it!
~Drew Gilliam

08 Oct 2009 Micah Richert

Hi Flavien,

I am looking into solutions for you; however, it is not looking good. It seems that the recommended solution to this problem is to upgrade glibc on your system to version 2.7 or higher. I'll keep looking though.


08 Oct 2009 Flavien

Hi Micah,

Thanks for this amazing work! Apparently I have this "new" error when trying to read an mp3 file:

Invalid MEX-file './MYMATLAB/mp3_toolbox/mmread/FFGrab.mexa64': ./ undefined symbol: __isoc99_sscanf.

I tried to change the to or but I still have this problem,

any clue?

Thanks in advance,


07 Oct 2009 Micah Richert

Hi Ronnie,

I hadn't noticed before that you are using useFFGrab==false; for this situation, yes, you need "data = data(end:-1:1,:,3:-1:1);" to be uncommented. For the newer version of mmread (useFFGrab==true), this line needs to stay commented out.

Glad you found it,

07 Oct 2009 Ronnie

I checked out the processframe.m function. In the latest .rar file that is available for download, the line 68 has been commented.
data = data(end:-1:1,:,3:-1:1);
Uncommenting it gives the correct orientation.

05 Oct 2009 Micah Richert

Hi Ronnie,

Make sure you have not removed the line of code in processFrame.m that corrects the orientation and RGB values: data = permute(reshape(data, 3, width, height),[3 2 1]);


05 Oct 2009 Ronnie

Hi Micah..
great work.
You've mentioned that you corrected the image orientation error as well as the rgb values error. But i'm still getting that stuff inverted when i run nature.avi i doing anything wrong?

video = mmread('C:\Documents and Settings\Ronnie\Desktop\CN\nature.avi',[],[],false,true,'processFrame',true,false)

03 Oct 2009 Micah Richert

Hi Samuel,

Delete and rename or copy to


02 Oct 2009 Samuel Pachoud

Hi again,

Thanks for tour quick help. I tried the latest version of your function (25.09) and here is the error message I obtained:

??? Invalid MEX-file '/homes/spachoud/PhD-project/Program/Utils/mmread/FFGrab.mexa64': wrong ELF class:

Error in ==> mmread at 157

I am sorry for the trouble and thank you again for your support.


28 Sep 2009 Valerie

Hi Micah,

Great tool! Thank you!


25 Sep 2009 Micah Richert

Hi Stavros,

Since so many systems are mis-configured in regard to libbz2 I have decided to remove mmread's dependency on it. Wait a few days for my upload to appear, after that you shouldn't have any more problems.


25 Sep 2009 Stavros

Hi Micah

Thank you for the very useful tool.

I am running mmread on my mac perfectly. But I am trying to run mmread on a linux server and I have exactly the same problem with Samuel. I followed your suggestions about the symbolic link but the problem still remains. The error is the above :

??? Invalid MEX-file 'mmread/FFGrab.mexa64': cannot open shared object file: No such file or directory.

Do you have any thoughts ?

Thank you in advance ...

24 Sep 2009 Micah Richert

Oh and don't try to compile mexDDGrab.cpp that is deprecated and only for Windows. You should try to compile mexFFGrab.cpp instead, but even that will be a MAJOR pain for most users.

24 Sep 2009 Micah Richert

Hi Samuel,

This is a system dependency issue not really a problem with mmread... is not install correctly on your systems; to be installed correctly there should be a symbolic link. But since you don't have root, run the following lines on the command line as a work around:

#this will make a symbolic link to the library with the right name and put it in your home directory under a directory called lib
mkdir ~/lib
ln -s /usr/lib/ ~/lib/

#if* is located somewhere else, then use the full path to that instead of /usr/lib/; for example I have /lib/
#To find you can use the command 'locate'

#This next line MUST be run EVERY TIME before you call Matlab, or you can put it into your .bashrc file.

#run Matlab like you normally would...

22 Sep 2009 Samuel Pachoud


Really useful tool! Thanks.

It's working fine on Windows (using R2008b) however I doesn't work on Linux 64 bits.
I have the same issue than Juan Carlos but as the Linux machine I'm using is a central server I can't add a symbolic link.

I tried to compile the mex function (mexDDGrab.cpp) but it failed as DDGrab.h is missing.

Any help?



14 Sep 2009 Micah Richert

Hi Juan,

Make a new symbolic link (ln -s /usr/lib/ /usr/lib/ and you should be good to go.


11 Sep 2009 Juan Carlos

Great tool!
I am getting a missing library error when running in Linux 64-bit: cannot open shared
object file: No such file or directory.

i do have a newer version in my system:

any ideas?

01 Sep 2009 Luigi Giaccari  
31 Aug 2009 Micah Richert

Hi Zeng,

I've fixed the undefined symbol problem. I'm surprised no one reported this sooner.


27 Aug 2009 Zeng


Thanks for the excellent tool first of all.

It's strange that I could use the mmread seamlessly on July 16. But today when I was trying with the updated version and experimenting on the same video clip as before, Matlab said

??? Invalid MEX-file '/home/sun/Documents/Hollywood2/FFGrab.mexa64': /home/sun/Documents/Hollywood2/FFGrab.mexa64: undefined symbol:

I'm using Ubuntu 9.04 64bit, with Matlab 2008b.

Thanks in advance!

16 Jul 2009 yoash

Many hours of web searching ended here!

10 Jul 2009 Harry  
23 Jun 2009 Micah Richert

Hi Chien,

I think your earlier post is missing. So, I can only guess what your problem is.

Mmread tries to read all of the required keyframes of the file, however, this process isn't perfect. Try setting trySeeking=false, this will make reading slow, but will be the most accurate.

I hope this helps, if not please repost your question.

19 Jun 2009 Chien Ting

I just think of a possible explanation. Prior to the the code I pasted above, I did mmread(infpath, 1); but didn't mmread the frames just prior to the requested frames. So perhaps the codec can only be trust after a keyframe is read?

So, random access of the file cannot be trusted until a keyframe is read, is that it? Please help a clueless guy out!

17 Jun 2009 Micah Richert

Hi Althea,

You are using a really old version of Matlab; I strongly suggest you upgrade. The current version of mmread does not support your version of Matlab.

As far as how to install them, simply unzip ALL files unto a directory. Then from within Matlab, either change the current directory to where you unzipped the files, or add that directory to the path (for info type 'help addpath').

Yes, mmread and mmplay can be used to play a MPEG file, however, I do not recommend trying to use them to do anything even remotely complicated or that requires precision (such as making a movie player or psychophysics).


17 Jun 2009 Althea Fortes

i am a beginner to MATLAB and i am using matlab 6.5.1,
the following programs "MMPLAY, MMREAD, and MMWRITE", after unzipping it where should be the items be placed.

what i mean is on what specific folder? like *.m, *.dll, *.mex4 and etc.

well the program might help to our project from playing MPEG file.

thank you in advance

17 Jun 2009 fero

Mercii Mr Micah
really really mercii

16 Jun 2009 Micah Richert

Hi Fero,

The download link is at the top of this page, just click on the link that says "Download Now".

Yes, you are using an old version. However, the error message you are getting is saying that mmread can't open/find the file. Try using the full path to the file you want to read. For example:

Hope that helps,

16 Jun 2009 fero

hi Mr Micah
i'm using matlab 7.3 R2OO6b
the function of mmread doesn't operate ( may be old version )

>> [video, audio] = mmread('xpp.wav');
Warning: In the directory "C:\Program Files\MATLAB\R2006b\work", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
??? Unable to open file

when changing the file i want to be read , the error repeating
i mean with another extension (wmv , avi , .....)

i trying to download new version or operate this one but i can't
plz tell me from where can i download the version which is suitable with my matlab version or solve this problem

sorry for disturbing
thanks alooot

16 Jun 2009 fero

please reply

15 Jun 2009 Micah Richert

Hi Chien,

The new version of mmread is supposed to work just like the old one. When I build FFGrab.mexw32, I include a direction to Windows for it to look for avbin.dll in the same directory as where FFGrab.mexw32 is located. I had confirmed that this in fact did work a while ago but haven't tested it recently. Once I have access again to a Windows system with Matlab, I'll test it. What version of Windows are you using?

As a work around, edit mmread.m and change the lines "if ~ispc" to "if true" and "if ~strmatch(computer,'PCWIN')" to "if true". Under Linux and Mac, there isn't a way to get a library (avbin) to load from the same directory as the library that loaded it (FFGrab.mex*), so I have mmread change the current directory when it is called and then change it back.

Hope this helps,

14 Jun 2009 Chien Ting

Thanks for a great toolbox, Micah.

Sorry for stupid question, I can't find installation instruction? I used to install your old version in C:\matlab\common\mmread\ and use addpath in all my projects that require mmread. But after the new version is installed, I can't run mmread unless I copy avibin to the current directory.

Where should I put avibin? In C:\WINDOWS\system32\ ? An installation how-to text file would be nice!

Thanks for your time!

09 Jun 2009 Micah Richert

Hi Alex,

Aviread uses Video for Windows (VFW), which is from the Windows 3.1 days, as a backend. useFFGRAB=false uses DirectShow as a backend, and is the more modern movie reader interface for Windows. useFFGRAB=true uses FFmpeg, which is an open source video reader originally designed for Linux but now supports all major OSs. Using google you can find out details for all of these, however, it probably won't be fruitful for your particular problem.

If you send me an example video that you are having a problem with, I might be able to figure out why useFFGRAB=true isn't working for you.


09 Jun 2009 Alexander

Hi Micah,

Thanks for the response. I do indeed set useFFGRAB=False so this is most likely the problem. However, I am running on a windows machine and useFFGRAB=true fails to read the file. I guess I just have an unfortunate batch of avi files. Now I just check for read failure and through the two ways of calling mmread (useFFGRAB=true/false) and aviread it seems I can open most files.
Do you know of any resources I could explore to understand the different back ends of how these functions open/read videos?
thanks for your help,

08 Jun 2009 Micah Richert

Hi Alex,

The 'no appropriate codec could be found error message is only appropriate to useFFGRAB=false (i.e. the old version of mmread). Setting useFFGRAB=true (the default value) will probably solve your issue. This version uses FFmpeg to decode videos and supports almost all video formats and codecs.

To answer your question though, aviread and mmread (both old and new versions) use very different backends to read videos. Each backend supports different codecs, so even on the same machine one reader might be able to read one file that the other can not.


08 Jun 2009 Alexander

Hello Micah,

I have a specific .avi format movie which when read with mmread() throws the 'no appropriate codec could be found' error, but when read with aviread() works like a charm. Any guess why mmread cannot find the proper codecs, but aviread seems able to?

thanks a lot,

01 Jun 2009 Micah Richert

Hi Massimo,

Try a newer version of Matlab. 2006a is a very old version and they hadn't standardized the 64bit interface by that time.

If you are very proficient with mex and gcc/g++, then you can try compiling FFGrab.cpp yourself. You will probably have to download the header files for avbin and point mex to


01 Jun 2009 Micah Richert

Hi Richard,

I'm glad that mmread works well for you. As far as a gray scale option, feel free to post the lines of code that you modified so that others could benefit. However, at this time, I'm not planning on adding this as a feature.


01 Jun 2009 Richard Gueler

I found this function much better than the standard matlab functions. I also was able to read VOB files off a DVD. I modified it slightly to read my video as monochromatic, thus saving memory. It would be nice to add this functionallity to the standard release.

29 May 2009 Massimo Camplani

Hi Mr. Micah Richert

I am very interested on mmread, I'm using it on UBUNTU 7.10 in a 64bit machine, also the matlab version support the 64bit architecture (matlab R2006a). I have a problem with the mexa file, I got this error :

Invalid MEX-file '/home/massimo/my_matlab/mmread/FFGrab.mexa64': /home/massimo/my_matlab/mmread/FFGrab.mexa64: undefined symbol: mxCreateDoubleMatrix_700.

Do you have any suggestions for me??


22 May 2009 Micah Richert

Hi Owen,

The full movie will probably not fit in memory when read into Matlab. So, try reading the movie in small pieces, such as:
v = mmread('mymovie.mpg',1:100);
v = mmread('mymovie.mpg',101:200);

I hope that helps,

22 May 2009 Owen

Hi Micah,
Many thanks for your promt reply...
I just found my problem resulted from that mmread might not support the names of the directories in Matlab Path setting in some other languages. But i have encountered another problem using mmread. If i use mmread to read my .mpg file for fewer frames (eg. <100frames), it works fine. When i tried to read the whole file (around 100 MB) or more frames by mmread, the matlab system would be always frozen which might also much slow down my computer and result in the failure of reading the mpg file. I have tried many ways to fix it, such as freeing up my memories of video variables or adjusting the virtual memory of my computer. None of them can work or make mmread run more successfully for reading my whole file. By the way, I use winxp... Do you have any ideas? thanx a lot...

Best Regards

20 May 2009 Micah Richert

Hi Owen,

First of all, make sure that the file name is correct. Second, try specifying a full path name (ex: 'c:\videos\something\myvid.mpg'). Finally, if none of those work set useFFGRAB=false:
[video, audio] = mmread('c:\videos\something\myvid.mpg', 1:10,[],false, false,'',true, false);

I hope that helps,

20 May 2009 Owen

Hi Micah,
I just tried to use mmread to read some mpg file which can be read by windows media player very successfully. However, Matlab aways shows "Unable to open file". I have installed almost every software and did everything you have recommended like the comments mentioned above. But i still can't solve this problem. It's very urgent for me to use mmread. Would you give me some suggestions to solve this problem? thanx a lot...

Best Regards

14 May 2009 Erik Benkler

Hi Micah,
no, I am using Win XP 32 bit. I give up at this point. Anyway, thanks for this tool which seems to be very useful in most cases.

Best regards,

13 May 2009 Micah Richert

Hi Erik,

Are you using 64 bit Matlab on Windows? If you are, that explains your issue. For technical reasons http reading is currently not supported under 64 bit Matlab for Windows.

As a work around run Matlab in 32 bit mode on your 64 bit system.

I hope that resolves your issue. Also, the issue Marco Francini was having has been resolved and only pertained to the old version of mmread (useFFGrab = false).


13 May 2009 Micah Richert

Hi Sean,

Unzip the file where ever you want. Then in Matlab go to File:Set Path and then click on Add Folder... select the folder where you unziped mmread. Click on Save and then mmread should work no matter what directory you are in.


12 May 2009 Sean

Where do I need to place all of this so that matlab accepts the input "mmread" on the workspace. Where can I put it so that it will work like the built-in functions regardless of what directory I'm in?

Thank you

11 May 2009 Micah Richert

Hi Alex,

Color indexed files will always be converted to "truecolor" when read using mmread. If you want to keep the color indexes you will either have to use aviread or do something like the following:

frames = reshape(indexes,[video.height video.width length(video.frames)]);
figure, image(frames(:,:,1)); % or whichever frame # you want

This is the memory inefficient but short code way. I'll leave it to you to figure out how to do the "truecolor" to indexed conversion on a frame by frame basis if you run out of memory.


10 May 2009 Alexander

Hello Micah,

Great program and much needed substitution for aviread.
It seems not to work for indexed files using a colormap (as noted "always empty" in the user guide).
First, is it supposed to work for indexed files and I am just misusing it? If not, is there any intention of providing indexed support in the near future? Otherwise I have to use aviread for indexed and mmread for truecolor.

All in all, though this is an awesome addition! Thanks

04 May 2009 Erik Benkler

Hi Micah,
the problems I described in my last comment arise both with the sample video on from your documentation and with my IP-cam. The video is read without problems when I set useFFGrab=false, but the stream from the IP-cam is not. That is the reason why I want to try ffGrab=true with my IP-cam. Software or any other firewall isn't the problem with the IP-cam. By the way: 30 April 2008, Marco Francini posted a similar problem here. Did he solve it?
Sorry for confusing things with ffdshow.
Best regards, Erik

30 Apr 2009 Micah Richert

Hi Erik,

What are you trying to read when it locks up, your IP cam? Have you tried reading just the first frame of a simple video? Does mmread lock up then?

If the lock up only happens when you are reading from your camera (or using http) then it might be a software firewall on your computer blocking mmread from connecting.

Just for your information, FFGrab doesn't used ffdshow (useFFGrab=false does).


30 Apr 2009 Erik Benkler

Hi Micah,
I tried your suggestions:
a) the FFGrab.mexw32 was already unzipped
b) In Matlab 7.04, renaming to .dll helps to avoid the error message "Undefined command/function 'FFGrab'"
c) In Matlab 7.5, renaming to .dll is not required ,
...BUT unfortunately I run into a new problem using either Matlab 7.04 or 7.5:
When line 148 of mmread is executed, nothing happens for a long time (waited several minutes although in the 'old' mode of mmread, your sample video is played within a second or so). Matlab says that it is Busy and the only way out is to kill the Matlab process in the task manager. Ctrl-C does not stop execution and taskman doesn't show any activity of Matlab.
I re-installed the latest version of ffdshow (ffdshow-rev2844_20090330_xxl.exe) to make sure the problem is not due to ffdshow, which does not help.


29 Apr 2009 Micah Richert

Hi Erik,

Make sure that you extracted the FFGrab.mexw32 from the zip file. If the file does exist then the only other thing I can think of is you are also using a pretty old version of Matlab. So there is a small chance that it will require you to rename the file FFGrab.mexw32 to FFGrab.dll.

I hope that helps,

29 Apr 2009 Erik Benkler

Hi Micah,

I get the same error message as yl Qiao in the comment from 16 Jan 2009 when using the newest version (downloaded 29 Apr. 2009) of mmread with useFFGrab set to "true":
The error "Undefined command/function 'FFGrab'" occurs in line 148, i.e. at the first FFGrab statement. I am using Matlab 7.04 SP2 on Win XP SP2. When I run mmread with useFFGrab set to "false", it works, at least with the sample file from in the doc. However, I would like to try the FFGrab version on a stream from an axis IP cam, which cannot be read in the old mmread mode (useFFGrab=false). Unfortunately, yl Qiao did not write how he solved the problem.
Best regards, Erik

10 Apr 2009 Sellavelu

Is it possible to extract single frame for every minute of the video?

09 Apr 2009 tmh

Hi Micah,

I use "top" to monitor memory (de-)allocation. A colleaegue of mine on 64-bit Vista does not have this problem, but he uses an older version of Matlab (R2007b). All the best,


07 Apr 2009 Micah Richert

Hi tmh,

There is the possibility of small memory leaks, especially for specific videos. However, calling "clear video" should free all (or at least nearly all) memory. I've tried pretty hard to remove leaks from my own code.

How were you verifying that memory was being freed?


07 Apr 2009 Micah Richert

Hi Brad,

Having a return value for processFrame is an interesting idea, however, I don't see much added value. This is an advanced feature, and most users would be able to get better performance (memory allocation and speed) out of using globals than by relying on mmread to manage this. So, at this time, I don't have plans on adding a return value.


06 Apr 2009 Brad

Could you make it so that processFrame returns a value? So that we don't have to use global variables.

03 Apr 2009 tmh

Hi Micah,

Every time I call mmread in matlab R2008b from the matlab command line:

e.g. video=mmread('/some/path/to/file.MPG');

and subsequently clear memory:

clear video;

memory is not deallocated. I am running this on 64-bit Linux. Do you know of any memory leak issues? Thanks!

31 Mar 2009 Brad

I found at and set LD_LIBRARY_PATH before starting matlab. It's working now. Thanks very much for this.

31 Mar 2009 Micah Richert

Hi Brad,

You or your sysadmin need to install bz2 (bzip2) on your system. You don't need to recompile.


30 Mar 2009 Brad

This looks like a very nice tool. But I get the error message:

Invalid MEX-file 'PATH/FFGrab.mexa64': cannot open shared object file: No such file or

Error in ==> mmread at 148

How can I recompile the mex file on Linux x86_64?

25 Mar 2009 Micah Richert

Hi Krishna,

I just tested 3gpp files and they seem to work fine. Make sure you can use mmread to read other videos on your system. If you have specific files that you can't be read, report the issue to ffmpeg (


25 Mar 2009 krishna warhade

Dear sir,
Really great function to read video. I tried mmread to read 3gpp video files from mobile, but unable to read it. can u modify this function to read 3gpp mobile video files?. it will be of great help to me.

24 Mar 2009 Micah Richert

Hi Buddala,

You will need to download mmread, and unzip ALL the files into a directory on your computer. Then you will need to change Matlab's current path to where you unzipped it (or add the directory to Matlab's path). Then you can use mmread.


24 Mar 2009 Snow Wave

Dear Micah

Your codes work well, thanks!


24 Mar 2009 buddala

My Matlab Software dont have mmread function. Do i need to install any toolbox for that.

23 Mar 2009 Izang

Dear Micah,

Using mmread, how do I get the video resolution from the video information? Is there any appropriate member object I could use?

19 Mar 2009 Snow Wave

Dear Micah

I have email you the link. If any eror, tell me.

Please check it, and give me more advice. Thanks!


18 Mar 2009 Micah Richert

Hi SnowWave,

In order to try to fix the problem I will need a file that causes the problem. Try to find a smaller file or put it up somewhere where I can download it then email me directly the small file or a link to the large file.


18 Mar 2009 Snow Wave

Dear Micah

Thank you for your attention!

The .mpg files which I use "mmread" to process is about 300M. I should get a few frames of the files and turn the frames to image.
When I use mmread to get specific frame and turn it to image, I found it different with the specific frame shown in movie player. I have test four files, get many frames, it shown non-ordered.

I have use matlab 7.7; the mmread also the newest. Would you like to test it ?



17 Mar 2009 Micah Richert

Hi Snowwave,

I just noticed that my original post isn't being display, so here it is again.

Make sure that you have installed the newest version of mmread. If you are still having a problem with mmread, please send me an example video that causes the problem.


17 Mar 2009 Micah Richert

Hi Veronica,

I don't think I understand. Are you saying that each time you call mmread (reading the same frame #) that it takes more time? Or are you saying that reading higher frame #s takes longer than reading lower frame #s? If it is the second one, then that is to be expected. You should try reading all the frames you need using a single call to mmread; this will be the fastest.


16 Mar 2009 Snow Wave

Dear Micah
Thank you for this nice tool!
It runs well when read .avi files; the frames are correct.

But when it used to read .mpg files in this way " mmread('mymovie.mpg',framenumber) "; The video frames returned appear upside-down.

when it used to read .mpg files in this way " mmread('mymovie.mpg',framenumber,[],false,false,'',false,false) "; The video frames returned appear well ordered. But this make the function too slowly.

Would you like to give me more soultion?



16 Mar 2009 Veronica

Dear Micah,

Thank you for providing such a nice tool! I am using the mmread for avi files with size greater than 2GB to read each individual frame for further process. I am running it in Windown (32bit) environment, and I noted that it takes much longer time to read more frames through iteration (each iteration only one frame is read). For example, it takes about .4 sec for 10 frames through 10 iterations, and it takes about 10 sec for 100 iteration, and then it takes for a long long time for 1000 iteration. I am not sure whether this is what I should expect or is it because I used it in a run manner:( Currently, I only included mmread.m, avbin.dll and FFGrab.mexw32 files.

Thank you for your help!




could u please suggest me the solution for the problem mentioned below:

Q)Load the x-ray image of the spine (spine.tif) from the MATLAB 7.0 --Image
Processing Toolbox. Slice the image into 4 different levels then plot in pseudocolor
using yellow, red, green, and blue for each slice. The 0 level slice should
be blue and the highest level slice should be yellow. Use grayslice and construct
you own colormap. Plot original and sliced image in the same figure. (If
the “original” image also displays in pseudocolor, it is because the computer
display is using the same 3-level colormap for both images. In this case, you
should convert the sliced image to RGB before displaying.)

24 Feb 2009 petrichor  
23 Feb 2009 Micah Richert

Hi Adam,

Unfortunately, the last version of mmread that used DDGrab (useFFGrab = false) assumed that there was a sound card; earlier versions did not but had other issues related to this assumption. Suffice it to say that handling audio (even when disabled) in DirectShow is more difficult than you would imagine.

To solve your issue, I will need to either provide you with a custom build of mmread (this will require me gaining access to some old computers...), you could find an old version of mmread floating around (try google, maybe this one:, or add a virtual audio device.

For the virtual audio device you could try this:
However, I have never used this before and have no idea if it will actually work for you.


23 Feb 2009 Adam

Hi Micah,

I'm attempting to use mmread on an .avi file that has been output by Cineform. I have the Cineform codec, but when I use the new FFGrab function, the message returned is "Could not open video stream". The video stream name (in the same directory as the .m files) is Dinosaur-2008-10-29_11-53-16.avi.

If I set FFGRAB to false, the message returned from the old mmread operation states: "Cannot play back the audio stream: no audio hardware is available, or the hardware is not responding." This is the command I used to call mmread:

mmread(videoName,usedFrames(startFrameIndex:endFrameIndex),[ ],false,true,'',true,false);

I don't have audio hardware on my computer (using a server as a workstation), but shouldn't that be a moot point if I have set the 'disableAudio' attribute to 'true'? I only want to use the video extraction capabilities.

I downloaded your code from this website today to have the most current version. I am running MATLAB R2008a on a 32-bit windows server 2003 system.

Are there incompatibilities with the Cineform codec that I am unaware of? Or do you suppose the error is somewhere else in the process?



09 Feb 2009 Micah Richert


I don't know what version of mmread you downloaded but it definitely is not the current version. Please download it again and tell me if you are still have an issue.



The video frames returned by mmread appear upside-down when viewed .
And the o/p is shown in command window as:
0x0 structure

even FFgrab isnt wrkng .
error produced is: undefined command/function "useFFgrab "

i m using matlab 7.0
window xp sp 3.
what should i do?

05 Feb 2009 Micah Richert

H All,

The code has just been updated. Several bugs have been fixed and there are a couple speed improvements. The most notable improvement is that sequential reads are now much faster.

For example, the following code is MUCH faster:
for i=0:99
v=mmread('myvideo.mpg',(1:10)+10*i); %reads 10 frames at a time

The improvement also helps when time ranges are specified.


30 Jan 2009 Micah Richert

Hi Tycho,

You shouldn't need to compile the code yourself, all mex files are included. I actually didn't intend to include buildlinux.m in the zip...

If you do want to compile it yourself you need to download the source code for AVbin ( and put it in a subdirectory of mmread called avbin.


28 Jan 2009 tmh

Hi Micah!
Thanks for the very useful code.

If anyone could help, or give a hint I would greatly appreciate it:

I am having trouble getting this compiled on a Linux 64-bit system (Ubuntu Intrepid 8.10). When I issue the command buildlinux from the matlab command line I get a warning followed by a slew of errors (first two listed):

Warning: You are using gcc version "4.3.2-1ubuntu12)". The earliest gcc version supported with mex is "4.0.0". The latest version tested for use with mex is "4.2.0". To download a different version of gcc, visit

-> g++ -c -Iavbin/include -Iavbin/ffmpeg -I/usr/local/matlab-R2008b/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "FFGrab.cpp"

FFGrab.cpp:44:20: error: avbin.h: No such file or directory
FFGrab.cpp:45:35: error: libavformat/avformat.h: No such file or directory ...

followed by a slew of other errors.

18 Jan 2009 yl Qiao

Hi Micah

The problem is solved. Thanks.

Is there some little mistake in this program?

function [video, audio] = mmread(filename, frames, time, disableVideo, disableAudio, matlabCommand, trySeeking, useFFGRAB)



The parameter useFFGRAB can not control the program. (useFFGRAB,? USEFFGRAB ?)

17 Jan 2009 Micah Richert

Hi yl Qiao,

Mmread now requires Matlab 7 and above. If you are using Windows you can set useFFGrab to false and you will be able to use the older version of mmread that supports 6.5. However, I strongly suggest you upgrade Matlab.


17 Jan 2009 yl Qiao

Hi Micah,

I am trying to read a avi file using mmread. However there is an error:
??? Undefined function or variable 'FFGrab'.

The version of my Matlab is Matlab 6.5. Should it be MATLAB 7 ?(R14)

Many Thanks

13 Jan 2009 Micah Richert

Hi Alex,

I don't see how that passed my testing... Edit mmread.m and change 'makedir' to 'mkdir' then it should work.


13 Jan 2009 Alex Kloth

Trying to run on Mac OS X (Leopard) with MATLAB v. 7.5, I get the following:

libavbin.dylib needs to be installed.
Shall I install this for you (no admin required)? [Y/n]y
??? Undefined function or method 'makedir' for input arguments of type 'char'.

Any help? Thanks, A.

12 Jan 2009 Micah Richert

Hi Holger,

The way to use processFrame is not in a loop as you are doing, but a single command:


processFrame will then be automatically called for each frame. In order for you to do something useful you will need to store the result in a global variable and then access that global variable after the call to mmread is completed. For more information on global variables, type "help global" at the Matlab prompt.

As far as the out of memory error. I have a few ideas as to what might cause that, but if you still have a problem after using processFrame correctly then contact me directly.

I hope this helps,

09 Jan 2009 Holger Goerlitz

Hi Micah,

thanks for your help. You're right, when I disable trySeeking, it correctly reads and displays every frame that I give as an argument to mmread. Unfortunately, this makes the function too slow for me, so I have to find another way. Is it possible that mmread with trySeeking=true sometimes does not read the correct frame as specified by the framenumber?

I looked into the processFrame option, and I'm sorry, I don't really understand how to use it - would you offer some more advice on that? Am I expected to adjust processFrame.m to my needs, e.g. where it says "% now do something with the data..."? However, I also get my original problem (which is that the displayed image does not correspond to the framenumber) when I use processFrame.m without changing it:

for i=1:1000,

The displayed image is changing roughly every 10-30 frames, and then for the next 10-30 frames the displayed image does not change again.

Some other observations that might help to figure out what is going on:
- In the above code which includes "processframe", I sometimes
also get Matlabs Out Of Memory Error.
- Without using "processframe", the video-structure returned by mmread does not contain any image-data, i.e., video.frames is a 1x0 structure array.

I'm sure I'm doing something wrong here, especially with processframe - any help would be highly appreciated.


08 Jan 2009 Micah Richert

Hi Francesca,

I also didn't notice this earlier. You are using the old version of mmread. Please try to the new version and see if that solves your problem.


08 Jan 2009 Micah Richert

Hi Holger,

To be able to read more frames than fit in memory, I strongly recommend looking into using processFrame.m (in mmread). As far as why the frames aren't changing, this probably has to do with having trySeeking turned on (the default behavior).

For example:

You can safely ignore the warning message about shadowing. It has to do with Matlab changing the file extension of mex files on Windows.


08 Jan 2009 Holger Goerlitz

Dear Micah,

thanks for this code; that seems to solve my problems of working with mpeg2 movies in Matlab.

I get the same Warning message as Francesca pointed out above:

Warning: In the directory "D:\common\matlab\_MatlabCentralToolboxes\mmread",
mexDDGrab.mexw32 now shadows mexDDGrab.dll.

but I can open my mpg-file. Is this anything to worry about?

In addition, I have another problem: I am stepping through a long mpeg2 movie, reading and displaying only one frame at a time, using mmread('mymovie.mpg',framenumber). However, when I successively increase framenumber by 1, it seems that mmread keeps retrieving the same image (there is now change visible in the displayed image). Only when doing bigger jumps of sometimes 10 or 50 frames, I really get the new frame.

Do you have any idea what's going on here?

Thanks for your help, and again for mmread as a whole!

08 Jan 2009 Francesca

Dear Micah,

I have the following segmentation violation problem when using your function:

>> [video] = mmread('br100.avi')

Warning: In the directory
mexDDGrab.mexw32 now shadows
Please see the MATLAB 7.1 Release Notes.
Saving minidump to file C:\DOCUME~1\FR9331~1\IMPOST~1\Temp\matlab_crash_dump.1316.0.dmp

Segmentation violation

MATLAB Version: (R2007b)
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 3)
Processor ID: x86 Family 6 Model 14 Stepping 8, GenuineIntel
Virtual Machine: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Default Charset: windows-1252

Register State:
EAX = 0acea7e8 EBX = 00bec49c
ECX = 00bec49c EDX = 0ace9648
ESI = 000002f0 EDI = 00000010
EBP = 00000002 ESP = 00bec43c
EIP = 0c39657f FLG = 00010206

Stack Trace:

This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

If it is an official MathWorks function, please
follow these steps to report this problem to The MathWorks so we
have the best chance of correcting it:

The next time MATLAB is launched under typical usage, a dialog box will
open to help you send the error log to The MathWorks. Alternatively, you
can send an e-mail to with the following file attached:


Any idea on what it is happening here?

Many thanks!


16 Dec 2008 Micah Richert

Hi everyone,

I just contributed a brand new version of mmread. It now supports Windows, Linux and Mac. It is a complete rewrite but still functions virtually the same on Windows systems. If however, you need/want to run the old version, simply set useFFGRAB to false.

The code uses AVbin ( which is built off of FFmpeg ( If you have a problem with reading a file, you can try updating the avbin libraries with ones from the AVbin site (rename the files to match the ones included with mmread).

Some Mac users and all Linux users will require some sort of installation. If you are the only one using it mmread's default install will work fine. If however, more than one user will be using mmread, the appropriate libavbin file should be installed in /usr/local/lib (or elsewhere) by the system admin.


04 Dec 2008 Ian Charest

Hi Again

Problem solved, sorry again for the long thread, it can be removed
here was the problem:

trying first:
[video audio] = mmread((listeT(mm));

got me the lousy segmentation violation


[video audio] = mmread(cell2mat(listeT(mm)));

solved it

Thanks again for the great function.


04 Dec 2008 Ian Charest

Hi Micah,
This toolbox is very useful, I have no problem reading my avi files.
However, when I try to read my wav files, I get an error message that I can't interpret. I have seen this error reported by someone else before but for another function.
I get this error: (Sorry if it is too long)

------------------------------------------------------------------------ Segmentation violation detected at Thu Dec 04 12:49:35 2008

MATLAB Version: (R2007b)
MATLAB License: 294300
Operating System: Microsoft Windows XP
Window System: Version 5.1 (Build 2600: Service Pack 3, v.5657)
Processor ID: x86 Family 6 Model 14 Stepping 8, GenuineIntel
Virtual Machine: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode
Default Charset: windows-1252

Register State:
EAX = 00000000 EBX = 5d5e9550
ECX = 00000000 EDX = 00000200
ESI = 1475f360 EDI = 00ced7fc
EBP = 00cecdc0 ESP = 00cecd88
EIP = 14fd283b FLG = 00210202

Stack Trace:
[0] mexDDGrab.mexw32:0x14fd283b(0x1475f360, 0x00cecdf4, 0x7840586f, 0x1850c380)
[1] mexDDGrab.mexw32:0x14fd20fb(0, 0x00ced7fc, 1, 0x00ced88c)
[2] libmex.dll:_mexRunMexFile(0, 0x00ced7fc, 1, 0x00ced88c) + 139 bytes
[3] libmex.dll:private: void __thiscall Mfh_mex::runMexFileWithSignalProtection(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00ced7fc, 1, 0x00ced88c) + 86 bytes
[4] libmex.dll:public: virtual void __thiscall Mfh_mex::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00ced7fc, 1, 0x00ced88c) + 261 bytes
[5] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00ced7fc, 1, 0x00ced88c) + 203 bytes
[6] m_interpreter.dll:void __cdecl mdCallFunction(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_MATLAB_fn *)(0, 0x00ced7fc, 1, 0x00ced88c) + 56 bytes
[7] m_interpreter.dll:public: void __thiscall ResolverFunctionDesc::CallFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag * * const)(0, 0x00ced7fc, 1, 0x00ced88c) + 93 bytes
[8] m_interpreter.dll:public: bool __thiscall Resolver::CallMFunction(int,int,class _m_operand * const,union m_operand_storage *,int,class _m_operand * const,union m_operand_storage *,int *)(0, 1, 0x14f9b760, 0) + 1388 bytes
[9] m_interpreter.dll:bool __cdecl inResolveMFunctionCall(struct _m_function_desc *,int,int,class _m_operand * const,union m_operand_storage *,int,class _m_operand * const,union m_operand_storage *,int *,enum inMarshalType *,int,class mpsTypeSequenceNlhs const *,struct mxArray_tag * (__cdecl*)(int))(0x13cdc7b8, 0, 1, 0x14f9b760) + 195 bytes
[10] m_interpreter.dll:private: bool __thiscall accelImpl::MFunctionCall(struct _accelOp * *)(0x00cede98, 0x909a1157, 0x15ebf050, 0x14388220) + 179 bytes
[11] m_interpreter.dll:public: enum jitReturnFlags __thiscall accelImpl::Exec(void)(0x909a11cf, 0x15ebf050, 1, 0x00cee24c) + 205 bytes
[12] m_interpreter.dll:public: enum jitReturnFlags __thiscall accelCode::Call(enum inMarshalType *,int *)const (0x00cedf9c, 0x00cedf74, 0x909a1083, 0) + 128 bytes
[13] m_interpreter.dll:public: static bool __cdecl inJit::ExecuteHotSegment(struct _inJitAccelInfo *,enum opcodes *,int *,int *)(0x00cee044, 0x00cee0f8, 0x00cee0a8, 0x00cee24c) + 1898 bytes
[14] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 2583, 269, 0) + 338 bytes
[15] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2583, 120, 0) + 87 bytes
[16] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 2583, 120, 0) + 274 bytes
[17] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0x146b47e0, 0x14753200, 0x909a2b3b, 0xffffffff) + 916 bytes
[18] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(2, 0x00cee4c4, 1, 0x00cee524) + 673 bytes
[19] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 2, 0x00cee4c4, 1) + 29 bytes
[20] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00cee4c4, 1, 0x00cee524) + 28 bytes
[21] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(2, 0x00cee4c4, 1, 0x00cee524) + 203 bytes
[22] m_interpreter.dll:__catch$?inDispatchFromStack@@YAHHPBDHH@Z$0(815, 0x169ab71c "mmread", 2, 1) + 744 bytes
[23] m_interpreter.dll:enum opcodes __cdecl inDispatchCall(char const *,int,int,int,int *,int *)(0x169ab71c "mmread", 815, 2, 1) + 156 bytes
[24] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(2, 0, 0, 0) + 2739 bytes
[25] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 87 bytes
[26] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(2, 0, 0, 0) + 274 bytes
[27] m_interpreter.dll:_inInterPcode(2, 0x909a27c3, 0, 0x1239ee20 "[video audio]=mmread(listeT(13))..") + 162 bytes
[28] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_eval_function(int *,struct _pcodeheader *,int *,struct mxArray_tag * * const,enum inDebugCheck,bool)(0x00cef2bc, 0x00cef32c, 0x00cef358, 2) + 152 bytes
[29] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalStringWithIsVarFcn(struct _memory_context *,char const *,enum EvalType,int,struct mxArray_tag * * const,enum inDebugCheck,struct _pcodeheader *,int *,bool (__cdecl*)(void *,char const *),void *,bool)(0x7ac2177c, 0x1239ee20 "[video audio]=mmread(listeT(13))..", 0, 0) + 2454 bytes
[30] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturnandtype(char const *,int *,enum inDebugCheck,bool)(0x1239ee20 "[video audio]=mmread(listeT(13))..", 0, 2, 0) + 107 bytes
[31] m_interpreter.dll:_inEvalCmdNoEnd(0x1239ee20 "[video audio]=mmread(listeT(13))..", 0, 0x914c788a, 0x7ab9e7f0) + 20 bytes
[32] bridge.dll:enum inExecutionStatus __cdecl ThrowSignal(char const *)(0x1239ee20 "[video audio]=mmread(listeT(13))..", 0x914c7fc6, 0x014d3f90, 0x014d3f30) + 77 bytes
[33] bridge.dll:__catch$_mnParser$0(0x93d507b0, 0x014d3f30, 0x014d3f30, 0) + 292 bytes
[34] mcr.dll:public: void __thiscall mcrInstance::mnParser(void)(0x93e1596b, 0x004043f0, 336710, 0) + 62 bytes
[35] MATLAB.exe:0x00401414(4194304, 0, 336710, 10)
[36] MATLAB.exe:0x00401733(0, 0, 0x7ffde000, 0x8054b6ed)
[37] kernel32.dll:0x7c817067(0x00401910, 0, 0x78746341, 32)

Any idea?

I am using Matlab 7.5.0 (R2007b)


14 Oct 2008 James Edwards

Excellent! Works straight away without compiling on Vista x64

29 Sep 2008 Micah Richert

Hi Rainer,

Windows Direct Show infrastructure does not support 565 encoding, as a consequence mmread does not either.


29 Sep 2008 Micah Richert

Hi Barba,

The problem is that the codec used to compress the video does not accurately report the time for your videos. This isn't really mmread's fault; however, to fix the problem set trySeeking to false. This will make reading your movies slower, but the time and frame information more accurate.


18 Sep 2008 Rainer Graser

One question
I have an avi-file were the RGB data has a 565 structure did anybody know how can i get singel pictures with this structure and not with a RGB 888 structure

17 Sep 2008 Barba Pere

I have noticed some problems

I am using matlab 2007b(7.5), and wvenever I load entire movie, totalDuration is set to 0. The movies I try to load are taken with Photocamera, and they are 15fps 320x240(low res, low quality).

also, when I try to load only first frame in those movies, i have to write mmread('name.avi',0), because if i write mmread('name.avi',1), he returns the second frame.

I have tried it with some wmv HD movies, but it works fine with them.

12 Sep 2008 Adam G

I am trying to compile mmread with the matlab compiler, mcc.
The exe that is created crashes with a run-time error on the 1st mexDDGrab() command (right after the try statement).
How can I fix that?

18 Aug 2008 Till Hartmann  
11 Aug 2008 Micah Richert

Hi Mathijs,

It sounds more like a problem with Virtualdub; you should contact them for help. mmread won't be able to read a video until Windows Media Player does.

If you are making the video out of a series of images, why don't you just read the images in Matlab?

Sorry I can't help more,

10 Aug 2008 Mathijs van Vulpen

Hi Micah,

Is there a way to disconnect the require codecs from Windows Media Player? mmread cannot read any avi file that I create with Virtualdub, because it cannot find the correct codec. Windows Media Player cannot play the file either, however VLC player can! and Media Player Classic can too! How is this possible?
With Virtualdub I create a high speed avi with a frame rate of 100 fps from multiple bitmap images. It does not matter which compression method I use, mmread is unable to read the file and media player cannot play it, how can I solve this problem?
Eventhough aviinfo can read the info from the avi file aviread, however, cannot read the file :S
Please help.

01 Aug 2008 Nikeah San

Cant believe I didn't come across this earlier! This made things a whole lot easier for me!:-) thanks!

31 Jul 2008 Micah Richert

Hi Andrea,

Are you using the latest version of mmread (2008-04-28)? This sounds exactly like the multi-threaded bug addressed in that release. I also can't get it to crash on my computers (using the newest version). Email me directly if you still have problems.

27 Jul 2008 Andrea Merlo

Hi Micah,
thank you so much for your work. I've installed mmread on my laptop, with MATLAB Version 7.5 (R2007b) and Windows Vista.
Your code works fine, after removing mmread.dll, as suggested.
As described by Mr. Songhao Zhu, Matlab is forced to close while trying to read an mpeg2 file. A similar behavior was addressed by Mr Abbas Cheddad with an avi file.
The problem appears at line 141 of mmread: mexDDGrab('doCapture') and is not managed by the try/catch instance
The problem takes place both using and not using ffdshow
I got this error on the files "slime.mpeg" and "dhl.mpeg", which can be downloaded from the following web page
An important point is that the software doesn't crash, with the same files, if the disableAudio input parameter is set to true
Is this a problem of codec? Do you have any suggestion?
Thank you again for delivering mmread.

03 Jul 2008 wu chengmao  
26 Jun 2008 Brian Hui

I have renamed mexDDGrab.dll to mexDDGrab.dll.old since Matlab 7.1 start using mexw32 as the compiled file, when a dll and mexw32 with same name in the same folder, it will report a warning.

Warning: In the directory "C:\arg_repos\external\Matlab\mmread", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.

If you are using Matlab below 7.1, you can name it back .

23 May 2008 Scott Smith

A truly excellent media reader. It literally took me 1 minute to replacement my aviread() call for video file input with mmread() and it works great!

08 May 2008 Ajay Patel  
06 May 2008 Micah Richert

Hi Marco,

Unfortunately, Microsoft doesn't provide very useful error messages...

You can try a few different calls to mmread to see if it makes any difference, such as:

%video only
v = mmread('axrtpm://',1:10);


%audio only
[v,a] = mmread('axrtpm://',[],[0 1],true,false);

If neither of those work, we can try doing some debugging, but to do that email me directly.


05 May 2008 Marco Francini

Hi Micah,

i have tried with GraphEdit and it doesn't work; i tried also with Media Player and it doesn't work; the URL i used in these experiments is rtsp://
The Axis ip camera supports an other URL axrtpm:// and i tried this and it works in GrapEdit and Media Player; if call mmread('axrtpm://') matlab replies ??? No such interface supported.
What can i do now?


30 Apr 2008 Marco Francini


First of all i want to congratulate with you for the great job you've done. That's my problem: I am using an Axis Ip Camera. What I want to do is to process the video stream coming from the ip-camera in Matlab. The ip-camera sends out a Motion JPEG stream or a MPEG4 stream. I tried to launch this command mmread('rtsp://',[],[0 5],false,false,'processFrame'); but Matlab replies "unknown error". Can you help or suggest me a way to make it works?

Thanks a lot,

24 Apr 2008 Micah Richert

Hi Zhu,

The code doesn't use ActiveX. It uses DirectShow, which is a part of DirectX. You'll have to give me some more details for me to figure out what is going wrong. If you can send me the code you are using that is causing the problem that will help and if you can send a movie that causes the problem that would really help.


22 Apr 2008 songhao zhu

Hi! Well done man. I just experience sometimes a problem when using mmread, MATLAB will be forced to close. I restart it for many times for the mmread to work, I think it has something to do with ActiveX. And I download the new version 'ffdshow' however the problem still happens.What do you think?

22 Apr 2008 Micah Richert

Hi Brent,

This really is a question relevant only to mmwrite. The problem is that Vista (and maybe some versions of XP) now require that the width and height of the movie be a multiple of 2 (and under some circumstances a multiple of 4). This error message is a generic error, but it indicates that the video size isn't supported.


14 Apr 2008 Brent F

I just discovered mmwrite (and read). It looks very helpful piece of code.

Unfortunately I have been getting this (for instance, from the last example in the mmwrite help documentation).

??? Error using ==> mmwrite
WMProfileManager can not load prx profile.

Error in ==> test at 15

I don't know if this is a factor: Vista 64. Below messages are sort of ambigious as to whether Vista 64 is supported.

I looked at the CPP code, and see the error message, but couldn't garner and further clarity on what profile it is failing to find.


08 Mar 2008 qingkai bu


12 Feb 2008 Jorn OdB

As a researcher I find this tool very useful for quantitative analysis of video material. And occasionally I use it in conjunction with mmwrite to convert video-files.

Note: I had to change the && to a single & and put in: true=1; false = 0; in mmread.m to make it work for matlab 6.

30 Jan 2008 Elena Ranguelova

The decoder installation was not properly done, now it works fine! Thanks!

29 Jan 2008 Elena Ranguelova

Dear Micah,

I've used your mmread and I find it very useful! It worked fine with not so large videos of various formats. Unfortunately now I have a problem with large AVI videos (> 500 MB). I'm getting the following error

The 'No combination of intermediate filters could be found to make the connection' error
means that no appropriate codec could be found. Mpg2 files seem to be the worst.
Installing ffdshow ( often fixes this problem.
??? Error using ==> mexDDGrab
No combination of intermediate filters could be found to make the connection.

Error in ==> VM_openCallback at 34
[video_info, audio_info] = mmread([movie_path_name movie_fname],1:nframes); %#ok<NASGU>

??? Error while evaluating uipushtool ClickedCallback

I have installed the mentioned codec (in the message and also in your reply to the other postings), but I still get the same error :-( Any suggestions?


30 Oct 2007 Micah Richert

Hi Krishna,

First, make sure that you are using the newest version of mmread. Second, try comparing the execution time between having trySeeking set to true and false.

tic; mmread('video1.avi',[],[ST ET],false,false,'',true); toc
tic; mmread('video1.avi',[],[ST ET],false,false,'',false); toc

If when tryseeking is false is a lot slower than when it is true, than nothing can be done to go faster because the code is already seeking to the time that you specified. If they are taking the same amount of time, then try updating your codec and seeing if that then allows the code to seek.


29 Oct 2007 krishna warhade

Dear sir,
i am using mmread for reading video framewise. as per ur command
[video, audio] = mmread('video1.avi',[],[ST ET]); if i wanted to work on video having 1,50,000 frames and wanted to read from 1,12,992 to 1,13,472 frames. then my ST=4708 sec and ET=4728 sec. and ur command really works. but the only problem is ,it takes so much time to read the frames(comptation time is large),also it requires more memory. i think ,if i wanted to read frames from 1,12,992 to 1,13,472 frames, ur command reads from first frame and then it will go to 1,12,992 frames. is it possible to read these frames directly,sothat computation time will be less

19 Oct 2007 Micah Richert

Hi Romulo,

It sounds like you have a buggy codec. Try installing ffdshow ( and seeing if this clears up the problem. This was also Abbas' problem.

The "Shadow" warning is completely harmless and is because I include both a .dll and a .mexw32 file.


18 Oct 2007 Romulo Fuentes

Hi Micah,
We are trying to read a complete mpg file every 30 frames.We use as second input argument the vector [1:30:video.nrFramesTotal], where
video.nrFramesTotal was obtained by previously reading the same file but just the first frame.
When we use the vector I mentioned, a warning appears:
'Frames(s) frame_numbers exceed the number of frames in the movie'
All the frame numbers in the warning are smaller than video.nrFramesTotal. After that Matlab will display a segmentation violation error message. Could you please give us a hint of what is happening or tell us
another way to get the hole file readed every N frames?
By the way, every time we run the script(even if it works fine, which is for small number of frames) we get the warning message:
'Warning: In the directory "C:\Documents and Settings\Owner\My Documents\MATLABSCRIPTS\per", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
> In mmread at 121'
Thank you very much

10 Oct 2007 Abbas Cheddad

Well done man. I just experience sometimes a problem when using mmread, MATLAB will be forced to close. I restart it for many times for the mmread to work, I think it has something to do with ActiveX. What do you think? the file am reading is not that big, less than 2MB avi file.


20 Sep 2007 khalid Niazi

Hello again,

Its working. Thanks a lot, you have done a great job. God bless you.

19 Sep 2007 Micah Richert

Hi Khalid,

The 'An object or name was not found' error means that the path+filename that you passed into mmread doesn't exist. Make sure you specify the full path to the file unless the file is in the same directory as Matlab's current directory.

19 Sep 2007 khalid Niazi

Hi Micah, I am trying to read an avi file using mmread, but getting an error,

Warning: In the directory "C:\Documents and Settings\BMC", mexDDGrab.mexw32 now shadows mexDDGrab.dll.
Please see the MATLAB 7.1 Release Notes.
??? An object or name was not found.

Currently I am using MATLAB 7.3(R2006b) on 32bit windows. Can you please help me out. Thanks in advance.

16 Aug 2007 Tim Streeter  
01 Aug 2007 susan thomas just made my data processing so much easier. True, processing from the beginning of the video for every frame is slow, but there is no loss of data, which is CRUCIAL for my time-sensitive application. So again, thanks.

25 Jul 2007 Mahocan Ganemur

Mr. Richert,

Do I have any chance to change the source code to make rendering process start not from the beginning? I need to extract mpeg2 video parts (from starttime to stoptime) from the whole video not very time-sensitive. If it is possible, I would be grateful if you describe what should I do to prevent the codec rendering the file from beginning and to enable it resume, from the point accessed last time in the file. Is some work at the "CleanUp" procedure of the DDG class enough? Or else?

21 Jul 2007 Mahocan Ganemur

Hi Mr.Richert,

Thanks for your explanation on the problem. I applied your suggestions with GraphEdit. I would like to point something that I experienced on the usage of Graph Edit for the people who will use this solution in the future. Since I aimed to use only the audio of the MPEG2 video, I set up the graph with and without "Null Renderer" block to be attached to the video stream by thinking there would be no important difference. I gathered "wav" audio in 6-7 mins. from a 3-hour MPEG2 video file when I did not use "Null Renderer" and more than 2 hours otherwise(by attaching Null Renderer block to the video stream). Though, this block discards the video samples, it still brings same delay as if the video was being processed, I think.
Found no more difference in these two cases. Consequently, I suggest the users that not to attach null renderer block if you dont need the video sequence of a video file, just leave the video output of the demux unconnected. Thanks for your helps again. Bye!

09 Jul 2007 Micah Richert

Hi Mahocan,

I am aware of what you are describing. Unfortunately not all codecs seek to the correct time (especially when there is audio). So to ensure that no data is lost or repeated, I force the movie to render itself from the beginning even when time or frames are specified.

A better solution would be to strip the audio from the movie and put it into a wav file. You can do this rather easily by using GraphEdit (google it). Just Render the .mpg file and attach a NullRenderer to the video stream and attach a "WAV Dest" to the audio stream. This mentions it briefly:

You could then read the wav file using mmread or wavread.


09 Jul 2007 Mahocan Ganemur

Thanks for building such a useful function. I have a problem on decoding and getting frames from MPEG-2 files.
I set a loop with the function mmread that reads the video file in sub-sequential manner. In every step it reads 5 minute-part of the mpeg2 video from the source file. I installed several types of mpeg2 codecs to run the code (i.e. ffdshow, dscaler mpeg2 filters, ligos etc...). The problem is that in any step of the loop, the decoding process starts from the very beginning of the video. For example, if the loop must read the part between 60 and 65th minutes of the video the program starts from the beginning of the video from the first frame, reaching to 60th minute that we need then it starts acquiring the video part that we need after a long time taken. The time taken for the program to reach the acquisition point in every loop step, is too long to be accepted. The time performance of the program is getting unacceptable,especially reading parts from longer mpeg2 video files (Actually my program needs only the audio part of the video. Although I set "DisableVideo" property as TRUE, the program still need to decode video part as well. Is there any way to skip video completely?). Is there any suggestion to overcome this problem? Can I configure codec and / or mmread function to make it start from the closest point just we need to read data from? Thanks in advance...

06 Jul 2007 Micah Richert

Hi Wei,

You need to change the current directory to where you have mexDDGrab.cpp (i.e. where you unzipped

I am curious to know why you are trying to compile the code.


04 Jul 2007 Wei Liu

Hi, I met a problem when I run "builddll.m" as follows:
"Generated build.m Run this in the future to compile.
Running: mex -I'C:\Program Files\Microsoft DirectX SDK (June 2007)\Include' -I'C:\Program Files\Microsoft DirectX SDK (June 2007)\Include' -I'C:\Program Files\Microsoft DirectX SDK (June 2007)\Include\atl' mexDDGrab.cpp DDGrab.cpp 'C:\Program Files\Microsoft DirectX SDK (June 2007)\Lib\Strmiids.lib' 'C:\Program Files\Microsoft DirectX SDK (June 2007)\Lib\Quartz.lib'

C:\MATLAB7\BIN\WIN32\MEX.PL: Error: 'mexDDGrab.cpp' not found.

??? Error using ==> mex
Unable to complete successfully"

Can you kindly advice me how to solve this? Thanks a lot

Error in ==> makedll at 92

01 Jun 2007 myoung chone an

Good !

I have a questione. How can I get captured images through mmread function. because I want to use captured images.

thank you! for your function^^

30 May 2007 Panos B.

THANK YOU!!!!!!!!!!!

It was so easy, but I couldn't solve it!

I'm grateful for your help (and specially for your quick response)!

29 May 2007 Micah Richert

Hi Panos,

The "No combination of intermediate filters could be found to make the connection" error means it can't find an appropriate codec/decoder. Mpg2 files seem to be the worst. Generally, installing ffdshow ( fixes this problem.


29 May 2007 Panos B.


Very useful program! GREAT WORK!

But I have a problem specially with the .mpg files. Matlab returns me the error "??? No combination of intermediate filters could be found to make the connection.".

I haven't any ideas what this error is! Could anyone help me with this?

Thank you!

15 May 2007 arun ramki

easiest tool yet for multi-media.

12 Apr 2007 Micah Richert

Hi Harish,

It sounds like a path issue. The error simply means that it can't find the function mexDDGrab. For your system this should either be mexDDGrab.mexw32 or mexDDGrab.mexw64 . Make sure that these are in the same directory as mmread.m and you may need to delete mexDDGrab.dll from the directory.

Hope this helps,

12 Apr 2007 Harish Bajaj


You've got a great program here. I just installed matlab 2007a though and it seems that the mexDDGrab function is broken.

It keep giving me an error saying,

'Undefined function or method 'mexDDGrab' for input arguments of type 'char'.

I was using it and it worked fine on Matlab R2006b.

I am also using Windows Vista (64bit) although I don't think that it should be the problem.

28 Mar 2007 Xuan Le

Wonderful function!!!

16 Mar 2007 Micah Richert

Hi Stefan,

I don't have any 10-bit video files. If you could email me a small one (<20mb) or include a link to where I can download one that gives you a problem I can look into what the issue is.


16 Mar 2007 Stefan Gottschlag

Great file. I am using Matlab 7.3.0 and 10 bit avi video. In Media Player the video is shown correct. With your file their are stripes and different colors.

Can I fix that?

11 Mar 2007 Micah Richert

Hi All,

I just added 64-bit Matlab support.


02 Mar 2007 Micah Richert

Hi x su,

It sounds like you are having a problem with Windows. Can you play these movies on that computer using Windows Media Player?

I did a quick search and following the instructions on this page may fix your problem:


02 Mar 2007 x su

thanks for your reply, I am using Matlab 6.5, but when I tried to use it, it can not get through:

video=mmread('tr18.wmv', 1:10);
??? An invalid media type was specified.

??? Class not registered

??? Class not registered

how can I fix that ?

Thanks a lot.

01 Mar 2007 Micah Richert

Hi x su,

You do not need to compile the cpp files. The compiled mex files are already provided in the zip file you download from here.

If you are using 64-bit Matlab that is not supported.


01 Mar 2007 Micah Richert

Hi krishna,

Can you email me the matlab commands that you are using and a short video that causes the problem? It seems to work correctly when I test it.


01 Mar 2007 x su

hi, I want to know how to compile the cpp files. I tried in Visual studio c++ and cygwin, but none of them works and the mmread does not work without the mexDDGrab defined... Thanks...

01 Mar 2007 krishna warhade

Excellent program,
But this program is not
working if we want to read in between frames for example. 2000 to 5000 frames only (it reads frames from 1 to 5000 continuously) from the video,then option given to read video from [0.25 0.5] doesn't work. will it requires some modification?

23 Feb 2007 Nilimb Misal

great makes my work easy

21 Feb 2007 Khalid Khan

Nice work dear

15 Feb 2007 Micah Richert

Hi Karthik,

64-bit Matlab under Windows is not currently supported. I don't have a system to test/setup this on.

You have two options. One option is to run Matlab in 32-bit mode (by far the easiest option).

The other option is to try compiling the code yourself. You will need to install Visual C++ Express (it's free) and then go through all of the steps needed to build the DirectX/DirectShow libraries, then try to get everything to compile together (makedll.m). I'm not even positive that it will work, there are several levels where things can go wrong. However, I invite anyone to try and please if you get it to work tell me so that other people can benefit.


15 Feb 2007 Karthik kasi


i am using a 64 bit computer. i tried to run your software and it is giving me this error message

"Undefined command/function 'mexDDGrab'"

i am not sure what the problem is and i would really appreciate if you could help me with this.



25 Jan 2007 Parthipan Siva

Great job!

25 Jan 2007 Erik vdB

Good program, although it regularly causes blue-screens! (R2006a, XP SP2)

14 Dec 2006 Noman Shaukat

Got it....
Great work dude

14 Dec 2006 Noman Shaukat

how can i get a single frame from the video?

07 Nov 2006 Mak mak

Nice program. Most of the time it works but I noticed following issues.
1. Sometimes it does not read the last frame of MPEG-2 file.
2. If Windows Media Player is opened then it works. Otherwise it gives error message about incorrect or unavailability of filter.

thanking you

12 Oct 2006 Radu Preda

Great work! Do you have a mmwrite function as well? I would like to create MPEG2 files in matlab, but haven't found any function doing this (only for MPEG1 files - function mpgwrite). Can antone hel me? Thanks

19 Sep 2006 clark bodie


17 Sep 2006 John Franklin

Had some video files requiring an obscure codec and the files were also too large to fit into memory all at once. Didn't know what to do until I found this package! Thanks very much. Fantastic work!

13 Aug 2006 akshada bhole


09 Aug 2006 Isbelle B  
28 Jul 2006 Micah Richert

Hi Vince,

I just uploaded a new version of mmread, maybe it will fix your problem (I doubt it though). Have you tried playing the same file in Media Player, how does it sound there?

I've tried reproducing what you describe by loading a .wav file that is saturated (has many high peeks), but what is loaded is identical to what wavread loads.

You can try sending me an example, otherwise I don't know what to say.


28 Jul 2006 Vince Badagnani

This is a pretty good utility, but I was having problems with the audio. For some reason during extraction of the audio data, the peaks were inverted creating a very distorted signal.

07 Jul 2006 Heiko Dankert

I have HUGE WMV-Files for reading and processing image-by-image. How could one get this program reserving memory only for one single frame? That would be much faster and saving memory ...

27 Apr 2006 Micah Richert

Hi Ray,

Go ahead and send me a small file that causes the problem. It seems like it should be pretty easy to debug.


27 Apr 2006 ray fire

There might be something wrong when it reads the last frame in some uncompressed avi.when I try to use mmread to read frames including last frame of some 320*240*32 uncompressed avi files which is produced by sony vegas,an error dialog like "memory 0x1684031 cannot be wriiten" will occur and matlab was forced to close without leaving any message...but it will work fine if not reading the last frame.sometimes the same error will also occur when reading the whole mpg file,but not often.the error happened both on matlab 7.1,windows xp s2,and also on matlab 7.2,windows server 2003.
I can send the avi file to your e-mail box,if needed.
Hope the program will be an excellent tool...

10 Apr 2006 Micah Richert

Hi Bindi,

First of all, you almost certainly don't need to compile the code yourself. The included .dll or .mexw32 file should work fine for you.

As far as the makedll interface, it is asking you to make a selection. To choose the first one, type 1 and then enter. I probably should add more instruction, but makedll was mainly for my own benefit and only intended for serious programmers.

09 Apr 2006 Bindi Dharia

i am gettin this error everytime i try to run the file in matlab
There are multiple options for DirectX_SDK_Include_dir please choose one of the following:
1 C:\Program Files\MATLAB71\sys\lcc\include
2 C:\Program Files\Microsoft DirectX SDK (February 2006)\Include
??? Subscript indices must either be real positive integers or logicals.

Error in ==> makedll>getpath at 99
path = path{choose(pathname,path)};

Error in ==> makedll at 39
DirectX_SDK_Include_dir = getpath('DirectX_SDK_Include_dir', DirectX_SDK_Include_dir, 'ddraw.h');

What could possibly be wrong
Can you give the exact sequence to use the function

08 Apr 2006 Lang Hong

Great program!

24 Feb 2006 Kasey Horton

Thanks. I'll check back for the update.

22 Feb 2006 Micah Richert

Hi Kasey,

To answer your question, yes wmv files should work. However, I discovered a division by zero error in the code last week, and this might be causing the error that you are seeing.

Try using Matlab's debugger to step through mmread.m and find out what line is actually causing the error.

I have already submitted an updated version of mmread which has the division by zero bug fixed, but Mathworks is taking a while to put it up. Check back in a few days.

22 Feb 2006 Micah Richert

Hi Lily,

The version currently downloadable requires an extra dll: msvcr70d.dll
You can download it from here, and put it in your MATLAB\bin\win32 directory. Download it from here:

I have already submitted an updated version of mmread which shouldn't require this, but Mathworks is taking a while to put it up. Check back in a few days.

22 Feb 2006 Kasey Horton

Is this function supposed to work on wmv files? I got it to work on an avi and mpg file, but the same thing didn't work for a wmv. All the movies play in Media Player. Matlab just comes back with ??? when I try the command
video = mmread('test.wmv');
Any ideas?

22 Feb 2006 lily lily

Hi. When I run it, it shows as follows:

??? Invalid MEX-file 'E:\\mexDDGrab.dll': The specified module could not be found..

Error in ==> mmread at 178

So how can I solve this problem? thank you!

21 Feb 2006 Micah Richert

Edward, you shouldn't have to compile the source (i.e. you don't need to run makedll). mmread should work once you unzip it. Are you getting an error when you run mmread?

Strmbase.lib is part of the DirectX SDK Extras. Just google for "DirectX SDK Extras" and any of them should be fine.

21 Feb 2006 Edward Leung

Sorry, I don't know how to use your kit. It seems I can't even read in any videos. Do I know to run 'makedll' first? Yet, when I run 'makedll' it always says that I don't have 'strmbase.lib', even though I have installed the DXSDK. Could you mind telling me y? Coz I wanna use this library for my Final Year Project. Many thanks.

20 Feb 2006 Micah Richert

Hi Trey,
You are right, the dll version I had last submitted still required MSVC dlls. I need to be more careful. As far as I can tell the warning is is harmless (I get it too), and I am guessing that it is due to Matlab dlls that Dependency Walker can't find.

I have just uploaded a new version which also includes some other improvements. I have confirmed it does not have MSVC dependencies. Try this new version and see if you still have issues. You may have to wait a day or two for Mathworks to make it live.

18 Feb 2006 Trey 64647

Current version still seems to require extra DLLs. Added APPHELP.DLL and MSVCR70d.dll which Dependency Walker for mexDDGrab.dll reported as missing. "The specified module could not be found" no longer comes up. The only error message is literally "???" and the video fails to load. Dependency Walker still returns one warning: "Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module."
Running Win2000 and DX9.

14 Feb 2006 Micah Richert

Hi Mak,
The "The specified module could not be found" error means that matlab couldn't load the dll or one of its dependencies (ie. any other dlls that it requires).

The newest version of mexDDGrab.dll
should only require quartz.dll. It should be under c:\windows\system32, if it is not then reinstall directX.

Older versions of mexDDGrab.dll require a couple other dlls to function. It needs msvcr70.dll, msvcp70.dll and msvcrt.dll. The msvc*.dll files are normally located under your matlab\bin\win32 directory. If you are missing any of the msvc*.dll files you can get them from here:,dll,115.html

14 Feb 2006 Mak mak

I got following error message
Invalid MEX-file mexDDGrab.dll': The specified module could not be found.
Error in ==> mmread at 178

09 Feb 2006 Micah Richert

Hi Wouter,
Edit mmread.m and change the || into |. Old versions of Matlab don't support ||, but that's what I am used to from C/Java so I default to using it. What version of matlab are you running? I am curious to know what versions work.

09 Feb 2006 Wouter Suren

hi, if i run
video = mmread('Paul.avi',1:10);

i get the following error message

mmread.m Line: 93 Column: 23
Expected a variable, function, or constant, found "|".

02 Feb 2006 Micah Richert

Hi Luis,

Unforutnately, Window's error messages are not so helpful in this case. The error has nothing to do with Java. What it actually means is that windows can't find the right codec to decode the movie. This can either be caused by a corrupt avi file, or missing/corrupt codecs. Can you play the movie in Media Player on the same machine?

Googling the error code '80040111' and 'Windows Media Player' comes up with some suggestions.

This website seems pretty helpful:

02 Feb 2006 luis galup

i installed june's sdk, and feb's extras, and built everything with .NET 2003.

i tried to run mmread in matlab, but it complained :"??? Invalid MEX-file 'E:\src\matlab_scripts\mmread\mexDDGrab.dll': The specified module could not be found."

then, i ran makedll correctly, but then get the error message when i run this:
video = mmread('C:\outdoor-boatDock-320x240-10fps.avi',1:10)

the error i get is: "??? ClassFactory cannot supply requested class "

i have the latest run time libs of java.

any ideas what i should do?

30 Jan 2006 Micah Richert

Hi Ranjini,
Unforunately, DirectX's error messages are not so helpful (and I'm not going to write my own to fix Microsoft's poor messages). Try googling for the exact error message and that can help. Most likely your movie is in Micorsoft's Mpeg-4 format and the newest codec is not installed on the computers that are having a problem. Try updating the codec. There are many websites that tell you how to do this, but here is one:

Hope that helps,

28 Jan 2006 Ranjini Mark

I use mmread for reading a mpeg file. In some machines it works well. In some other machines while executing mmread it gives a error like class not registered. Why? can you please explain?

18 Jan 2006 Micah Richert

Hi Joaquin,
Microsoft decided to update the page...
Just google for "DirectX SDK Extras" and any of them should be fine. Feb 2005 seems to be the newest (as of Jan 2006). But it really doesn't sound like you want to compile the code.

As far as mmread taking 5 minutes, it should not take that long. What happens when you use Media Player? Does your system use a lot of virtual memory when you run mmread? If there is an audio stream (which you don't want) make sure you don't specify the audio output variable. As in, only do video = mmread(...) instead of [video, audio] = mmread(...), because otherwise it will capture the entire audio stream (which could take 5 minutes).

If you are still having problems email me directly.

18 Jan 2006 Joaquin Zepeda

I've managed to install directshow/directsound, and mmread is running. However, it takes extremely long to execute (something like 5 minutes to load a single frame). Is this how its meant to run? -Joaquin

18 Jan 2006 Joaquin Zepeda

Hi Micah,
I'm trying to follow your instructions insade the "makedll.m file" but I can't find any "Extras" for DirectX in the download link you provide that contain DirectShow and DirectSound. (The current version in the download link is December 2005, the one pointed out in your files is June 2005). Thanks -Joaquin

16 Dec 2005 Micah Richert

I've uploaded a new version that has time support and removes the dependence on the MSVC*.dlls. Based upon Jason Xu's comments I realized the reason why some movies were not having the right size data being returned; scanlines (width*3) must be a multiple of 4. His ceil(width*3/4)*4 code made me realize this, though it has nothing to do with alpha channels. Hopefully, this will resolve people's problems.

14 Dec 2005 Micah Richert

Hi Jason,

Alpha channel information should never be returned. If you are getting alpha channel data then something is screwy in DirectX because the code instructs DirectX to format the data as RGB (MEDIASUBTYPE_RGB24). I can add more checks to make sure that DirectX hasn't played with the dataformat. Could you email me a small movie that doesn't work for you (other than clock.avi)? Also, what version of DirectX are you using?


13 Dec 2005 Jason Xu

I downloaded the package just now, but found that it still didn't work with "C:\windows\clock.avi", showing the RESHAPE error message. It also cannot work with some of my video files either.

I found out what causes the error is that the frame data returned by 'mexDDGrab' has an unexpected size for 'mmread'. There are two possibilities for this to happen:
(1) The frame contains 4 channels, including the alpha channel.
(2) The frame data is aligned with padding at the end of each scanline.

My hack is this:
% Handle alpha channel (if existing) and DWORD alignment
widthStep = ceil(3*width/4)*4;
if(length(data)>widthStep*height) data = data(1:(widthStep*height))'; end % Discard alpha channel if necessary
data = reshape(data, widthStep, height);
data = data(1:3*width,:);

Open 'mmread.m', insert the above code lines between
'data = mexDDGrab('getVideoFrame',i-1,f-1);'
'% the data ordering is wrong for matlab images, so permute it'

It works for all my video files.

01 Aug 2005 Micah Richert

I've finally updated the files. The orientation, color bug has been fixed. I also have beta code to handle the clock.avi problem that Alex Pudmenzky pointed out, but since I haven't found any documentation on specifically how to handle this, it is beta. I also commented the code a little better and added two more examples.

29 Jul 2005 Micah Richert

clock.avi seems to be the only file that I can find that has a problem. Specifically there is 1 extra byte per scanline, since the data is no longer 3 x width x height when I reshape it, it generates an error. I can make some guesses as to how to deal with this problem, but I'm looking to see if this is covered in the video format spec.

Thanks for telling me, and please send me any other examples that don't work.

27 Jul 2005 Alex Pudmenzky

I am receiving an error when reading the (standard Win-XP) file

>> mmread('c:\windows\clock.avi',1)
??? Error using ==> reshape
To RESHAPE the number of elements must not change.

Any ideas?

20 Jul 2005 Micah Richert

I've fixed the orientation problem (and the RGB values were backwards too). Sorry about that. However, I can't seem to login and update the files... We'll have to wait for mathworks to let me back in.

As a temporary fix, use the following code:
for f=1:length(video.frames)
tmp = video.frames(f).cdata;
video.frames(f).cdata = tmp(end:-1:1,:,3:-1:1);

19 Jul 2005 Don Orofino

The video frames returned by mmread appear upside-down when viewed with movie, imshow, mplay, etc.

01 Aug 2005

Updated a few bugs, and added a few more comments.

08 Aug 2005

Added support for images, now it stops processing when last specified frame is captured instead of letting it complete on its own. Fixed when frames were specified in non-increasing order they would not be provided in the order specified.

10 Aug 2005

Switched to a more appropriate category.

19 Dec 2005

Removed dependence on MSVC dlls. Added time range support. Added better support for when the returned data doesn't match expected size.

20 Dec 2005

Corrected the description

23 Feb 2006

Removed dependencies on other dlls (for real this time). Added a few other features. Resubmitted because Mathworks haven't made my changes live in a couple days.

05 Apr 2006

Compiled the mexw32 version (same code just for Matlab 7.1+).
Added some improvements to makedll.

05 May 2006

Added comments to makedll and removed most of the M-lint messages.

31 Jul 2006

Fixed several memory leaks, and fixed a problem with specifying time.

Added inline frame processing support. Frames can now be processed as they are being captured.

31 Jul 2006

Fixed several memory leaks, and fixed a problem with specifying time.

Added inline frame processing support. Frames can now be processed as they are being captured.

01 Aug 2006

Fixed audio stream bugs...

29 Sep 2006

Fixed a bug with reading in large audio files.
Added Float audio format support.

29 Sep 2006

Fixed a bug with reading in large audio files.
Added Float audio format support.

06 Mar 2007

Added some speed improvements to the sequential frame processing (processFrames.m).

12 Mar 2007

Added 64-bit Matlab support

25 Apr 2007

Fixed a bug with startTime being ignored.

30 Jul 2007

Added Seeking, fixed a memory leak and fixed a problem with 24 bit audio.

30 Jul 2007

Added Seeking, fixed a memory leak and fixed a problem with 24 bit audio.

15 Dec 2008

This is a completely new version that now supports Linux and Mac by using FFmpeg and AVbin.

04 Feb 2009

Several bug fixes and now the code is MUCH faster for sequential reads from the same file.

22 Jul 2009

Minor updates are accepted the BSD license.

23 Jul 2009

Changed to BSD license. Minor bug fixes.

29 Aug 2009

Fixed the FFGrab.mexa64: undefined symbol:
avbin_open_filename_with_format error.

25 Sep 2009

Removed dependency on libbz2

12 Oct 2009

Removed __isoc99* functions

15 Oct 2009

Added support for anonymous functions

12 Nov 2009

Fixed the "specified procedure could not be found" error on Win64 systems.

Contact us