Skip to contents

Save one frame of a video to an image file, selected either by timestamp or by frame number. Provide exactly one of timestamp or frame.

Usage

extract_frame(infile, outfile, timestamp = NULL, frame = NULL, run = TRUE)

Arguments

infile

A string containing the path to a video file.

outfile

A string containing the path of the image file to write.

timestamp

Either a number of seconds, a time-duration-syntax string, or NULL. Provide exactly one of timestamp or frame.

frame

Either an integerish frame number or NULL. Provide exactly one of timestamp or frame.

run

A logical: run the command through FFmpeg (TRUE, default) or return the compiled command without running it (FALSE).

Value

The compiled FFmpeg command (invisibly when run = TRUE).

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# run = FALSE returns the reproducible command instead of executing it
extract_frame(video, "frame.png", timestamp = 0.5, run = FALSE)
#> [1] "-y -ss 0.5 -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -avoid_negative_ts make_zero -qmin 1 -q:v 1 -qscale:v 2 -frames:v 1 -huffman optimal \"frame.png\""