View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.1 | 17 ratings Rate this file 22 Downloads (last 30 days) File Size: 494 KB File ID: #308 Version:



David Foti (view profile)


05 Apr 1999 (Updated )

The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file.

| Watch this File

File Information

MPEG is an ISO standard movie encoding format. The MPEG converter for MATLAB takes a MATLAB movie matrix and writes the movie to disk as an MPEG file with file extension '.mpg' (MPGWRITE). It also takes an MPEG file and converts it into a MATLAB matrix (MPGREAD).


This file inspired Mmread.

MATLAB release MATLAB 5.2 (R10)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (40)
24 Apr 2016 Phuc Nguyen

07 Feb 2013 arun

arun (view profile)

hello everyone,can anyone over here tell me the procedure to which frame is a i,p,or b frame.i have extracted the frames from a mpeg-4 video.but,not getting how to detect the frmes.please help.

Comment only
02 Aug 2012 Philip

Philip (view profile)

-you have to "make" before using. I made sure there were no mex or dll's in my MPGREAD directory, then ran makedll.m. All I believe is needed is mpgread.mex32.
-you have to remove audio, as others said, from your MPEG-1 for MPGREAD to read it. in Pinnacle Studio this can be done by selecting "settings" and unchecking include audio.

Comment only
04 Nov 2011 Rami

Rami (view profile)

Hi David, Thanks for nice program. I am using this as follow:
mpg_mov= mpgread('tumor1.mpg','indexed');
video = {mpg_mov.cdata}

Got error "??? Attempt to reference field of non-structure array."

Could you please help me resolve this problem. What alternative I should you to get cdata? Thanks

Comment only
11 Feb 2011 Gourav Kumar Soni

very nice programmm

15 Oct 2010 Jorge de los Santos

Hi. I'm Jorge from Spain. I'm working in a academic proyect to finish my
Egineering degree. I'm trying to use mpgwrite and mpwread to design an
aplication about quality control in digital videos. My problem is with
mpgread. Whem I use mpgread I obtein one sequece of frames in a matlab
structure but in this structure frame 1 and frame 2 is the same frame than
frame 1 in the original video and I lost last frame. For example:

Compressed Video, frames: 1 2 3 4 5 6 7 8 9 10 Total number of frames: 10
Uncompressed Video, frames: 1 1 2 3 4 5 6 7 8 9 Total number of frames: 10

What can I do to resolve this problem? Thank's so
much in advance.

Comment only
15 Jan 2009 claudia butini

I have 7.6.0 matlab version. I'd like to know how I can obtain an mpeg video made also of B-frame. Because using mpgwrite (and then mpgread) I obtain an mpeg video made only of I- and P-frames. Can anyone help me?

Comment only
07 May 2008 saleh mohmed

how to change video to picture

Comment only
21 Sep 2007 dee smith

Does anyone know how to read mpeg-2 file using mpgread? MPEG-1 stram works fine, but mpeg-2 stream results in an error:
"Segmentation violation detected at Fri Sep 21 15:59:49 2007 ..............."

Can anyone help?

Comment only
06 Sep 2007 john m

I will answer my own question in order for others to benefit as well.

If you encounter the problems described in my previous post, it is likely that the mpgread mex file for your architecture is missing. for my linux installation, i had to compile the sources in the src/ folder. For this, i had to edit the make file and change cmex into mex (cmex was not found, mex is in the matlab bin folder). after calling make, a file called mpgread.mexglx was produced. i copied this into the mpgread folder and was able to call mpgread() from matlab with success.

best wishes,

Comment only
06 Sep 2007 john m

Dear all,

how can mpgread be used? The mpgread.m file only contains comments (for the help call), and calling mpgread like described in the documentation:

>> [movie, map] = mpgread('movie.mpg');

results in the error:

??? Attempt to execute SCRIPT mpgread as a function:

where .. denotes the path of the mpgread.m file (and all other files in the same dir)

does anybody know how to solve this?

thanks alot,

Comment only
03 Jul 2007 Samuel R

It works, just having trouble converting the movie into an width x Height x Length matrix so that I can compare to the uncompressed original data. Any ideas?

26 Mar 2007 Balvinder Kaur

Excellent! I am glad to find it on Mathworks site!

12 Mar 2007 insect Z

It's really neat! Is it possible to also put a mpginfo function? Return things like aviinfo?

02 Feb 2007 David Zeng

Very Excellent!

08 Jan 2007 Zhijun Wang

Very good

13 Aug 2006 Thuy Than

How come it keeps on saying
Error in ==> c:\matlab6p5\mpgread\mpgread.dll
I did compile the file makedll and there is no problem with this. Can anyone give me a hand. Thank your very much for your kindness and have a good day!

Comment only
13 Dec 2005 Hua Zhang

I have separated video and audio by TMPGEnc. Still doesn't work, the error message is "Improper or missing sequence end code in MPEG file" Anyone know how to solve it? Thanks!

