rskit-media 0.2.0-alpha.3

Media types, codec/format registry, pipeline builder, and processing traits
Documentation
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//! Convenience constructors for well-known filters.

use super::{Filter, FilterTarget, Params};

// ── Video filters ────────────────────────────────────────────────

/// Noise reduction with configurable strength (0–10).
pub fn denoise(strength: u8) -> Filter {
    Filter {
        name: "denoise".into(),
        target: FilterTarget::Video,
        params: Params::new().set("strength", strength as i64),
    }
}

/// Sharpening with configurable amount.
pub fn sharpen(amount: f32) -> Filter {
    Filter {
        name: "sharpen".into(),
        target: FilterTarget::Video,
        params: Params::new().set("amount", amount as f64),
    }
}

/// Blur with configurable radius.
pub fn blur(radius: f32) -> Filter {
    Filter {
        name: "blur".into(),
        target: FilterTarget::Video,
        params: Params::new().set("radius", radius as f64),
    }
}

/// Brightness adjustment.
pub fn brightness(value: f32) -> Filter {
    Filter {
        name: "brightness".into(),
        target: FilterTarget::Video,
        params: Params::new().set("value", value as f64),
    }
}

/// Contrast adjustment.
pub fn contrast(value: f32) -> Filter {
    Filter {
        name: "contrast".into(),
        target: FilterTarget::Video,
        params: Params::new().set("value", value as f64),
    }
}

/// Saturation adjustment.
pub fn saturation(value: f32) -> Filter {
    Filter {
        name: "saturation".into(),
        target: FilterTarget::Video,
        params: Params::new().set("value", value as f64),
    }
}

