ts2frame: Convert timestamps to frame numbers

Description Usage Arguments Details Value Examples

View source: R/exported.R

Description

This is typically used for aligning cells by a common time.

Usage

1
ts2frame(x, fps = 30, tstart = 0L, tend = NULL, as_ts = FALSE, warn = TRUE)

Arguments

x

Vector of timestamps in milliseconds

fps

Frames per second of the video source. Defaults to 30 fps. The smaller the value, the more likely two events will be binned together and marked as the same frame number.

tstart

Start timestamp in milliseconds (optional). Any timestamp before start start will be NA, and the frame number will start at 1 where above tstart. A warning will be triggered if anything outside of tstart and tend is found, unless warn=FALSE.

tend

Longest possible timestamp in milliseconds (optional). Any timestamp past tend will be NA. Defaults to max of x if not used.

as_ts

If set to TRUE, will return a timestamp representation of the frame number, adjusted for tstart and tend.

warn

Turn on/off warnings if any NAs were found.

Details

Frame numbers may be repeated if several timestamps are close in duration within the specified frames per second.

Value

A numeric vector of the same size as x.

Examples

1
2
3
4
5
t <- c(
  -1000, 100, 4047, 7451, 14347, -1,
  27920, 30669, 39798, 42504, 42510, 51451, 56034
)
ts2frame(t, tstart=1000, warn=FALSE)

iamamutt/datavyur documentation built on Dec. 20, 2021, 5:57 p.m.