subtitles:
FFmpeg-based Subtitle Authoring and Rendering in Rsubtitles provides tools to generate
standard subtitle files (SRT, ASS) from structured transcription outputs
and to render those subtitles into videos using the
FFmpeg command-line interface.
This package does not perform speech-to-text itself.
Instead, it works with structured transcription results — for example,
those produced by audio.whisper — to produce subtitle
artifacts and to orchestrate FFmpeg for subtitle rendering.
The core design principles are:
.srt, .ass) are first-class citizens.You must have FFmpeg installed and available on your system
PATH. A standard FFmpeg build with subtitle filter support
(libass) is required.
Verify installation:
ffmpeg -versionThis package is available on GitHub:
# install remotes if you don’t have it
install.packages("remotes")
# install subtitles from GitHub
remotes::install_github("cornball-ai/subtitles")Use your preferred speech-to-text tool. For example, with
audio.whisper:
srt_text <- predict(
model,
newdata = "audio.wav",
language = "en",
token_timestamps = TRUE
)This returns a structured transcription object with segments and token timing.
whisper_to_srt(srt_text, file = "captions.srt")This produces a valid SubRip (.srt) file representing
the timed segments.
ASS format supports richer styling and optional karaoke-style word highlighting:
whisper_to_ass(srt_text, file = "captions.ass", karaoke = TRUE)burn_subtitles(
video = "input.mp4",
subtitles = "captions.ass",
output = "output_with_subtitles.mp4"
)You can also pass style overrides:
burn_subtitles(
"input.mp4",
"captions.srt",
"output.mp4",
style = "FontSize=36,Outline=2,Shadow=1"
)whisper_to_srt(x, file)Converts a structured transcription object into a SubRip
.srt file.
x: Object returned from a transcription tool with
segments.file: Path where the SRT file will be saved.whisper_to_ass(x, file, karaoke = TRUE)Converts a structured transcription object into an Advanced
SubStation Alpha (.ass) file.
karaoke: If TRUE, include token-level
timing for word highlighting.burn_subtitles(video, subtitles, output, style = NULL)Invokes the FFmpeg CLI to render subtitles into a video.
video: Path to the source video.subtitles: Path to .srt or
.ass subtitle file.output: Path where the subtitled video will be
saved.style: Optional ASS style overrides (passed to FFmpeg’s
filter).Every file these functions write gets a JSON record at
<output>.json: the resolved call (defaults filled in)
plus a media block describing the delivered file (event
count and time span for subtitles; fps, dimensions, and duration for
video). Downstream tooling can lift these records into edit metadata.
Disable with options(subtitles.sidecar = FALSE).
Existing R packages for subtitle manipulation either focus on parsing
(SRTtools) or linguistics. There is no dedicated,
FFmpeg-first R tool for generating subtitle artifacts from
structured transcriptions and invoking FFmpeg to render them.
subtitles fills that gap by
providing:
This package embraces the fact that the FFmpeg command line
is the authoritative interface for video processing. Rather
than hiding or abstracting it, subtitles builds on it:
This aligns with how video professionals work and ensures your R code stays in sync with FFmpeg documentation and community tooling.
processx (for process execution)Contributions are welcome. Suggested areas:
MIT
This package is not a speech-to-text provider. It is designed to integrate with tools such as:
audio.whisper