Skip to contents

Choose which input streams go into the output, with FFmpeg's -map option. The default, "0", maps every stream from the first input. The glossary in vignette("tidymedia") explains media terms such as stream.

Usage

ffm_map(object, mapping = "0", replace = FALSE)

Arguments

object

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

mapping

A character vector of one or more stream specifiers. Each one adds one -map.

replace

A logical. TRUE discards any mapping already set on object. FALSE (the default) adds to it.

Value

object with an added instruction to map streams.

Details

mapping can be a character vector. Each element adds one -map, in the order given. For example, ffm_map(object, c("0:v", "0:a:1")) keeps the video and the second audio track of the input.

A second ffm_map() call adds to the maps already set. It does not replace them. Pass replace = TRUE to discard them instead. That is how you narrow the all-streams map that ffm_copy sets. Adding to that map puts the stream in the output twice, and does not select it.

ffm_map() is the only pipeline function that adds to earlier calls. Every other ffm_* function that sets a value, ffm_copy included, replaces it. ffm_map() is different because its arguments are partial choices that combine. For example, you keep the video, then name one audio track.

When the pipeline uses a function with several inputs, such as ffm_hstack, your mapping is added beside the automatic -map "[vout]" of the filtered stream. For example, ffm_map(object, "0:a") keeps the audio of the first input next to the stacked video.

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
ffm_files(video, "output.mp4") |>
  ffm_map(mapping = "0") |>
  ffm_compile()
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -map \"0\" \"output.mp4\""

# Keep the video and the second audio track only
ffm_files(video, "output.mkv") |>
  ffm_map(mapping = c("0:v", "0:a:1")) |>
  ffm_compile()
#> [1] "-y -i \"/home/runner/work/_temp/Library/tidymedia/extdata/sample.mp4\" -map \"0:v\" -map \"0:a:1\" \"output.mkv\""