Is there a way to create an MPEG movie frame by frame, such
as within a loop, similar to the addframe command used to
create AVIs?
I have tried using mpgwrite, but the arrays I am dealing
with are too large to store at once and are currently added
to an avi frame by frame.... such as (within a loop):
F = getframe(gca);
aviobj = addframe(aviobj, F);
I also tried using movieeditor to load the created AVI and
convert it to an MPEG, but when using 150 mb avi's, the
memory quickly balloons to 2 gigs and I therefore receive an
out of memory error.
"Travis " <traviib.nospam.@yahoo.com> wrote in message
<fb4lmd$cno$1@fred.mathworks.com>...
> Is there a way to create an MPEG movie frame by frame,
such
> as within a loop, similar to the addframe command used to
> create AVIs?
>
> I have tried using mpgwrite, but the arrays I am dealing
> with are too large to store at once and are currently
added
> to an avi frame by frame.... such as (within a loop):
>
> F = getframe(gca);
> aviobj = addframe(aviobj, F);
>
> I also tried using movieeditor to load the created AVI and
> convert it to an MPEG, but when using 150 mb avi's, the
> memory quickly balloons to 2 gigs and I therefore receive
an
> out of memory error.
>
> Any ideas? Thanks all.
Travis,
This is some stock movie demo code I trot out when someone
asks about this and I think it might be helpful as .avi is
very inefficient:
% Movie Demo
% create some image data
[X Y Z] = sphere(25);
sz = size(Z);
C = rand(sz(1),sz(2),3);
% stitch data to wrap color around sphere
C(:,end,:) = C(:,1,:);
% render an image
figure('color',[0 0 0]);
sp = surf(X,Y,Z,C,'FaceColor','interp',...
'FaceLighting','phong');
material shiny
axis off vis3d
cl = camlight('right');
camzoom(1.5)
set(sp,'edgecolor','none');
drawnow
% setup the rotation vector for the movie
view_vect_yaw = [-180:3:180];
sz_vect = size(view_vect_yaw);
% "lights, camera, action!"
for f = 1:sz_vect(2)
% set the view, reset light position and render
view([view_vect_yaw(f) 15]);
camlight(cl,'right')
drawnow
% grab a frame
m(f) = getframe(gcf);
end
% format frames as mpeg and write to file
mpgwrite(m,C,'my_movie.mpg',...
[1, 0, 1, 0, 10, 1, 1, 1]);
% end of code
This demo requires mpgwrite.dll which is available in the
file exchange. You just drop a copy of the dll into the
directory where you are developing and running your movie
code.
Thanks for the response, however, that does not solve my
problem. (I have tried using mpgwrite.) In that example,
the structure "m" is created and the entire array is then
converted with mpgwrite.
My arrays are too large to store in the workspace as a
complete movie, so I need to add frames individually, one by
one (such as in a loop)... and I would like to do so to an
mpeg instead of making an avi by using addframe.
Possible?
> Travis,
> This is some stock movie demo code I trot out when someone
> asks about this and I think it might be helpful as .avi is
> very inefficient:
>
> % Movie Demo
>
> % create some image data
> [X Y Z] = sphere(25);
> sz = size(Z);
> C = rand(sz(1),sz(2),3);
>
> % stitch data to wrap color around sphere
> C(:,end,:) = C(:,1,:);
>
> % render an image
> figure('color',[0 0 0]);
> sp = surf(X,Y,Z,C,'FaceColor','interp',...
> 'FaceLighting','phong');
> material shiny
> axis off vis3d
> cl = camlight('right');
> camzoom(1.5)
> set(sp,'edgecolor','none');
> drawnow
>
> % setup the rotation vector for the movie
> view_vect_yaw = [-180:3:180];
> sz_vect = size(view_vect_yaw);
>
> % "lights, camera, action!"
> for f = 1:sz_vect(2)
> % set the view, reset light position and render
> view([view_vect_yaw(f) 15]);
> camlight(cl,'right')
> drawnow
> % grab a frame
> m(f) = getframe(gcf);
> end
> % format frames as mpeg and write to file
> mpgwrite(m,C,'my_movie.mpg',...
> [1, 0, 1, 0, 10, 1, 1, 1]);
> % end of code
>
> This demo requires mpgwrite.dll which is available in the
> file exchange. You just drop a copy of the dll into the
> directory where you are developing and running your movie
> code.
>
> hth,
> Scott
>
Does the AVI fit completely into the memory? If yes, try to
use Bink Video for conversion from AVI to MPEG. If not,
maybe you can make parts of the AVI, save them to disk and
later paste them together with some dubbing software.
Yes, the AVI should fit, it is only ~150 mb or so. I
figured there would be some type of external video editing
software that could do the conversion, but was wondering if
it could be done when the code generates the file so I
didn't have to go through this extra step...
Has anyone used mpgwrite with large movie arrays (that won't
fit in memory in their entirety when in the matlab structure
format)?
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.