| rgl.makemovie {rglplus} | R Documentation |
Produce a movie from and 3d rgl scene
Description
Generates an MP4-movie of a 3d rgl scene with time-dependent objects and/or a camera path. The routine has been developed and tested for MacOS and it requires on a working installation of ffmpeg.
Usage
rgl.makemovie(
frame = NULL,
path = NULL,
tmin = 0,
tmax = 1,
nframes = 60,
fps = 60,
output.path,
output.filename,
keep.frames = FALSE,
quiet = TRUE,
separator = .Platform$file.sep,
ffmpeg.cmd = "ffmpeg",
ffmpeg.opt = "-vcodec libx264 -crf 18 -pix_fmt yuv420p",
manual = FALSE
)
Arguments
frame |
optional function that plots or updates the 3D scene at a given time. This function must have exactly one argument, which specifies the time of the frame. |
path |
optional list that specifies the motion of the camera at some discrete times. The list contains the following elements (for more details see |
tmin |
physical time of first frame in the movie. |
tmax |
physical time of last frame in the movie. |
nframes |
number of frames in the movie. The time variable is sampled evenly between |
fps |
number of frames per second |
output.path |
character specifying the directory, where the movie and temporary frames are saved |
output.filename |
movie filename without path. This filename should end on the extension '.mp4'. |
keep.frames |
logical flag specifying whether the temporary directory with the individual frame files should be kept |
quiet |
logical flag; if true, all console outputs produced by 'ffmpeg' are suppressed |
separator |
filename separate of the system ('/' for Mac, Linux, Unix; '\' for Windows) |
ffmpeg.cmd |
command used to call ffmpeg form a terminal. Normally, this is just 'ffmpeg'. |
ffmpeg.opt |
optional arguments used with ffmpeg, such as compression and formatting options (see https://www.ffmpeg.org/ffmpeg.html). |
manual |
logical flag, if TRUE, ffmpeg is not run automatically. The ffmpeg command line is returned. |
Details
Note that the frame width and height should be divisible by 2 for mp4 video compression to work.
To accelerate the movie generation, it is possible to suppress the screen update by calling rgl.hold before calling rgl.makemovie.
Value
Returns the command line to run ffmpeg in a terminal.
Author(s)
Danail Obreschkow
Examples
rgl.new(aspect=4/3, col='black', xlim=c(-4,4), ylim=c(-4,4), zlim=c(-4,4))
rgl::clear3d(type = "lights")
rgl::light3d(30,60,viewpoint.rel = FALSE)
# Make frame function
frame = function(t) {
# t = time in seconds
rgl.hold()
if (t>0) {for (i in seq(3)) rgl::pop3d()}
rgl.ball(0, 0, 0, 1, normals='improved', depth=6, png=system.file('earth.png', package='rglplus'),
emission='#444466', rotation=rgl::rotationMatrix(t/86400*2*pi,0,0,1))
alpha = seq(0,2*pi,length=360)+2*pi*t/43200
alpha = c(alpha[1],rep(alpha[2:359],each=2),alpha[360])
y = 3.168*cos(alpha)
z = 3.168*sin(alpha)
rgl.ball(0,y[1],z[1],0.05,col='red',emission='#aa0000')
rgl::segments3d(0,y,z,col='red',alpha=seq(0,1,length=720))
rgl.draw()
}
# Make path
path = list(position=c(10,10,0), up=c(0,0.5,1), fov = function(t) 40-t/8640)
# Produce movie
## Not run:
rgl.makemovie(frame=frame, path=path, tmin=0, tmax=86400, output.path='~/testmovie',
output.filename = 'movie.mp4', ffmpeg.cmd = 'ffmpeg', nframes=600)
## End(Not run)