09 Dec 2005 Muharram Mansoorizadeh

This tool may help to extract video only:
file -> mpeg tools -> simple demultiplex.

I'think it needs an improvement to support audio + video encoded files for both wide range support and audio/video applications

12 Sep 2005 Eugene Pretorius

The mpeg files contain an audio stream. If you remove it using some software encoding program mpgread works just fine

28 Jul 2004 bai hongliang

i can use the mpgread in matlab6.5, release 13. I think many people may meet with the same problem, fistly system gives error message as "This is not an MPEG file" even if video is in MPEG. i solve the problem by changing the video format to MPEG-1 Video.
you can use the Ulead VideoStudio8.
may help to you.

Comment only
30 Jun 2004 Aimee Monteiro

what do we have to do after downloading the .zip file? we are clueless...

Comment only
09 Jun 2004 Sudhir Porwal

It is not working properly. It gives error message as "This is not an MPEG file" even if video is in MPEG. It also gives segmentation fault for some video files. It read a single video file successfully but the matrix contains only zeros. Finally, I could not use it. It reads MPEG-1 or MPEG-2 video?

Comment only
13 Apr 2004 ding ding

Is anyone willing to tell me how to use it via Matlab 6.0?

Comment only
10 Mar 2004 CW Ko

Hi I've tried to separate video and audio by TMPGEnc. But it still doesn't work and shows: "Segmentation violation" and crashed. My Matlab is R13. Does anyone know how to solve it? Thanks!

Comment only
10 Mar 2004 CW Ko

Have anyone encountered such a problem?

I cannot use mpgread at all. but I am sure the file is of MPEG format. So what's wrong?
Here is the message:
>> M = mpgread('d:\Studies\120V_cm_MPEG1.mpg');
??? This is not an MPEG stream.

Error in ==> D:\Matlab_Program\mpgread\mpgread.dll

Comment only
08 Mar 2004 Andreas -

Is there another way to get a grayscale frame?

[R G B] = mpgread('my_movie.m1v',1:1); % take frame 1
movie = (R + G + B) / 3; % graysacele it
frame1 = movie(1:567,1:720); % PAL framesize


04 Mar 2004 Dinh Q. Phung

There are a couples of emails sent to me asking for further help on video/audio separation issue, so I think it's helpful to briefly describe it here.

1. download the software - you only need to free demo version

2. Say "file.mpg" is your mpeg file with both video and audio.

3. From "File" menu choose "MPEG tools", then click on "Simple De-multiplexed"

4. Enter "file.mpg" in "Input" edit box, then specify names for your video and audio streams.

5. Click "Run", and that's it

Now your de-multiplexed (only) video file should be able to be called by mpgread function.

Comment only
16 Jan 2004 Dinh Quoc Phung

As one of you suggested, it works for me once I've separated the video and audio stream.
Here is a free software that can do the splitting job for you:

Comment only
23 Dec 2003 prem prem

give an example for using mpgread and mpgwrite functions in to convert mpeg file into frames(no.)

Comment only
23 Dec 2003 vimal vimal

give me an example for opening an mpeg file in matlab.

Comment only
02 Dec 2003 pan lei

I cannot use this function ,my matlab's edition is matlab6.5,but this funciton doesn't work.Who can do me a favor to explain this question??The system always tells me "This is not a mpeg stream"!!!

Comment only
09 Oct 2003 Max Caprile

I can't read the files, the following message appears:
??? This is not an MPEG stream.

Comment only
19 Sep 2003 ©P §Ó©¾

04 Apr 2003 J Larsen

There aren't sufficient instructions to get this thing to work. You must have to be a guru in C and Matlab.

19 Mar 2003 Richard Samms

Hey! Works! Using Matlab 5.3/VCC++6.0

Tried all methods of read. Once in, a colormap call and a movie call work. This'll come in handy

21 Jan 2003 Asia m.

I downloaded the mpgwrite and mpgread from here, but they are empty files -- they only have comments in them. Is it supposed to be like that? Please advice me on this.

Comment only
04 Dec 2002 C Harding

The error message "This is not an MPEG stream" can be avioded by stripping the audio stream from the Mpeg first. I use a program called M1 Edit to do this before reading my MPEG into Matlab.

06 Oct 2002 Hz Wang

I also met this problem whem I use MATLAB R12. I use
and I found the background color have been changed! I wondering how to solve this problem or any othe updated mpgread available?

Thanks a lot!

03 Oct 2002 John ng

This version is not work in matlab 6.1?!

As I have try to call mpgread in matlab 6.1,
but I only got the error message
"This is not an MPEG stream."
Please advice what's wrong.

I know that there is a update of mpgwrite,
will there be any update for mpgread ??


24 Jul 2009 1.1

Updated description and copyright.

07 Jan 2010 1.3

Updated copyright and license information.

01 Sep 2016

Updated license

Contact us