Commit 326fcd28 authored by Todd Hayden's avatar Todd Hayden

added make_video_av function, added av to description file, recompiled package and namespace

parent d9e3d9ec
......@@ -31,7 +31,8 @@ Imports:
sf,
sp,
tibble,
tidyr
tidyr,
av
Suggests:
gganimate,
gifsky,
......@@ -53,6 +54,6 @@ Authors@R: c(
License: GPL-2
LazyLoad: yes
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
VignetteBuilder: knitr
Encoding: UTF-8
......@@ -22,6 +22,7 @@ export(make_transition)
export(make_transition2)
export(make_transition3)
export(make_video)
export(make_video_av)
export(min_lag)
export(point_offset)
export(position_heat_map)
......
##' Create video from sequence of still images
##'
##' Stitch a sequence of images into a video animation using R package "av"
##'
##' @param dir directory containing images, default is working
##' directory.
##' @param ext character, file extension of images to be stitched into
##' a video.
##' @param output character, output video file name. See details.
##' @param fps_in integer, intended framerate of input image sequence
##' in frames per second.
##' @param start_frame integer, start frame. Defaults to
##' \code{start=1}.
##' @param end_frame integer, end frame. Defaults to \code{end_frame
##' = NULL}.
##' @param codec character, video codec used.
##' @param verbose Logical (default = FALSE). If true, returns details
##' of processing
##' @param audio audio or video input file with sound for the output
##' video
##' @param vfilter a string defining an ffmpeg filter. This is the
##' same parameter as the -vf argument in FFmpeg.
##'
##' @details This function stitches a sequence of images into a video
##' without an external installation of FFmpeg software.
##' \code{make_video_av} is a simple wrapper of
##' \code{av_encode_video}. More information about the \code{av}
##' package is available at
##' https://cran.r-project.org/web/packages/av/index.html and
##' https://docs.ropensci.org/av/.
##'
##' @details The argument \code{codec} defaults to \code{libx264} for
##' most formats which is usually the best choice. More information
##' about other available codecs can be found by running
##' \code{av::av_encoders}. The argument \code{vfilter} is used to
##' specify FFmpeg filters to modify video output.
##' \code{av::av_filters()} function lists the possible filters
##' available. More information and examples of using filters to
##' manipulate video output can be found at
##' https://trac.ffmpeg.org/wiki/FilteringGuide#Examples
##'
##' @details A directory of sequenced image files (.png, .jpeg) are
##' passed to \code{dir} argument. The \code{ext} argument
##' specifies the type of files to be stitched into a video. The
##' images passed to the function must all have the same size,
##' height, and format.
##'
##' @details Function can create .mp4, .mov, .mkv, .flv .wmv, or
##' .mpeg animations. Format of created animation is determined by
##' file extension of \code{output}.
##'
##' @details \code{make_video_av} allows user to specify input
##' framerate \code{fps_in} of image sequence and specify the
##' starting and ending frames (\code{start_frame},
##' \code{end_frame}). If specified, only images within range are
##' used in animation and all other frames are skipped.
##'
##' @details
##'
##' @return One video animation will be written to \code{output_dir}
##'
##' @author Todd Hayden, Tom Binder, Chris Holbrook
##'
##' @examples
##'
##' \dontrun{
##'
##' # load frames
##' frames <- system.file("extdata", "frames", package = "glatos")
##'
##' # make .mp4 video
##' make_video_av(dir = frames, ext = ".png", output = "animation1.mp4", verbose = FALSE)
##'
##' # make .wmv video
##' make_video_av(dir=frames, ext = ".png", output = "animation2.wmv", verbose = TRUE)
##'
##' # start animation on frame 10, end on frame 20
##' make_video_av(dir=frames, ext = ".png", start_frame = 10,
##' end_frame = 20, output = "animation_3.mp4")
##'
##'# make move backwards- start animation of frame 20 and end on frame 10
##' make_video_av(dir=frames, ext = ".png", start_frame = 20,
##' end_frame = 10, output = "animation_4.mp4")
##'
##' # resize output video by specifying a scale filter
##' make_video_av(dir=frames, ext= ".png", vfilter = "scale=320:240",
##' output = "animation_5.mp4" )
##'
##' # slow the video by 10 times
##' make_video_av(dir=frames, ext= ".png", vfilter = "setpts=10*PTS",
##' output = "animation_6.mp4" )
##'
##' # slow video by 10 times and scale to 320x240 resolution
##' make_video_av(dir=frames, ext = ".png",
##' vfilter = "scale=320:240, setpts=10*PTS", output = "animation_7.mp4")
##'
##' # slow video by 10 times and smooth movement
##' make_video_av(dir=frames, ext = ".png", vfilter = "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120', setpts=10*PTS", output = "animation_8.mp4")
##'
##' # change input framerate
##' make_video_av(dir=frames, ext = ".png", fps_in = 5,
##' output = "animation_9.mp4")
##'
##' }
##'
##' @export
make_video_av <- function(dir = getwd(),
ext = ".png",
output = "animation.mp4",
fps_in = 30,
start_frame = 1,
end_frame = NULL,
codec = NULL,
vfilter = NULL,
verbose = TRUE,
audio = NULL){
# makes vector of images
ext <- paste0("*", ext)
files <- list.files(dir, full.names = TRUE, pattern = ext)
#check if dir exists
if(!dir.exists(dir)) stop(paste0("Input dir '", dir , "' not found."),
.call = FALSE)
# subset out frames if needed
if(is.null(end_frame)){end_frame <- length(files)}
fls <- files[start_frame:end_frame]
if(is.null(vfilter)){vfilt <- "null"} else {vfilt <- vfilter}
av::av_encode_video(input = fls, output = output, framerate = fps_in, vfilter = vfilt, codec = codec, verbose = verbose, audio = audio)
message("Video file written to ", output, ".")
}
......@@ -4,10 +4,18 @@
\alias{abacus_plot}
\title{Plot detection locations of acoustic transmitters over time}
\usage{
abacus_plot(det, location_col = "glatos_array", locations = NULL,
show_receiver_status = NULL, receiver_history = NULL,
out_file = NULL, x_res = 5, x_format = "\%Y-\%m-\%d",
outFile = NULL, ...)
abacus_plot(
det,
location_col = "glatos_array",
locations = NULL,
show_receiver_status = NULL,
receiver_history = NULL,
out_file = NULL,
x_res = 5,
x_format = "\%Y-\%m-\%d",
outFile = NULL,
...
)
}
\arguments{
\item{det}{A \code{glatos_detections} object (e.g., produced by
......
......@@ -4,9 +4,15 @@
\alias{adjust_playback_time}
\title{Modify playback time of video}
\usage{
adjust_playback_time(scale_factor = 1, input, output_dir = getwd(),
output = "new.mp4", overwrite = FALSE, ffmpeg = NA,
diagnostic_mode = FALSE)
adjust_playback_time(
scale_factor = 1,
input,
output_dir = getwd(),
output = "new.mp4",
overwrite = FALSE,
ffmpeg = NA,
diagnostic_mode = FALSE
)
}
\arguments{
\item{scale_factor}{multiplicative factor changes duration of
......
......@@ -4,8 +4,12 @@
\alias{calc_collision_prob}
\title{Estimate probability of collision for telemetry transmitters}
\usage{
calc_collision_prob(delayRng = c(60, 180), burstDur = 5,
maxTags = 50, nTrans = 10000)
calc_collision_prob(
delayRng = c(60, 180),
burstDur = 5,
maxTags = 50,
nTrans = 10000
)
}
\arguments{
\item{delayRng}{A 2-element numeric vector with minimum and maximum delay
......
......@@ -4,8 +4,13 @@
\alias{crw}
\title{Simulate a correlated random walk}
\usage{
crw(theta = c(0, 5), stepLen = 10, initPos = c(0, 0),
initHeading = 0, nsteps = 10000)
crw(
theta = c(0, 5),
stepLen = 10,
initPos = c(0, 0),
initHeading = 0,
nsteps = 10000
)
}
\arguments{
\item{theta}{A 2-element numeric vector with turn angle parameters
......
......@@ -4,9 +4,17 @@
\alias{crw_in_polygon}
\title{Simulate a correlated random walk inside a polygon}
\usage{
crw_in_polygon(polyg, theta = c(0, 10), stepLen = 100,
initPos = c(NA, NA), initHeading = NA, nsteps = 30, EPSG = 3175,
sp_out = TRUE, show_progress = TRUE)
crw_in_polygon(
polyg,
theta = c(0, 10),
stepLen = 100,
initPos = c(NA, NA),
initHeading = NA,
nsteps = 30,
EPSG = 3175,
sp_out = TRUE,
show_progress = TRUE
)
}
\arguments{
\item{polyg}{A \code{\link[sp]{SpatialPolygons}} object.
......
......@@ -4,8 +4,14 @@
\alias{detect_transmissions}
\title{Simulate detection of transmitter signals in a receiver network}
\usage{
detect_transmissions(trnsLoc = NA, recLoc = NA, detRngFun = NA,
EPSG = 3175, sp_out = TRUE, show_progress = TRUE)
detect_transmissions(
trnsLoc = NA,
recLoc = NA,
detRngFun = NA,
EPSG = 3175,
sp_out = TRUE,
show_progress = TRUE
)
}
\arguments{
\item{trnsLoc}{A three-column data frame with locations (numeric columns
......
......@@ -4,10 +4,18 @@
\alias{detection_bubble_plot}
\title{Plot number of tagged animals or detections on a map}
\usage{
detection_bubble_plot(det, location_col = "glatos_array",
receiver_locs = NULL, map = NULL, out_file = NULL,
background_ylim = c(41.3, 49), background_xlim = c(-92.45, -75.87),
symbol_radius = 1, col_grad = c("white", "red"), scale_loc = NULL)
detection_bubble_plot(
det,
location_col = "glatos_array",
receiver_locs = NULL,
map = NULL,
out_file = NULL,
background_ylim = c(41.3, 49),
background_xlim = c(-92.45, -75.87),
symbol_radius = 1,
col_grad = c("white", "red"),
scale_loc = NULL
)
}
\arguments{
\item{det}{A \code{glatos_detections} object (e.g., produced by
......
......@@ -4,8 +4,12 @@
\alias{detection_events}
\title{Classify discrete events in detection data}
\usage{
detection_events(det, location_col = "glatos_array", time_sep = Inf,
condense = TRUE)
detection_events(
det,
location_col = "glatos_array",
time_sep = Inf,
condense = TRUE
)
}
\arguments{
\item{det}{A \code{glatos_detections} object (e.g., produced by
......
......@@ -4,8 +4,7 @@
\alias{false_detections}
\title{False detection filter}
\usage{
false_detections(det, tf, min_lag_col = "min_lag", show_plot = FALSE,
...)
false_detections(det, tf, min_lag_col = "min_lag", show_plot = FALSE, ...)
}
\arguments{
\item{det}{A \code{glatos_detections} object (e.g., produced by
......
......@@ -4,8 +4,7 @@
\alias{get_days}
\title{Determines which calculation method to use for the residency index.}
\usage{
get_days(dets, calculation_method = "kessel",
time_interval_size = "1 day")
get_days(dets, calculation_method = "kessel", time_interval_size = "1 day")
}
\arguments{
\item{dets}{- data frame pulled from the detection events}
......
......@@ -3,7 +3,6 @@
\docType{package}
\name{glatos}
\alias{glatos}
\alias{glatos-package}
\title{An R package for the Great Lakes Acoustic Telemetry Observation System}
\description{
\code{glatos} is an R package with functions useful to members of the Great
......
......@@ -4,9 +4,15 @@
\alias{interpolate_path}
\title{Interpolate new positions within a spatiotemporal path data}
\usage{
interpolate_path(det, trans = NULL, start_time = NULL,
int_time_stamp = 86400, lnl_thresh = 0.9, out_class = NULL,
show_progress = TRUE)
interpolate_path(
det,
trans = NULL,
start_time = NULL,
int_time_stamp = 86400,
lnl_thresh = 0.9,
out_class = NULL,
show_progress = TRUE
)
}
\arguments{
\item{det}{An object of class \code{glatos_detections} or data frame
......
......@@ -4,9 +4,18 @@
\alias{kml_workbook}
\title{Make a KML or KMZ file of receiver and animal release locations}
\usage{
kml_workbook(wb = NULL, wb_file = NULL, receiver_locs = NULL,
animals = NULL, kmz = FALSE, show_ongoing_recs = TRUE,
end_date = NULL, out_file = NULL, wb_version = NULL, ...)
kml_workbook(
wb = NULL,
wb_file = NULL,
receiver_locs = NULL,
animals = NULL,
kmz = FALSE,
show_ongoing_recs = TRUE,
end_date = NULL,
out_file = NULL,
wb_version = NULL,
...
)
}
\arguments{
\item{wb}{A \code{glatos_workbook} object created by
......
......@@ -4,12 +4,24 @@
\alias{make_frames}
\title{Create an animated video of spatiotemporal path data}
\usage{
make_frames(proc_obj, recs = NULL, out_dir = getwd(),
background_ylim = c(41.3, 49), background_xlim = c(-92.45, -75.87),
show_interpolated = TRUE, tail_dur = 0, animate = TRUE,
ani_name = "animation.mp4", frame_delete = FALSE,
overwrite = FALSE, ffmpeg = NA, preview = FALSE, bg_map = NULL,
show_progress = TRUE, ...)
make_frames(
proc_obj,
recs = NULL,
out_dir = getwd(),
background_ylim = c(41.3, 49),
background_xlim = c(-92.45, -75.87),
show_interpolated = TRUE,
tail_dur = 0,
animate = TRUE,
ani_name = "animation.mp4",
frame_delete = FALSE,
overwrite = FALSE,
ffmpeg = NA,
preview = FALSE,
bg_map = NULL,
show_progress = TRUE,
...
)
}
\arguments{
\item{proc_obj}{A data frame created by
......@@ -170,7 +182,7 @@ recs <- read_glatos_receivers(rec_file)
pos1 <- interpolate_path(dtc)
# make sequential frames and animation
# make sure ffmpeg is installed if argument \\code{animate = TRUE}
# make sure ffmpeg is installed if argument \code{animate = TRUE}
# If you have not added path to 'ffmpeg.exe' to your Windows PATH
# environment variable then you'll need to do that
# or set path to 'ffmpeg.exe' using the 'ffmpeg' input argument
......
......@@ -4,8 +4,13 @@
\alias{make_transition}
\title{Create transition layer from polygon shapefile}
\usage{
make_transition(in_file, output = "out.tif", output_dir = NULL,
res = c(0.1, 0.1), all_touched = TRUE)
make_transition(
in_file,
output = "out.tif",
output_dir = NULL,
res = c(0.1, 0.1),
all_touched = TRUE
)
}
\arguments{
\item{in_file}{A SpatialPolygonsDataFrame object or a character string with file path to
......
......@@ -4,8 +4,13 @@
\alias{make_transition2}
\title{Create transition layer from a spatial polygon}
\usage{
make_transition2(poly, res = c(0.1, 0.1), extent_out = NULL,
x_lim = NULL, y_lim = NULL)
make_transition2(
poly,
res = c(0.1, 0.1),
extent_out = NULL,
x_lim = NULL,
y_lim = NULL
)
}
\arguments{
\item{poly}{A spatial polygon object of class
......
......@@ -4,8 +4,7 @@
\alias{make_transition3}
\title{Create transition layer from polygon shapefile}
\usage{
make_transition3(poly, res = c(0.1, 0.1), receiver_points = NULL,
epsg = 3175)
make_transition3(poly, res = c(0.1, 0.1), receiver_points = NULL, epsg = 3175)
}
\arguments{
\item{poly}{A spatial polygon object of class
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vis-make_video.r
% Please edit documentation in R/vis-make_video_ffmpeg.r
\name{make_video}
\alias{make_video}
\title{Create video from sequence of still images}
\usage{
make_video(dir = getwd(), pattern, output = "animation.mp4",
output_dir = getwd(), fps_in = 30, start_frame = 1,
end_frame = NULL, size = "source", preset = "medium",
codec = "default", format = "yuv420p", lossless = FALSE,
fps_out = 30, overwrite = FALSE, ffmpeg = NA,
diagnostic_mode = FALSE)
make_video(
dir = getwd(),
pattern,
output = "animation.mp4",
output_dir = getwd(),
fps_in = 30,
start_frame = 1,
end_frame = NULL,
size = "source",
preset = "medium",
codec = "default",
format = "yuv420p",
lossless = FALSE,
fps_out = 30,
overwrite = FALSE,
ffmpeg = NA,
diagnostic_mode = FALSE
)
}
\arguments{
\item{dir}{directory containing images, default is working
......@@ -166,7 +178,7 @@ Presets provide a certain encoding speed to compression
frames <- system.file("extdata", "frames", package = "glatos")
# make .mp4 video
# make sure ffmpeg is on system path (see \\code{make_frames} and details)
# make sure ffmpeg is on system path (see \code{make_frames} and details)
make_video(dir = frames, pattern = "\%02d.png", output = "animation.mp4" )
# make .wmv video
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vis-make_video_av.r
\name{make_video_av}
\alias{make_video_av}
\title{Create video from sequence of still images}
\usage{
make_video_av(
dir = getwd(),
ext = ".png",
output = "animation.mp4",
fps_in = 30,
start_frame = 1,
end_frame = NULL,
codec = NULL,
vfilter = NULL,
verbose = TRUE,
audio = NULL
)
}
\arguments{
\item{dir}{directory containing images, default is working
directory.}
\item{ext}{character, file extension of images to be stitched into
a video.}
\item{output}{character, output video file name. See details.}
\item{fps_in}{integer, intended framerate of input image sequence
in frames per second.}
\item{start_frame}{integer, start frame. Defaults to
\code{start=1}.}
\item{end_frame}{integer, end frame. Defaults to \code{end_frame
= NULL}.}
\item{codec}{character, video codec used.}
\item{vfilter}{a string defining an ffmpeg filter. This is the
same parameter as the -vf argument in FFmpeg.}
\item{verbose}{Logical (default = FALSE). If true, returns details
of processing}
\item{audio}{audio or video input file with sound for the output
video}
}
\value{
One video animation will be written to \code{output_dir}
}
\description{
Stitch a sequence of images into a video animation using R package "av"
}
\details{
This function stitches a sequence of images into a video
without an external installation of FFmpeg software.
\code{make_video_av} is a simple wrapper of
\code{av_encode_video}. More information about the \code{av}
package is available at
https://cran.r-project.org/web/packages/av/index.html and
https://docs.ropensci.org/av/.
The argument \code{codec} defaults to \code{libx264} for
most formats which is usually the best choice. More information
about other available codecs can be found by running
\code{av::av_encoders}. The argument \code{vfilter} is used to
specify FFmpeg filters to modify video output.
\code{av::av_filters()} function lists the possible filters
available. More information and examples of using filters to
manipulate video output can be found at
https://trac.ffmpeg.org/wiki/FilteringGuide#Examples
A directory of sequenced image files (.png, .jpeg) are
passed to \code{dir} argument. The \code{ext} argument
specifies the type of files to be stitched into a video. The
images passed to the function must all have the same size,
height, and format.
Function can create .mp4, .mov, .mkv, .flv .wmv, or
.mpeg animations. Format of created animation is determined by
file extension of \code{output}.
\code{make_video_av} allows user to specify input
framerate \code{fps_in} of image sequence and specify the
starting and ending frames (\code{start_frame},
\code{end_frame}). If specified, only images within range are
used in animation and all other frames are skipped.
}
\examples{
\dontrun{
# load frames
frames <- system.file("extdata", "frames", package = "glatos")
# make .mp4 video
make_video_av(dir = frames, ext = ".png", output = "animation1.mp4", verbose = FALSE)
# make .wmv video
make_video_av(dir=frames, ext = ".png", output = "animation2.wmv", verbose = TRUE)
# start animation on frame 10, end on frame 20
make_video_av(dir=frames, ext = ".png", start_frame = 10,
end_frame = 20, output = "animation_3.mp4")
# make move backwards- start animation of frame 20 and end on frame 10
make_video_av(dir=frames, ext = ".png", start_frame = 20,
end_frame = 10, output = "animation_4.mp4")
# resize output video by specifying a scale filter
make_video_av(dir=frames, ext= ".png", vfilter = "scale=320:240",
output = "animation_5.mp4" )
# slow the video by 10 times
make_video_av(dir=frames, ext= ".png", vfilter = "setpts=10*PTS",
output = "animation_6.mp4" )
# slow video by 10 times and scale to 320x240 resolution
make_video_av(dir=frames, ext = ".png",
vfilter = "scale=320:240, setpts=10*PTS", output = "animation_7.mp4")
# slow video by 10 times and smooth movement
make_video_av(dir=frames, ext = ".png", vfilter = "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120', setpts=10*PTS", output = "animation_8.mp4")
# change input framerate
make_video_av(dir=frames, ext = ".png", fps_in = 5,
output = "animation_9.mp4")
}
}
\author{
Todd Hayden, Tom Binder, Chris Holbrook
}
......@@ -4,8 +4,13 @@
\alias{point_offset}
\title{Identify new location based on distance and bearing from another}
\usage{
point_offset(lon = NA, lat = NA, offsetDist = NA, offsetDir = NA,
distUnit = "m")
point_offset(
lon = NA,
lat = NA,
offsetDist = NA,
offsetDir = NA,
distUnit = "m"
)
}
\arguments{
\item{lon}{vector of longitudes (dd) to calculate offset points}
......
......@@ -4,11 +4,22 @@
\alias{position_heat_map}
\title{Position Heat Maps}
\usage{
position_heat_map(positions, projection = "LL", fish_pos_int = "fish",
abs_or_rel = "absolute", resolution = 10, interval = NULL,
x_limits = NULL, y_limits = NULL, utm_zone = NULL,
hemisphere = "N", legend_gradient = "y", legend_pos = c(0.99, 0.2,
1, 0.8), output = "plot", folder = "position_heat_map")
position_heat_map(
positions,
projection = "LL",
fish_pos_int = "fish",
abs_or_rel = "absolute",
resolution = 10,
interval = NULL,
x_limits = NULL,
y_limits = NULL,
utm_zone = NULL,
hemisphere = "N",
legend_gradient = "y",
legend_pos = c(0.99, 0.2, 1, 0.8),
output = "plot",
folder = "position_heat_map"
)
}
\arguments{
\item{positions}{A dataframe containing detection data with at least the
......
......@@ -4,9 +4,17 @@
\alias{receiver_line_det_sim}
\title{Simulate detection of acoustic-tagged fish crossing a receiver line}
\usage{
receiver_line_det_sim(vel = 1, delayRng = c(120, 360), burstDur = 5,
recSpc = 1000, maxDist = 2000, rngFun, outerLim = c(0, 0),
nsim = 1000, showPlot = FALSE)
receiver_line_det_sim(
vel = 1,
delayRng = c(120, 360),
burstDur = 5,
recSpc = 1000,
maxDist = 2000,
rngFun,
outerLim = c(0, 0),
nsim = 1000,
showPlot = FALSE
)
}
\arguments{
\item{vel}{A numeric scalar with fish velocity in meters per second.}
......
......@@ -4,9 +4,14 @@
\alias{residence_index}
\title{Generate the residence index from a set of detections}
\usage{
residence_index(detections, calculation_method = "kessel",
locations = NULL, group_col = "animal_id",
time_interval_size = "1 day", groupwise_total = TRUE)
residence_index(
detections,
calculation_method = "kessel",
locations = NULL,
group_col = "animal_id",
time_interval_size = "1 day",
groupwise_total = TRUE
)
}
\arguments{
\item{detections}{A data.frame from the \code{\link{detection_events}}
......