pub struct StreamMap { /* private fields */ }Expand description
Parameters for one stream mapping of an Output:
an FFmpeg-style specifier plus optional per-map encoder selection.
This is the builder-API equivalent of the FFmpeg CLI’s indexed
per-stream options. One -map plus its matching -c/-b/… options
become one StreamMap:
-map "[v0]" -c:v:0 libx264 -b:v:0 4M -preset:v:0 slow
-map "[v1]" -c:v:1 libx265 -crf:v:1 22
-map 0:a:0 -c:a:0 aac -b:a:0 128k
-map 0:a:1 -c:a:1 libopus -b:a:1 96kuse ez_ffmpeg::{Output, StreamMap};
let output = Output::from("out.mkv")
.add_stream_map(StreamMap::new("[v0]").codec("libx264")
.codec_opt("b", "4M").codec_opt("preset", "slow"))
.add_stream_map(StreamMap::new("[v1]").codec("libx265")
.codec_opt("crf", "22"))
.add_stream_map(StreamMap::new("0:a:0").codec("aac").codec_opt("b", "128k"))
.add_stream_map(StreamMap::new("0:a:1").codec("libopus").codec_opt("b", "96k"));§Precedence
- Encoder: per-map
codec> per-typeset_video_codec/set_audio_codec/set_subtitle_codec> the container format’s default encoder. - Options: per-map
codec_optentries are merged key by key over the per-typeset_video_codec_opt/set_audio_codec_opttables — the FFmpeg semantics, where every option matches its stream specifier independently (-b:v 4M -preset:v:0 slowleaves streamv:0with both the bitrate and the preset). A per-map key overrides the same-named per-type key; other per-type keys still apply.
This “more specific wins, per key” chain is the builder equivalent of the CLI’s “last matching option is applied” rule.
§Map granularity is binding granularity
A map that expands to several streams applies its codec to all of
them: StreamMap::new("0:a").codec("aac") re-encodes every audio
stream of input 0 with AAC (like -c:a aac). To give two streams
different encoders, write two single-stream maps ("0:a:0",
"0:a:1"), exactly like splitting one coarse -map 0 into indexed
maps on the CLI.
§Copy
codec("copy") selects stream copy for the map, equivalent to
Output::add_stream_map_with_copy
(FFmpeg -c:<spec> copy). Combining copy with a different per-map
codec, or with codec_opt entries, is rejected at
build time with
OpenOutputError::StreamMapCopyConflict:
copied packets never pass through an encoder, so those settings could
never take effect.
A negative (disabling) map such as "-0:v" only disables previously
matched streams; attaching a codec or codec options to one is rejected
at build time as well.
Implementations§
Source§impl StreamMap
impl StreamMap
Sourcepub fn new(spec: impl Into<String>) -> Self
pub fn new(spec: impl Into<String>) -> Self
Creates a mapping for spec, an FFmpeg-style stream specifier
("0:v", "1:a:0", "0:s?") or a filter output label
("[v0]").
Without further calls this is exactly
Output::add_stream_map(spec).
Sourcepub fn codec(self, name: impl Into<String>) -> Self
pub fn codec(self, name: impl Into<String>) -> Self
Selects the encoder for every stream this map matches — the
builder form of FFmpeg’s indexed -c:v:0 libx264.
"copy" selects stream copy (see the type-level docs). Calling
codec again replaces the previous value.
Sourcepub fn codec_opt(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn codec_opt(self, key: impl Into<String>, value: impl Into<String>) -> Self
Adds one encoder option for every stream this map matches — the
builder form of FFmpeg’s indexed -b:v:0 4M / -preset:v:0 slow.
Per-map entries override same-named per-type options key by key (see the type-level docs). Repeating a key keeps the last value.