R/ari_burn_subtitles.R

Defines functions ari_burn_subtitles

Documented in ari_burn_subtitles

#' Burn Subtitles into a video
#' 
#' @note This needs \code{ffmpeg} that was compiled with 
#' \code{--enable-libass} as per 
#' \url{https://trac.ffmpeg.org/wiki/HowToBurnSubtitlesIntoVideo}
#'
#' @param video Video in \code{mp4} format
#' @param srt Subtitle file in \code{srt} format
#' @param verbose print diagnostic messages.  If > 1, 
#' then more are printed
#'
#' @return Name of output video
ari_burn_subtitles = function(video, srt, verbose = FALSE) {
  ffmpeg = ffmpeg_exec(quote = TRUE)
  if (verbose > 0) {
    message("Burning in Subtitles")
  }
  command <- paste(
    ffmpeg, "-y -i", video, paste0("-vf subtitles=", srt),
    video)

  if (verbose > 0) {
    message(command)
  }
  res = system(command)
  if (res != 0) {
    warning("Result was non-zero for ffmpeg")
  }
  
  return(video)
}

Try the ari package in your browser

Any scripts or data that you put into this service are public.

ari documentation built on Feb. 9, 2020, 1:07 a.m.