ffm_map: Set the Stream Mapping in an FFmpeg Pipeline

View source: R/ffm.R

ffm_mapR Documentation

Set the Stream Mapping in an FFmpeg Pipeline

Description

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.

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.

Value

object with an added instruction to map streams.

See Also

ffm_copy(), which maps all streams, and separate_audio_video(), a task function built on ffm_map().

Other pipeline functions: ffm_batch(), ffm_codec(), ffm_compile(), ffm_concat(), ffm_copy(), ffm_crop(), ffm_drawbox(), ffm_drop(), ffm_files(), ffm_fps(), ffm_hstack(), ffm_jobs(), ffm_loudnorm(), ffm_output_options(), ffm_overlay(), ffm_pixel_format(), ffm_run(), ffm_scale(), ffm_seek(), ffm_trim(), ffm_vstack(), print.tidymedia_ffm()

Examples

video <- system.file("extdata", "sample.mp4", package = "tidymedia")
ffm_files(video, "output.mp4") |>
  ffm_map(mapping = "0") |>
  ffm_compile()

# 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()

tidymedia documentation built on Oct. 11, 2026, 5:08 p.m.