[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:
From: |
Leo Butler |
Subject: |
Re: |
Date: |
Tue, 8 Dec 2009 21:03:17 +0000 (GMT) |
User-agent: |
Alpine 1.10 (DEB 962 2008-03-14) |
On Tue, 8 Dec 2009, address@hidden wrote:
< I saved this posting from Francesco, watch out for line wrap
<
<
< =-=-=
< Subject: Re: avifile (and all that jazz)
< From: "Francesco Potorti`" <address@hidden>
< Date: Wed, September 16, 2009 5:43 am
<
< >You can do this by generating a series of, for example, png-images and then
< >let mencoder put them together to an avi-file.
<
< Or else use this function of mine. By the way, wahat people think:
< would it be reasonable to add it to the video package?
<
< function movie (action, mmov="octave_movie.mp4")
< ## Create a movie from plots
< ##
< ## Example usage:
< ## figure("visible","off"); movie("init")
< ## a=zeros(100,100); a(1:20,41:60)=1;
< ## for i=1:100; a=shift(a,1); imshow(a); movie("add"); endfor
< ## movie("close"); close; system("totem octave_movie.mp4")
< ##
< ## There are three commands used as first argment: "init", "add",
< ## "close". By default, a movie named "octave_movie.mp4" is created
< ## using ffmpeg. An optional second argument allows one changing both
< ## the name and the type of movie. The type ".dir" creates a
< ## directory containing a png file per frame. The type ".zip"
< ## archives it using zip. Types ".mp4", ".ogg", ".mov", ".mjpeg",
< ## ".avi", ".flv" are created using ffmpeg; types ".mng", ".gif" are
< ## created using convert; type ".swf" is created using png2swf. You
< ## must have the relevant program installed to create a movie with the
< ## corresponding extension; no program is required for ".dir".
<
< ## Francesco Potortì, 2008
< ## Revision 1.10
< ## License: GPL version 3 or later
<
< verbose = false;
< rate = 5; # frames per second
<
< actions = {"init" "add" "close"};
< # gif swf
< types = {".mp4" ".mng" ".gif" ".zip" ".ogg" ".swf" ".mov" ...
< ".mjpeg" ".avi" ".flv" ".dir"};
< if (nargin < 1 || !ischar(action) || !any(strcmp(action, actions)))
< error("first argument must be one of:%s", sprintf(" %s",actions{:}));
< endif
< if (nargin != 2 || !ischar(mmov))
This should be:
if (nargin >= 2 && !ischar(mmov))
The example in the comments won't work unless the above line is changed.
< error("second arg must be a string");
< endif
< [mpath mname mtype] = fileparts(mmov);
<
< mdir = fullfile(mpath, [mname ".d"]);
< ppat = "%06d.png";
< mpat = fullfile(mdir, ppat);
< mglob = fullfile(mdir, strrep(sprintf(ppat,0),"0","[0-9]"));
< fnof = fullfile(mdir, "+frame-number+");
<
< switch (action)
< case actions{1} # init a movie
< if (isdir(mmov))
< cleandir(mmov, verbose)
< else
< unlink(mmov);
< endif
< while (!([allgood msg] = mkdir(mdir)))
< if (stat(fnof) && load(fnof).frameno == 0)
< error("while creating dir '%s': %s", mdir, msg);
< else
< cleandir(mdir, verbose);
< endif
< endwhile
< frameno = 0; save("-text",fnof,"frameno");
< if (verbose) printf("Directory '%s' created.\n", mdir); endif
< case actions{2} # add a frame
< load(fnof);
< mfile = sprintf(mpat, ++frameno);
< drawnow("png", mfile);
< save("-text",fnof,"frameno");
< if (verbose) printf("Frame '%s' added.\n", mfile); endif
< case actions{3} # close the movie
< switch (mtype)
< case {types{[1 5 7 8 9 10]}} # mp4, ogg, mov, mjpeg, avi, flv
< cmd = sprintf("ffmpeg -y -r %d -sameq -i %s %s 2>&1", rate,
< mpat, mmov);
< case {types{[2 3]}} # mng, gif
< cmd = sprintf("convert %s -adjoin %s 2>&1", mglob, mpat);
< case types{4} # zip
< cmd = sprintf("zip -qr9 %s %s 2>&1", mmov, mglob);
< case types{6} # swf
< cmd = sprintf("png2swf -z -r %d -o %s %s", rate, mmov, mglob);
< case types{end} # dir
< rename(mdir, mmov); return
< otherwise
< error("second arg must end with one of:%s", sprintf("
< %s",types{:}));
< endswitch
< [status output] = system(cmd);
< if (status != 0)
< load(fnof);
< error("Creation of movie '%s' containing %d frames failed:\n%s",
< mmov, frameno, output);
< endif
< if (verbose) printf("Movie '%s' contains %d frames:\n%s",
< mmov, frameno, output); endif
< cleandir(mdir, verbose);
< endswitch
< endfunction
<
<
< function cleandir(mdir, verbose)
< unwind_protect
< save_crr = confirm_recursive_rmdir(false);
< [allgood msg] = rmdir(mdir,"s");
< if (!allgood)
< error("while removing dir '%s': %s", mdir, msg); endif
< unwind_protect_cleanup
< confirm_recursive_rmdir(save_crr);
< end_unwind_protect
< if (verbose) printf("Directory '%s' removed\n", mdir); endif
< endfunction
<
< --
< Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
< ISTI - Area della ricerca CNR Fax: +39 050 315 2040
< via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
< (entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/
<
< =-=-=
< > Hello list,
< >
< > For an assignment, my students are using finite differences to compute a
< > solution of the 1D wave equation. Because I only want them to bother with
< > the numerics, not with practical plotting stuff, I've made available the
< > following script which they can use to animate their solution:
< >
< > --------------------------- begin script ---------------------------
< >
< > function generate_movie1d(f, g, Nx, t_max, L, c, lambda)
< >
< > [u dt] = wave1d(f, g, Nx, t_max, L, c, lambda);
< >
< > mymax = max(max(u));
< > mymin = min(min(u));
< >
< > x = linspace(0, L, Nx+1);
< > for i=1:size(u,2)
< >
< > plot(x, u(:,i), '*r')
< > axis([0 L mymin mymax])
< > title(sprintf('Solution of the one-dimensional wave equation at t = %f',
< > (i-1)*dt))
< > drawnow
< > hold off
< >
< > end
< >
< > ------------------------------ end script
< > ----------------------------------
< >
< > This all worked fine on my (fast) Ubuntu desktop PC, but one of my
< > students (working on a quite fast Windows Vista laptop) reported
< > 'flickering' graphics... the updating of the animation is very bad and
< > makes the animation very unfluent. I assume this is not due to a slow
< > computer (his laptop is quite fast), but rather due to the fact that I use
< > the drawnow command to update the graphics... maybe also due to the fact
< > that he works on Windows Vista? Unfortunately, I don't know how I would
< > have to change my code so that the updating is more 'fluent'.
< >
< > Can anybody help me out here, so that I can give my students a script that
< > also gives fluent animations, even on Windows? What is the general
< > technique to do this? Am i doing it the right way?
< >
< > Kind regards,
< > Bart
The example provided in the comments to the script does not work on an
out-of-the-box
debian ffmpeg, because the mp4 codec is not available. Try .ogg in place of
.mp4.
Leo
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.