Description Usage Arguments Details Value Note Author(s) References See Also
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.
1 2 3 4 5 6 7 8 | saveVideo(
expr,
video.name = "animation.mp4",
img.name = "Rplot",
ffmpeg = ani.options("ffmpeg"),
other.opts = if (grepl("[.]mp4$", video.name)) "-pix_fmt yuv420p",
...
)
|
expr |
the R code to draw (several) plots |
video.name |
the file name of the output video (e.g. ‘animation.mp4’ or ‘animation.avi’) |
img.name |
the file name of the sequence of images to be generated |
ffmpeg |
the command to call FFmpeg (e.g.
|
other.opts |
other options to be passed to |
... |
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.
Some linux systems may use the alternate software 'avconv' instead of 'ffmpeg'. The package will attempt to determine which command is present and set ani.options('ffmpeg')
to an appropriate default value. This can be overridden by passing in the ffmpeg
argument.
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: https://code.google.com/archive/p/winff.
Yihui Xie, based on an inital version by Thomas Julou thomas.julou@gmail.com
Examples at https://yihui.org/animation/example/savevideo/
To know more about ffmpeg, please see http://ffmpeg.org/documentation.html
Other utilities:
im.convert()
,
saveGIF()
,
saveHTML()
,
saveLatex()
,
saveSWF()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.