Rank: 77 based on 570 downloads (last 30 days) and 2 files submitted
photo

David Foti

E-mail
Company/University
The MathWorks, Inc.

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Files Posted by David View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
07 Jan 2010 mpgread The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti mpeg, convert, graphics import, graphics export, movie, utilities 67 36
  • 4.0
4.0 | 16 ratings
07 Jan 2010 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti movie, convert, mpeg, graphics import, graphics export, utilities 503 101
  • 4.06849
4.1 | 74 ratings
Comments and Ratings on David's Files View all
Updated File Comment by Comments Rating
05 Apr 2012 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti Orloff, Nathan

One more suggestion for people using this code. I ended up using FFMPEG and then running it through the command line. It is much faster than everything else I have used, and it has all the codecs for all the different formats. Email me if you want the command like calls.

15 Mar 2012 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti Peter

Just got it to work!

Specs:
Windows XP Professional x64 Edition
MATLAB R2007b 64-bit

Steps:
1) Install Visual C++ 2008 Express http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express
- It doesn't come with the x64 bit compilers (thanks cheap-o Microsoft)

2) Install Microsoft SDK 6.1
http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en
- Make sure that the x64 compilers option is selected _before_ installing.

3) In "mpgwrite/src/Makefile"
change "$(MCC) $(MCFLAGS) " to "-v -DWIN32"

4) Open "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\Visual Studio 2008 x64 Win64 Command Prompt"

5) Navigate to the mpgwrite/src folder

6) Run nmake -f Makefile

7) Move mpgwrite.mexw64 to mpgwrite folder (out of the src folder)

8) Add mpgwrite folder to your MATLAB path

Sources:
* http://www.mathworks.com/support/solutions/en/data/1-6IJJ3L/?solution=1-6IJJ3L
* http://grantnz.blogspot.com/2010/07/compiling-matlab-mpgwrite-with-vs2010.html
* Andrea's post above

01 Mar 2012 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti Hansen, Jens Munk

Tried your program running 64-bit linux and Matlab 2010b and Matlab2011a both with the gcc shipped with Ubuntu and with the versions supported by Matlab. They all crashes due a double free or stack corruption.

This is my sample program
figure(1)
numframes=100;
A=moviein(numframes); % create the movie matrix
set(gca,'NextPlot','replacechildren')
axis equal % fix the axes
for i=1:numframes
    plot(fft(eye(i+16)));
    A(:,i)=getframe;
end

for i = 1:length(A)
  if (i==1)
    [r1,c1,s] = size(A(i).cdata);
    rk = r1;
    ck = c1;
  else
    [rk,ck,s] = size(A(i).cdata);
  end
  r1 = min(r1,rk);
  c1 = min(c1,ck);
end

for i = 1:length(A)
  [rk,ck] = size(A(i).cdata);
  if ((rk~= r1) || (ck ~=c1))
    A(i).cdata = A(i).cdata(1:r1, 1:c1,:);
  end
end
% compare frame sizes
for i = 1:numframes
    fprintf(1,'%d %d %d\n',i,size(A(i).cdata,1),size(A(i).cdata,2));
end

mpgwrite(A,jet,'movie.mpg');

23 Feb 2012 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti Orloff, Nathan

You should include a simple set of instructions or write an installer. It took me a minute to figure out how to run the dll to install the mex files.

One simple trick to decreasing the frame rate that has a negligible effect on increasing the file size is to duplicate the frames.

dupframes = 3;
ii = 1;
for jj = 1:(length(imagefiles)*dupframes)
    [im4D(:,:,:,jj),map] = imread([imfiles]);
    if mod(jj,dupframes) == 1 && jj ~=1
        ii = ii + 1;
    end
end

19 Jan 2012 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti Julia

Seems to work so far. Just wanted to say I'm running Windows and was having the same trouble as many people, but Andrea's detailed advice on installing and using Visual Studio as a compiler made all the difference.

I'm copy-pasting the key part from the website Andrea linked, even though it's long, since this was the key part for me.
http://grantnz.blogspot.com/2010/07/compiling-matlab-mpgwrite-with-vs2010.html

Compiling Matlab mpgwrite with VS2010 for 64 bit Windows
I was having trouble producing Matlab movies of reasonable quality on my 64 bit Windows 7 laptop until I was able to compile and run mpgwrite (source available from Matlab Central http://www.mathworks.com/matlabcentral/fileexchange/309-mpgwrite).

It wasn't obvious how to get this to compile and run so in case someone else would like to do this I've documented what I did:

1. Ensure Visual Studio 2010 installation includes the "X64 Compilers and Tools" (and option under the Visual C++ feature in the Visual Studio 2010 installer).

2. Configure the mex script for VS2010.
Matlab R2009b and earlier doesn't directly support Visual Studio 2010 but you can still use it by running
mex -setup
from Matlab.
a. Answer n to the first question (Would you like mex to locate installed compilers [y]/n? )
b. Select "Microsoft Visual C++ 2008 SP1 " (option 5)
c. The script will output:
The default location for Microsoft Visual C++ 2008 SP1 compilers is
C:\Program Files (x86)\Microsoft Visual Studio 9.0,
but that directory does not exist on this machine.
Use C:\Program Files (x86)\Microsoft Visual Studio 9.0 anyway [y]/n?

Answer n
d. Locate your Visual Studio 2010 installation folder and enter this in response to the next question. Visual Studio 2010 was probably installed to C:\Program Files (x86)\Microsoft Visual Studio 10.0
e. Finally, you will be asked to confirm the settings and Matlab will create a file mexopts.bat with the configuration information.

3. From Microsoft Visual Studio 2010\Visual Studio Tools open "Visual Studio x64 Win64 Command prompt (2010)".

4. Change to the src folder of the downloaded the mpgwrite source code using the "cd" command.

5. Edit the file makefile and replace $(MCC) $(MCFLAGS) after the call to mex with
-v -DWIN32
That is, your makefile should contain:

mpgread:
mex -v -DWIN32 mpgwrite.c mfwddct.c \
postdct.c huff.c bitio.c mheaders.c iframe.c \
pframe.c bframe.c psearch.c bsearch.c block.c \
mpeg.c subsampl.c jrevdct.c frame.c fsize.c

5. Run
nmake -f makefile

6. This should generate the file
mpgwrite.mexw64
Copy this file to a folder on the matlab path.

You should now be able to generate mpeg movies from matlab.

Top Tags Applied by David
convert, graphics export, graphics import, movie, mpeg
Files Tagged by David View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
07 Jan 2010 mpgread The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti mpeg, convert, graphics import, graphics export, movie, utilities 67 36
  • 4.0
4.0 | 16 ratings
07 Jan 2010 mpgwrite The MPEG converter takes a MATLAB movie matrix and writes the movie to disk as an MPEG file. Author: David Foti movie, convert, mpeg, graphics import, graphics export, utilities 503 101
  • 4.06849
4.1 | 74 ratings

Contact us at files@mathworks.com