/// Convert to grayscale.
pub fn grayscale() -> Filter {
    Filter {
        name: "grayscale".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Apply a sepia tone.
pub fn sepia() -> Filter {
    Filter {
        name: "sepia".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Video stabilization.
pub fn stabilize() -> Filter {
    Filter {
        name: "stabilize".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Deinterlacing.
pub fn deinterlace() -> Filter {
    Filter {
        name: "deinterlace".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Pass a raw FFmpeg video filter string.
pub fn custom_video(raw: impl Into<String>) -> Filter {
    Filter {
        name: raw.into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

// ── Audio filters ────────────────────────────────────────────────

/// High-pass filter at given frequency (Hz).
pub fn high_pass(freq_hz: u32) -> Filter {
    Filter {
        name: "high_pass".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("frequency", freq_hz as i64),
    }
}

/// Low-pass filter at given frequency (Hz).
pub fn low_pass(freq_hz: u32) -> Filter {
    Filter {
        name: "low_pass".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("frequency", freq_hz as i64),
    }
}

/// Parametric equalizer band.
pub fn equalizer(freq: u32, width: f32, gain: f32) -> Filter {
    Filter {
        name: "equalizer".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("frequency", freq as i64)
            .set("width", width as f64)
            .set("gain", gain as f64),
    }
}

/// Audio noise reduction.
pub fn noise_reduction(amount: f32) -> Filter {
    Filter {
        name: "noise_reduction".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("amount", amount as f64),
    }
}

/// Dynamic range compressor.
pub fn compressor(threshold: f32, ratio: f32) -> Filter {
    Filter {
        name: "compressor".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("threshold", threshold as f64)
            .set("ratio", ratio as f64),
    }
}

/// Pass a raw FFmpeg audio filter string.
pub fn custom_audio(raw: impl Into<String>) -> Filter {
    Filter {
        name: raw.into(),
        target: FilterTarget::Audio,
        params: Params::new(),
    }
}

// ── New video filters ────────────────────────────────────────────

/// Adjust gamma.
pub fn gamma(value: f32) -> Filter {
    Filter {
        name: "gamma".into(),
        target: FilterTarget::Video,
        params: Params::new().set("value", value as f64),
    }
}

/// Adjust hue by rotation angle (degrees).
pub fn hue(degrees: f32) -> Filter {
    Filter {
        name: "hue".into(),
        target: FilterTarget::Video,
        params: Params::new().set("degrees", degrees as f64),
    }
}

/// Invert/negate colors.
pub fn invert() -> Filter {
    Filter {
        name: "invert".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Video fade (in or out).
pub fn fade(fade_in: bool, start_secs: f32, duration_secs: f32) -> Filter {
    Filter {
        name: "fade".into(),
        target: FilterTarget::Video,
        params: Params::new()
            .set("type", if fade_in { "in" } else { "out" })
            .set("start", start_secs as f64)
            .set("duration", duration_secs as f64),
    }
}

/// Draw text overlay on video.
pub fn drawtext(text: impl Into<String>, fontsize: u32) -> Filter {
    Filter {
        name: "drawtext".into(),
        target: FilterTarget::Video,
        params: Params::new()
            .set("text", text.into())
            .set("fontsize", fontsize as i64),
    }
}

/// Draw a box on video.
pub fn drawbox(x: u32, y: u32, w: u32, h: u32, color: impl Into<String>) -> Filter {
    Filter {
        name: "drawbox".into(),
        target: FilterTarget::Video,
        params: Params::new()
            .set("x", x as i64)
            .set("y", y as i64)
            .set("w", w as i64)
            .set("h", h as i64)
            .set("color", color.into()),
    }
}

/// Chroma-key (green screen removal).
pub fn chromakey(color: impl Into<String>, similarity: f32, blend: f32) -> Filter {
    Filter {
        name: "chromakey".into(),
        target: FilterTarget::Video,
        params: Params::new()
            .set("color", color.into())
            .set("similarity", similarity as f64)
            .set("blend", blend as f64),
    }
}

/// Color-key removal.
pub fn colorkey(color: impl Into<String>, similarity: f32, blend: f32) -> Filter {
    Filter {
        name: "colorkey".into(),
        target: FilterTarget::Video,
        params: Params::new()
            .set("color", color.into())
            .set("similarity", similarity as f64)
            .set("blend", blend as f64),
    }
}

/// Apply a vignette effect.
pub fn vignette(angle: f32) -> Filter {
    Filter {
        name: "vignette".into(),
        target: FilterTarget::Video,
        params: Params::new().set("angle", angle as f64),
    }
}

/// Lens distortion correction.
pub fn lenscorrection(k1: f64, k2: f64) -> Filter {
    Filter {
        name: "lenscorrection".into(),
        target: FilterTarget::Video,
        params: Params::new().set("k1", k1).set("k2", k2),
    }
}

/// Apply a 3D LUT file.
pub fn lut3d(file: impl Into<String>) -> Filter {
    Filter {
        name: "lut3d".into(),
        target: FilterTarget::Video,
        params: Params::new().set("file", file.into()),
    }
}

/// Deshake (simple stabilization).
pub fn deshake() -> Filter {
    Filter {
        name: "deshake".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Change output frame rate.
pub fn fps(rate: u32) -> Filter {
    Filter {
        name: "fps".into(),
        target: FilterTarget::Video,
        params: Params::new().set("rate", rate as i64),
    }
}

/// Motion-interpolated frame rate conversion.
pub fn minterpolate(target_fps: u32) -> Filter {
    Filter {
        name: "minterpolate".into(),
        target: FilterTarget::Video,
        params: Params::new().set("fps", target_fps as i64),
    }
}

/// Color balance adjustment.
pub fn colorbalance(rs: f64, gs: f64, bs: f64) -> Filter {
    Filter {
        name: "colorbalance".into(),
        target: FilterTarget::Video,
        params: Params::new().set("rs", rs).set("gs", gs).set("bs", bs),
    }
}

/// Color curves preset.
pub fn curves(preset: impl Into<String>) -> Filter {
    Filter {
        name: "curves".into(),
        target: FilterTarget::Video,
        params: Params::new().set("preset", preset.into()),
    }
}

/// Normalize video levels.
pub fn normalize() -> Filter {
    Filter {
        name: "normalize".into(),
        target: FilterTarget::Video,
        params: Params::new(),
    }
}

/// Deflicker.
pub fn deflicker(size: u32) -> Filter {
    Filter {
        name: "deflicker".into(),
        target: FilterTarget::Video,
        params: Params::new().set("size", size as i64),
    }
}

// ── New audio filters ────────────────────────────────────────────

/// Audio limiter.
pub fn limiter(limit_db: f32) -> Filter {
    Filter {
        name: "limiter".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("limit", limit_db as f64),
    }
}

/// Audio noise gate.
pub fn gate(threshold_db: f32, ratio: f32) -> Filter {
    Filter {
        name: "gate".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("threshold", threshold_db as f64)
            .set("ratio", ratio as f64),
    }
}

/// EBU R128 loudness normalization with custom targets.
pub fn loudnorm(integrated: f64, true_peak: f64, lra: f64) -> Filter {
    Filter {
        name: "loudnorm".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("I", integrated)
            .set("TP", true_peak)
            .set("LRA", lra),
    }
}

/// Echo effect.
pub fn echo(in_gain: f64, out_gain: f64, delays_ms: f64, decays: f64) -> Filter {
    Filter {
        name: "echo".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("in_gain", in_gain)
            .set("out_gain", out_gain)
            .set("delays", delays_ms)
            .set("decays", decays),
    }
}

/// Audio delay (milliseconds).
pub fn delay(ms: u32) -> Filter {
    Filter {
        name: "delay".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("ms", ms as i64),
    }
}

/// Remove silence from audio.
pub fn silence_remove(threshold_db: impl Into<String>, min_duration: f64) -> Filter {
    Filter {
        name: "silenceremove".into(),
        target: FilterTarget::Audio,
        params: Params::new()
            .set("threshold", threshold_db.into())
            .set("duration", min_duration),
    }
}

/// Resample audio to a different sample rate.
pub fn aresample(rate: u32) -> Filter {
    Filter {
        name: "aresample".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("rate", rate as i64),
    }
}

/// Stereo balance adjustment (-1.0 left to 1.0 right).
pub fn stereo_balance(balance: f64) -> Filter {
    Filter {
        name: "stereotools".into(),
        target: FilterTarget::Audio,
        params: Params::new().set("balance", balance),
    }
}