Skip to main content

ez_ffmpeg/core/context/output/
bsf.rs

1use super::Output;
2
3impl Output {
4    /// Sets the **bitstream-filter chain** for the **video** output stream(s),
5    /// equivalent to FFmpeg `-bsf:v`.
6    ///
7    /// Bitstream filters transform encoded packets without decoding them (e.g.
8    /// rewriting NAL headers). The chain runs in the mux stage — after stream
9    /// copy or encoding, before the packet is written — matching the FFmpeg CLI.
10    ///
11    /// # Arguments
12    /// * `bsf_chain` - A single BSF name (e.g. `"h264_mp4toannexb"`) or a
13    ///   comma-separated chain with per-filter options
14    ///   (e.g. `"hevc_metadata=aud=insert,extract_extradata"`), parsed by
15    ///   FFmpeg's `av_bsf_list_parse_str`. An **empty string clears** any
16    ///   previously set video BSF.
17    ///
18    /// # Returns
19    /// * `Self` - Returns the modified `Output`, allowing for method chaining.
20    ///
21    /// # Examples
22    /// ```rust,ignore
23    /// // Convert H.264 from MP4 (length-prefixed) to Annex B for MPEG-TS.
24    /// let output = Output::from("output.ts")
25    ///     .set_format("mpegts")
26    ///     .add_stream_map_with_copy("0:v")
27    ///     .set_video_bsf("h264_mp4toannexb");
28    /// ```
29    pub fn set_video_bsf(mut self, bsf_chain: impl Into<String>) -> Self {
30        let chain = bsf_chain.into();
31        self.video_bsf = if chain.is_empty() { None } else { Some(chain) };
32        self
33    }
34
35    /// Sets the **bitstream-filter chain** for the **audio** output stream(s),
36    /// equivalent to FFmpeg `-bsf:a`.
37    ///
38    /// See [`set_video_bsf`](Self::set_video_bsf) for the chain syntax; an
39    /// **empty string clears** any previously set audio BSF.
40    ///
41    /// # Examples
42    /// ```rust,ignore
43    /// let output = Output::from("output.aac")
44    ///     .add_stream_map_with_copy("0:a")
45    ///     .set_audio_bsf("aac_adtstoasc");
46    /// ```
47    pub fn set_audio_bsf(mut self, bsf_chain: impl Into<String>) -> Self {
48        let chain = bsf_chain.into();
49        self.audio_bsf = if chain.is_empty() { None } else { Some(chain) };
50        self
51    }
52
53    /// Sets the **bitstream-filter chain** for the **subtitle** output
54    /// stream(s), equivalent to FFmpeg `-bsf:s`.
55    ///
56    /// See [`set_video_bsf`](Self::set_video_bsf) for the chain syntax; an
57    /// **empty string clears** any previously set subtitle BSF.
58    pub fn set_subtitle_bsf(mut self, bsf_chain: impl Into<String>) -> Self {
59        let chain = bsf_chain.into();
60        self.subtitle_bsf = if chain.is_empty() { None } else { Some(chain) };
61        self
62    }
63}