Skip to main content

StreamMap

Struct StreamMap 

Source
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 96k
use 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-type set_video_codec / set_audio_codec / set_subtitle_codec > the container format’s default encoder.
  • Options: per-map codec_opt entries are merged key by key over the per-type set_video_codec_opt / set_audio_codec_opt tables — the FFmpeg semantics, where every option matches its stream specifier independently (-b:v 4M -preset:v:0 slow leaves stream v:0 with 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

Source

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).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for StreamMap

Source§

fn clone(&self) -> StreamMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StreamMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Into<String>> From<T> for StreamMap

A plain specifier string is a map with no per-map overrides, so every pre-existing add_stream_map("0:v") call keeps compiling unchanged.

Source§

fn from(linklabel: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,