subclip: Extract a Time Range from a Media File

View source: R/subclip.R

subclipR Documentation

Extract a Time Range from a Media File

Description

Cut [start, start + duration] (or [start, end]) out of an audio or video file via ffmpeg. Re-encodes by default for frame-accurate cuts; set reencode = FALSE for a fast stream copy (cuts land on keyframes).

Usage

subclip(input, output, start = 0, duration = NULL, end = NULL, reencode = TRUE,
        overwrite = TRUE, dry_run = FALSE)

Arguments

input

Path to input media.

output

Path for the extracted output; extension selects the format.

start

Start time in seconds (default 0).

duration

Length in seconds, or NULL to use end or run to the end of the file.

end

End time in seconds (ignored when duration is set).

reencode

If TRUE (default), re-encode for accurate cuts; if FALSE, stream-copy (fast, keyframe-aligned).

overwrite

If TRUE (default), overwrite the output file.

dry_run

If TRUE, return the ffmpeg command without executing.

Value

Invisibly returns the output path. If dry_run, returns the command string.

Examples

## Not run: 
subclip("audio.mp3", "chunk.mp3", start = 2.14, duration = 5.0)
subclip("clip.mp4", "head.mp4", start = 0, end = 3, reencode = FALSE)

## End(Not run)


compost documentation built on Aug. 4, 2026, 5:11 p.m.