Given a vector of paths to images (preferably .jpgs or .pngs) and a flat list of Waves of equal length this function will create an .mp4 video file where each image is shown with its corresponding audio. Take a look at the readWave function if you want to import your audio files into R. Please be sure that all images have the same dimensions.

ari_stitch(
  images,
  audio,
  output = tempfile(fileext = ".mp4"),
  verbose = FALSE,
  cleanup = TRUE,
  ffmpeg_opts = "",
  divisible_height = TRUE,
  audio_codec = get_audio_codec(),
  video_codec = get_video_codec(),
  video_sync_method = "2",
  audio_bitrate = NULL,
  video_bitrate = NULL,
  pixel_format = "yuv420p",
  fast_start = FALSE,
  deinterlace = FALSE,
  stereo_audio = TRUE,
  duration = NULL,
  video_filters = NULL
)

Arguments

images

A vector of paths to images.

audio

A list of Waves from tuneR.

output

A path to the video file which will be created.

verbose

print diagnostic messages. If > 1, then more are printed

cleanup

If TRUE, interim files are deleted

ffmpeg_opts

additional options to send to ffmpeg. This is an advanced option, use at your own risk

divisible_height

Make height divisible by 2, which may be required if getting "height not divisible by 2" error.

audio_codec

The audio encoder for the splicing. If this fails, try copy.

video_codec

The video encoder for the splicing. If this fails, see ffmpeg -codecs

video_sync_method

Video sync method. Should be "auto" or `"vfr"` or a numeric. See https://ffmpeg.org/ffmpeg.html.

audio_bitrate

Bit rate for audio. Passed to -b:a.

video_bitrate

Bit rate for video. Passed to -b:v.

pixel_format

pixel format to encode for `ffmpeg`.

fast_start

Adding `faststart` flags for YouTube and other sites, see https://trac.ffmpeg.org/wiki/Encode/YouTube

deinterlace

should the video be de-interlaced, see https://ffmpeg.org/ffmpeg-filters.html, generally for YouTube

stereo_audio

should the audio be forced to stereo, corresponds to `-ac 2`

duration

a vector of numeric durations for each audio track. See pad_wav

video_filters

any options that are passed to -vf arguments for ffmpeg

Value

A logical value, with the attribute outfile for the output file.

Details

This function uses FFmpeg which you should be sure is installed before using this function. If running Sys.which("ffmpeg") in your R console returns an empty string after installing FFmpeg then you should set the path to FFmpeg on you computer to an environmental variable using Sys.setenv(ffmpeg = "path/to/ffmpeg"). The environmental variable will always override the result of Sys.which("ffmpeg").

Examples

if (FALSE) { if (ffmpeg_version_sufficient()) { result = ari_stitch( ari_example(c("mab1.png", "mab2.png")), list(tuneR::noise(), tuneR::noise())) } }