Skip to contents

Sample many videos into numbered image sequences, using one jobs table. This is the batch form of sample_frames(). Each row is one input video, sampled at a fixed rate into its own image sequence. The function is a thin wrapper over ffm_batch. It builds one reproducible command for each input. The glossary in vignette("tidymedia") explains media terms such as frame rate.

Usage

sample_frames_batch(
  jobs,
  fps = NULL,
  interval = NULL,
  outdir = NULL,
  format = "png",
  run = TRUE,
  parallel = FALSE,
  ...
)

Arguments

jobs

A data frame with one row per input. It needs at least an input column (source path). An optional outdir column gives the output directory for that row's sequence. When it is absent, the function derives one as <input-base>_frames beside each input. Optional fps and interval columns override the rate per row. The function ignores any other columns. The function refuses two rows whose image sequences would share a file-name pattern, before any row runs. Two rows share a pattern when they have the same output directory path and the same input file name without its extension. The directory path can come from the column, from the outdir argument, or from the derived name.

fps, interval

The sampling rate applied to every row, as in sample_frames(). A per-row column of the same name overrides it. Supply exactly one of the two (as an argument or a column). (default = NULL)

outdir

An optional single output directory for all rows. An outdir column overrides it. When both are absent, the function derives one directory per input. (default = NULL)

format

A string giving the output image file extension, as in sample_frames(). (default = "png")

run

A logical: run each input's command through FFmpeg (TRUE, default) or only compile them for inspection (FALSE).

parallel

A logical passed to ffm_batch: sample in parallel with furrr (TRUE) or one after another (FALSE, default). Parallel work follows the active future plan. TRUE under the default sequential plan runs one at a time and warns.

...

Additional arguments forwarded to ffm_batch, such as verify, manifest, checksums, and progress.

Value

The tibble returned by ffm_batch: jobs with an added command column. When outdir was derived, it also has the resolved outdir column. When run = TRUE, it has a success column, plus any columns the forwarded arguments add, such as verified.

Details

Supply the sampling rate once as the single fps or interval argument, which applies to every row. Or supply it per row as an fps or interval column, which overrides the argument of the same name. Supply exactly one of the two, fps or interval, across arguments and columns.

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
jobs <- tibble::tibble(
  input  = c(video, video),
  outdir = c(file.path(tempdir(), "a"), file.path(tempdir(), "b"))
)
# run = FALSE compiles one command per input without calling FFmpeg
sample_frames_batch(jobs, fps = 2, run = FALSE)
#> # A tibble: 2 × 3
#>   input                                                        outdir    command
#>   <chr>                                                        <chr>     <chr>  
#> 1 /home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4 /tmp/Rtm… "-y -i…
#> 2 /home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4 /tmp/Rtm… "-y -i…