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.
Arguments
- object
An FFmpeg pipeline (
ffm) object created byffm_files().- mapping
A character vector of one or more stream specifiers. Each one adds one
-map.- replace
A logical.
TRUEdiscards any mapping already set onobject.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.
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()
#> [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\""