Skip to content

rgl: insert pauses in animation sequence / movie formats other than gif?

5 messages · Michael Friendly, Duncan Murdoch

#
Two questions related to creating animated movies with rgl:

1. I've created an rgl scene with 5 different views I want to display in 
a movie, but I'd like to insert pauses (say, 5 seconds)
at each view.  How can I do this?

I first created 5 userMatrix's, then

play3d( par3dinterp( userMatrix=list(M1, M2, M3, M4, M5)),  
,duration=2*60/5) )

then tried simply repeating each twice,

play3d( par3dinterp( userMatrix=list(M1, M1, M2, M2, M3, M3, M4, M4, M5, 
M5)),  ,duration=2*60/5) )

but that didn't give the desired effect.  I see that play3d() has a 
times= argument, but the documentation
doesn't indicate how to use it in this context.

2. With movie3d(), I can get an animated .gif, but I wonder if there are 
other movie formats (.mov, .mpg) I can get,
either with convert, or an external tool, e.g., so I can embed a movie 
in a LaTeX  -> .pdf document using the
movie15 package.

e.g., I tried using convert at in a command prompt window,
 > convert -delay 1x8 coffee-av3D-1*.png coffee-av3D-1.mov

but it seems that only one frame was used.
#
On 07/06/2011 9:24 AM, Michael Friendly wrote:
Something like this works:

play3d(par3dinterp(times=c(0,5,6,11,12,17),
              userMatrix=list(m1,m1,m2,m2,m3,m3),
              method="linear"))

The "linear" says to use linear interpolation between time points, so it 
will stay exactly constant when the userMatrix doesn't change.  If you 
leave it out, it uses spline interpolation, and that gives some 
irritating overshooting.
I don't know what formats convert handles these days.  I used ffmpeg to 
put together an mp4 movie a while ago.  The command line was

ffmpeg  -b 2400000 -r 24 -i movie%03d.png -s xga movie.mp4

That is:  a bitrate of 2.4 million bits per second, showing at 24 frames per second, frames named movie001.png etc, output size 1024x768 ("xga" size) in file movie.mp4.

Duncan Murdoch
#
On 6/7/2011 10:52 AM, Duncan Murdoch wrote:
Thanks very much for this, Duncan.

Something like this would make an excellent documentation example for 
play3d/movie3d, or perhaps better
par3dinterp, even under \dontrun{}.

I take it that the times are relative rather than absolute, and time is 
scaled according to duration and
fps when the scene is play3d()'d.  Yes?  If so, the description for 
time= could also be clarified.

best,
-Michael
#
On 07/06/2011 12:22 PM, Michael Friendly wrote:
Definitely it should be clarified in the docs; they are absolute times, 
in units of seconds.  Things get a little complicated when you go past 
the last time (17 seconds):  there are a number of different 
extrapolation methods described in ?par3dinterp.

What the par3dinterp function returns is a function that takes a time 
(expressed in seconds) and computes the parameters (i.e. the userMatrix 
in the example) that should be in effect at that time.  It doesn't know 
anything about fps, that's used by play3d to choose what times to pass 
to that constructed function.  The function that play3d is given can do 
lots of things other than returning new viewpoint parameters; for 
example, the flag demo redraws the scene in every frame (using 
skipRedraw=TRUE to avoid showing partial versions).

Duncan
#
On 6/7/2011 12:36 PM, Duncan Murdoch wrote:
OK, I don't exactly understand all the relationships among time (in 
seconds) for par3dinterp() and duration
and fps for play3d() and movie3d(), but the following gave me *exactly* 
what I was looking for: transitions
among 5 views, with pauses at each:

# define an order to show the views and basic times for each:
views <- list(M1, M3, M4, M5, M2)
times <- 5 * (seq_along(views)-1)

# add pauses; use linear interpolation in time
interp3d.fun <- par3dinterp( times=sort(c(times, times+2)),
             userMatrix=rep(views, each=2),  method="linear")
play3d( interp3d.fun, duration=2*60/5)

best,
-Michael