Uses ffmpeg through the av package to stitch images into a video.

images.to.video(
  image.dir = NULL,
  out.dir = NULL,
  vid.name = NULL,
  overwrite = FALSE,
  ...
)

Arguments

image.dir

character; directory containing images to stitch.

out.dir

character; directory in which to store video.

vid.name

character; file name given to video including extension.

overwrite

logical; should path described by vid.name be overwritten if it exists.

...

other arguments to be passed to av::av_encode_video.

Value

Outputs a video of name "video.name+vid.ext".

Details

Assumes images are appended with a numeric sequence.

Examples


#make some images
# \donttest{
dir.create(paste0(tempdir(),"/images")) #make a directory to store images

a <- 2
b <- 3
theta <- seq(0,10*pi,0.01)
r <- a + b*theta
df <- data.frame(x=r*cos(theta), y=r*sin(theta)) # Cartesian coords
every.i <- 30
for(i in seq(1,length(theta),30)) {
  jpeg(paste0(tempdir(),"/images/image_",sprintf("%03d",which(i==seq(1,length(theta),30))),".jpg"))
  with(df[1:i,],plot(x,y,xlim=range(df$x),ylim=range(df$y),col="red"))
  dev.off()
  }

images.to.video(image.dir=paste0(tempdir(),"/images"),vid.name="spiral.mp4",out.dir=tempdir())
#> successfully created video '/var/folders/5c/s3c2hjfd7blbqwwpl1q10wxm0000gy/T//RtmpNMLlNq/spiral.mp4'

file.exists(paste0(tempdir(),"/spiral.mp4"))
#> [1] TRUE

#clean up
unlink(paste0(tempdir(),"/spiral.mp4"))
unlink(paste0(tempdir(),"/images"),recursive=TRUE)
# }