| saveVideo {animation} | R Documentation |
This function opens a graphics device to record the
images produced in the code expr, then uses FFmpeg
to convert these images to a video.
saveVideo(expr, video.name = "animation.mp4", img.name = "Rplot", ffmpeg = "ffmpeg",
other.opts = "", clean = FALSE, ...)
expr |
the R code to draw (several) plots |
img.name |
the file name of the sequence of images to be generated |
video.name |
the file name of the output video (e.g. ‘animation.mp4’ or ‘animation.avi’) |
ffmpeg |
the command to call FFmpeg (e.g.
|
other.opts |
other options to be passed to
|
clean |
whether to remove the sequence of images after conversion |
... |
other arguments to be passed to
|
This function uses system to call
FFmpeg to convert the images to a single video. The
command line used in this function is: ffmpeg -y
-r <1/interval> -i <img.name>%d.<ani.type> other.opts
video.name
where interval comes from
ani.options('interval'), and ani.type is
from ani.options('ani.type'). For more details on
the numerous options of FFmpeg, please see the reference.
An integer indicating failure (-1) or success (0) of the
converting (refer to system).
There are a lot of possibilities in optimizing the video. My knowledge on FFmpeg is very limited, hence the default output by this function could be of low quality or too large. The file ‘presets.xml’ of WinFF might be a good guide: http://code.google.com/p/winff/.
Yihui Xie <http://yihui.name>, based on an inital version by Thomas Julou thomas.julou@gmail.com
http://ffmpeg.org/documentation.html
saveGIF, saveLatex,
saveHTML, saveSWF
oopts = ani.options(ffmpeg = "D:/Installer/ffmpeg/bin/ffmpeg.exe")
## usually Linux users do not need to worry about the path as long as FFmpeg
## has been installed
if (.Platform$OS.type != "windows") ani.options(ffmpeg = "ffmpeg")
saveVideo({
par(mar = c(3, 3, 1, 0.5), mgp = c(2, 0.5, 0), tcl = -0.3, cex.axis = 0.8, cex.lab = 0.8,
cex.main = 1)
ani.options(interval = 0.05, nmax = 300)
brownian.motion(pch = 21, cex = 5, col = "red", bg = "yellow")
}, video.name = "BM.mp4", other.opts = "-b 300k") # higher bitrate, better quality
ani.options(oopts)