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

Duncan Murdoch murdoch.duncan at gmail.com
Tue Jun 7 16:52:12 CEST 2011


On 07/06/2011 9:24 AM, Michael Friendly wrote:
> 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.

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.

> 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.
>
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



More information about the R-help mailing list