1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
use super::Output;
use std::collections::HashMap;
impl Output {
/// Sets a **video codec-specific option**.
///
/// These options control **video encoding parameters** such as compression, quality, and speed.
///
/// **Supported Parameters:**
/// | Parameter | Description |
/// |-----------|-------------|
/// | `crf=0-51` | Quality level for x264/x265, lower means higher quality (`0` is lossless) |
/// | `preset=ultrafast, superfast, fast, medium, slow, veryslow` | Encoding speed, affects compression efficiency |
/// | `tune=film, animation, grain, stillimage, fastdecode, zerolatency` | Optimizations for specific types of content |
/// | `b=4M` | Bitrate (e.g., `4M` for 4 Mbps) |
/// | `g=50` | GOP (Group of Pictures) size, affects keyframe frequency |
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_video_codec_opt("crf", "18")
/// .set_video_codec_opt("preset", "fast");
/// ```
pub fn set_video_codec_opt(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
if let Some(ref mut opts) = self.video_codec_opts {
opts.insert(key.into(), value.into());
} else {
let mut opts = HashMap::new();
opts.insert(key.into(), value.into());
self.video_codec_opts = Some(opts);
}
self
}
/// **Sets multiple video codec options at once.**
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_video_codec_opts(vec![
/// ("crf", "18"),
/// ("preset", "fast")
/// ]);
/// ```
pub fn set_video_codec_opts(
mut self,
opts: Vec<(impl Into<String>, impl Into<String>)>,
) -> Self {
let video_opts = self.video_codec_opts.get_or_insert_with(HashMap::new);
for (key, value) in opts {
video_opts.insert(key.into(), value.into());
}
self
}
/// Sets a **audio codec-specific option**.
///
/// These options control **audio encoding parameters** such as bitrate, sample rate, and format.
///
/// **Supported Parameters:**
/// | Parameter | Description |
/// |-----------|-------------|
/// | `b=192k` | Bitrate (e.g., `128k` for 128 Kbps, `320k` for 320 Kbps) |
/// | `compression_level=0-12` | Compression efficiency for formats like FLAC |
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_audio_codec_opt("b", "320k")
/// .set_audio_codec_opt("compression_level", "6");
/// ```
pub fn set_audio_codec_opt(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
if let Some(ref mut opts) = self.audio_codec_opts {
opts.insert(key.into(), value.into());
} else {
let mut opts = HashMap::new();
opts.insert(key.into(), value.into());
self.audio_codec_opts = Some(opts);
}
self
}
/// **Sets multiple audio codec options at once.**
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_audio_codec_opts(vec![
/// ("b", "320k"),
/// ("compression_level", "6")
/// ]);
/// ```
pub fn set_audio_codec_opts(
mut self,
opts: Vec<(impl Into<String>, impl Into<String>)>,
) -> Self {
let audio_opts = self.audio_codec_opts.get_or_insert_with(HashMap::new);
for (key, value) in opts {
audio_opts.insert(key.into(), value.into());
}
self
}
/// Sets a **subtitle codec-specific option**.
///
/// These options control **subtitle encoding parameters** such as format and character encoding.
///
/// **Supported Parameters:**
/// | Parameter | Description |
/// |-----------|-------------|
/// | `mov_text` | Subtitle format for MP4 files |
/// | `srt` | Subtitle format for `.srt` files |
/// | `ass` | Advanced SubStation Alpha (ASS) subtitle format |
/// | `forced_subs=1` | Forces the subtitles to always be displayed |
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_subtitle_codec_opt("mov_text", "");
/// ```
pub fn set_subtitle_codec_opt(
mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self {
if let Some(ref mut opts) = self.subtitle_codec_opts {
opts.insert(key.into(), value.into());
} else {
let mut opts = HashMap::new();
opts.insert(key.into(), value.into());
self.subtitle_codec_opts = Some(opts);
}
self
}
/// **Sets multiple subtitle codec options at once.**
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_subtitle_codec_opts(vec![
/// ("mov_text", ""),
/// ("forced_subs", "1")
/// ]);
/// ```
pub fn set_subtitle_codec_opts(
mut self,
opts: Vec<(impl Into<String>, impl Into<String>)>,
) -> Self {
let subtitle_opts = self.subtitle_codec_opts.get_or_insert_with(HashMap::new);
for (key, value) in opts {
subtitle_opts.insert(key.into(), value.into());
}
self
}
/// Sets a format-specific option for the output container.
///
/// FFmpeg supports various format-specific options that can be passed to the muxer.
/// These options allow fine-tuning of the output container’s behavior.
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_format_opt("movflags", "faststart")
/// .set_format_opt("flvflags", "no_duration_filesize");
/// ```
///
/// ### Common Format Options:
/// | Format | Option | Description |
/// |--------|--------|-------------|
/// | `mp4` | `movflags=faststart` | Moves moov atom to the beginning of the file for faster playback start |
/// | `flv` | `flvflags=no_duration_filesize` | Removes duration/size metadata for live streaming |
///
/// **Parameters:**
/// - `key`: The format option name (e.g., `"movflags"`, `"flvflags"`).
/// - `value`: The value to set (e.g., `"faststart"`, `"no_duration_filesize"`).
///
/// Returns the modified `Output` struct for chaining.
pub fn set_format_opt(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
if let Some(ref mut opts) = self.format_opts {
opts.insert(key.into(), value.into());
} else {
let mut opts = HashMap::new();
opts.insert(key.into(), value.into());
self.format_opts = Some(opts);
}
self
}
/// Sets multiple format-specific options at once.
///
/// This method allows setting multiple format options in a single call.
///
/// **Example Usage:**
/// ```rust,ignore
/// let output = Output::from("some_url")
/// .set_format_opts(vec![
/// ("movflags", "faststart"),
/// ("flvflags", "no_duration_filesize")
/// ]);
/// ```
///
/// **Parameters:**
/// - `opts`: A vector of key-value pairs representing format options.
///
/// Returns the modified `Output` struct for chaining.
pub fn set_format_opts(mut self, opts: Vec<(impl Into<String>, impl Into<String>)>) -> Self {
if let Some(ref mut format_opts) = self.format_opts {
for (key, value) in opts {
format_opts.insert(key.into(), value.into());
}
} else {
let mut format_opts = HashMap::new();
for (key, value) in opts {
format_opts.insert(key.into(), value.into());
}
self.format_opts = Some(format_opts);
}
self
}
}