ffm_seek: Cut a Continuous Section from an FFmpeg Pipeline by Seeking

View source: R/ffm.R

ffm_seekR Documentation

Cut a Continuous Section from an FFmpeg Pipeline by Seeking

Description

Keep one continuous section of the input with FFmpeg's fast -ss and -to seek options. It does not use the trim filter of ffm_trim. Unlike the filter, seeking can use stream copy, so it is the tool for fast, lossless cuts. The glossary in vignette("tidymedia") explains media terms such as keyframe, re-encode and stream copy.

Usage

ffm_seek(object, start = NULL, end = NULL, reencode = TRUE)

Arguments

object

An FFmpeg pipeline (ffm) object created by ffm_files().

start

The start of the kept section, in seconds or in FFmpeg time duration syntax. NULL keeps the section from the beginning.

end

The end of the kept section, in seconds or in FFmpeg time duration syntax. NULL keeps the section to the end.

reencode

A logical. TRUE (the default) re-encodes for a frame-accurate cut. FALSE makes a fast seek that is safe to copy, and its cut points move to keyframes.

Details

The reencode argument trades accuracy against speed:

  • reencode = TRUE (the default) is frame-accurate. The section is re-encoded, so it starts and ends on the exact frames you ask for. This is the safe default.

  • reencode = FALSE is a fast, lossless copy. But the cut points move to the nearest keyframes. So the output duration can differ from the request by up to the gap between two keyframes. Use it with ffm_copy for the fastest path.

Value

object with an added instruction to cut the input by seeking.

References

https://ffmpeg.org/ffmpeg.html#Main-options

See Also

ffm_trim() for the filter that cuts, ffm_copy() for the fast copy path, and segment_video(), the task function built on it.

Other pipeline functions: ffm_batch(), ffm_codec(), ffm_compile(), ffm_concat(), ffm_copy(), ffm_crop(), ffm_drawbox(), ffm_drop(), ffm_files(), ffm_fps(), ffm_hstack(), ffm_jobs(), ffm_loudnorm(), ffm_map(), ffm_output_options(), ffm_overlay(), ffm_pixel_format(), ffm_run(), ffm_scale(), ffm_trim(), ffm_vstack(), print.tidymedia_ffm()

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
# Fast, lossless copy cut (snaps to keyframes)
ffm_files(video, "output.mp4") |>
  ffm_seek(start = 1, end = 5, reencode = FALSE) |>
  ffm_copy() |>
  ffm_compile()

tidymedia documentation built on Oct. 11, 2026, 5:08 p.m.