Skip to contents

animate_frames creates an animation from moveVis frames computed with frames_spatial, frames_graph or join_frames.

Usage

animate_frames(
  frames,
  out_file,
  fps = 25,
  width = 700,
  height = 700,
  res = 100,
  end_pause = 0,
  display = TRUE,
  overwrite = FALSE,
  verbose = TRUE,
  ...
)

Arguments

frames

an object of class moveVis created with frames_spatial.

out_file

character, the output file path, e.g. "/dir/to/file.mov". The file extension must correspond to a file format known by the available renderers of the running system. Use suggest_formats to get a vector of suggested known file formats.

fps

numeric, the number of frames to be displayed per second. Default is 2.

width

numeric, width of the output animation in pixels.

height

numeric, height of the output animation in pixels.

res

numeric, resolution of the output animation in ppi.

end_pause

numeric, defining how many seconds the last frame of the animation should be hold to add a pause at the the end of the animation. Default is 0 seconds to not add a pause.

display

logical, whether the animation should be displayed after rendering or not.

overwrite

logical, wether to overwrite an existing file, if out_file is already present.

verbose

logical, if TRUE, messages and progress information are displayed on the console (default).

...

additional arguments to be passed to the render function.

Value

None or the default image/video viewer displaying the animation

Details

An appropriate render function is selected depending on the file extension in out_file: For .gif files, gifski::save_gif is used, for any other (video) format, av::av_capture_graphics is used.

Author

Jakob Schwalb-Willmann

Examples

library(moveVis)
library(move2)
library(terra)

data("move_data", package = "moveVis")
r <- readRDS(example_data(file = "basemap_data.rds"))

# align movement
m <- align_move(move_data, res = units::set_units(4, "min"))
#> Temporal resolution of 4 [min] is used to align trajectories.

# create frames 
frames <- frames_spatial(m, r, r_type = "gradient", fade_raster = TRUE) %>% 
  add_colourscale(
    type = "gradient", colours = c("orange", "white", "darkgreen"),
    legend_title = "NDVI") %>% 
  add_northarrow(position = "bottomleft") %>% 
  add_scalebar(colour = "white", position = "bottomright") %>% 
  add_progress() %>% 
  add_timestamps(type = "label")
#> Processing input data...
#> Approximated animation duration: ≈ 7.52s at 25 fps using 188 frames
#> CRS (geodetic):   WGS 84
#> Assigning raster maps to frames...
 
# check available formats
suggest_formats()
#> [1] "gif"  "mov"  "mp4"  "flv"  "avi"  "mpeg" "3gp"  "ogg" 

if (FALSE) { # \dontrun{
# animate frames as GIF
out_file <- tempfile(fileext = ".gif")
animate_frames(frames, out_file = out_file)
browseURL(out_file) # view animation
 
# animate frames as mov
out_file <- tempfile(fileext = ".mov")
animate_frames(frames, out_file = out_file)
browseURL(out_file) # view animation
} # }