av (version 0.3)

capturing: Record Video from Graphics Device

Description

Runs the expression and captures all plots into a video.

Usage

av_capture_graphics(expr, output = "output.mp4", width = 720,
  height = 480, framerate = 1, vfilter = "null", audio = NULL,
  verbose = TRUE, ...)

Arguments

expr

an R expression that generates the graphics to capture

output

name of the output file. File extension must correspond to a known container format such as mp4, mkv, mov, or flv.

width

width in pixels of the graphics device

height

height in pixels of the graphics device

framerate

video framerate in frames per seconds. This is the input fps, the output fps may be different if you specify a filter that modifies speed or interpolates frames.

vfilter

a string defining an ffmpeg filter graph. This is the same parameter as the -vf argument in the ffmpeg command line utility.

audio

audio or video input file with sound for the output video

verbose

emit some output and a progress meter counting processed images. Must be TRUE or FALSE or an integer with a valid av_log_level.

...

extra graphics parameters passed to png()

See Also

Other av: demo, encoding, formats, info, logging

Examples

Run this code
# NOT RUN {
library(gapminder)
library(ggplot2)
makeplot <- function(){
  datalist <- split(gapminder, gapminder$year)
  lapply(datalist, function(data){
    p <- ggplot(data, aes(gdpPercap, lifeExp, size = pop, color = continent)) +
      scale_size("population", limits = range(gapminder$pop)) + geom_point() + ylim(20, 90) +
      scale_x_log10(limits = range(gapminder$gdpPercap)) + ggtitle(data$year) + theme_classic()
    print(p)
  })
}

# Play 1 plot per sec, and use an interpolation filter to convert into 10 fps
video_file <- file.path(tempdir(), 'output.mp4')
av_capture_graphics(makeplot(), video_file, 1280, 720, res = 144, vfilter = 'framerate=fps=10')
av::av_video_info(video_file)
# utils::browseURL(video_file)
# }

Run the code above in your browser using DataCamp Workspace