rff-cli 0.3.9

Remade FFmpeg (Rust): the ffmpeg & ffprobe command-line front-ends.
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
//! FFmpeg-compatible argument parsing.
//!
//! FFmpeg's CLI is not a flat flag list — it's a small grammar:
//!
//! ```text
//!   ffmpeg [global opts] {[input opts] -i INPUT}... {[output opts] OUTPUT}...
//! ```
//!
//! Options can carry a *stream specifier* after a colon — `-c:v libx264` means
//! "codec, video stream". This module parses that grammar into a neutral
//! [`Cli`] and, for transcode invocations, builds an [`rff::transcode::TranscodeSpec`].
//!
//! This is a deliberately pragmatic subset: the common options people actually
//! type. Unknown options are skipped with a warning rather than aborting, and
//! the recognised set is easy to extend — add an arm to the match in [`parse`].

use std::path::PathBuf;

use rff::transcode::{InputSpec, MapSelector, MapSpec, OutputSpec, StreamCodec, TranscodeSpec};
use rff_core::{CodecId, Dictionary, MediaType};

/// Parse a `-map` value like `0`, `0:v`, `0:a`, or `0:2`.
fn parse_map(spec: &str) -> Option<MapSpec> {
    let mut parts = spec.split(':');
    let input: usize = parts.next()?.parse().ok()?;
    let selector = match parts.next() {
        None => MapSelector::All,
        Some("v") | Some("V") => MapSelector::Kind(MediaType::Video),
        Some("a") => MapSelector::Kind(MediaType::Audio),
        Some(idx) => MapSelector::Index(idx.parse().ok()?),
    };
    Some(MapSpec { input, selector })
}

/// What the user actually asked `ffmpeg` to do. Informational sub-commands
/// (`-version`, `-codecs`, ...) short-circuit a transcode.
pub enum Action {
    Version,
    Help,
    ListCodecs,
    ListFormats,
    Transcode(TranscodeSpec),
}

/// A fully parsed command line.
pub struct Cli {
    pub hide_banner: bool,
    pub loglevel: Option<String>,
    /// Non-fatal parse notes (unknown options, ignored values) to print to stderr.
    pub warnings: Vec<String>,
    pub action: Action,
}

/// Parse `args` (everything after the program name) into a [`Cli`].
///
/// Returns `Err` only for hard syntax errors (e.g. an option missing its
/// required value); soft problems become [`Cli::warnings`].
pub fn parse(args: &[String]) -> Result<Cli, String> {
    let mut hide_banner = false;
    let mut loglevel = None;
    let mut warnings = Vec::new();

    // Informational sub-commands win over a transcode if present.
    let mut action_override: Option<Action> = None;

    // --- transcode accumulators ---
    let mut inputs: Vec<InputSpec> = Vec::new();
    let mut pending_input_format: Option<String> = None;
    let mut out_format: Option<String> = None;
    let mut video_codec: Option<CodecId> = None;
    let mut audio_codec: Option<CodecId> = None;
    let mut subtitle_codec: Option<CodecId> = None;
    // Sample format pinned by the codec NAME (`-c:a pcm_s16le`) or by an
    // explicit `-sample_fmt`. Kept separate from the codec id, which is
    // format-agnostic by design.
    let mut audio_sample_format: Option<rff_core::SampleFormat> = None;
    let mut video_opts = Dictionary::new();
    let mut audio_opts = Dictionary::new();
    // Options given WITHOUT a `:v`/`:a` stream specifier that more than one
    // codec kind understands (FFmpeg treats `-compression_level` this way).
    // Held aside and attached after parsing, once we know which codecs actually
    // exist — attaching eagerly to both made every `-compression_level` on an
    // image encode emit a spurious "audio options given without -c:a" warning.
    let mut shared_opts = Dictionary::new();
    let mut max_video_frames: Option<u64> = None;
    let mut video_filters: Option<String> = None;
    let mut audio_filters: Option<String> = None;
    let mut filter_complex: Option<String> = None;
    let mut maps: Vec<MapSpec> = Vec::new();
    let mut overwrite = false;
    let mut output_path: Option<PathBuf> = None;
    // Trim window: -ss (start), -t (duration), -to (absolute end).
    let mut trim_start: Option<f64> = None;
    let mut trim_duration: Option<f64> = None;
    let mut trim_to: Option<f64> = None;
    let mut frame_rate: Option<(u32, u32)> = None;
    let mut audio_rate: Option<u32> = None;
    let mut audio_channels: Option<u16> = None;
    let mut metadata = Dictionary::new();
    let mut format_options = Dictionary::new();

    let mut i = 0;
    while i < args.len() {
        let arg = &args[i];

        // A bare `-` is stdout (FFmpeg's pipe spelling), not an option.
        let Some(opt) = arg.strip_prefix('-').filter(|_| arg != "-") else {
            // A bare token is a positional argument: the output file.
            if output_path.is_some() {
                warnings.push(format!(
                    "multiple output files given; using the last (`{arg}`)"
                ));
            }
            output_path = Some(PathBuf::from(arg));
            i += 1;
            continue;
        };

        // Split an option into its base name and optional stream specifier:
        // `c:v:0` -> ("c", Some("v:0")).
        let (base, spec) = match opt.split_once(':') {
            Some((b, s)) => (b, Some(s)),
            None => (opt, None),
        };

        match base {
            "version" => action_override = Some(Action::Version),
            "h" | "help" | "?" => action_override = Some(Action::Help),
            "codecs" | "encoders" | "decoders" => action_override = Some(Action::ListCodecs),
            "formats" | "muxers" | "demuxers" => action_override = Some(Action::ListFormats),
            "hide_banner" => hide_banner = true,
            "y" => overwrite = true,
            "n" => overwrite = false,
            "loglevel" | "v" => loglevel = Some(take_value(args, &mut i, arg)?),

            "i" => {
                let path = take_value(args, &mut i, arg)?;
                inputs.push(InputSpec {
                    path: PathBuf::from(path),
                    format: pending_input_format.take(),
                });
            }

            // `-f` applies to the next input if we haven't reached outputs yet,
            // otherwise to the output.
            "f" => {
                let fmt = take_value(args, &mut i, arg)?;
                if inputs.is_empty() {
                    pending_input_format = Some(fmt);
                } else {
                    out_format = Some(fmt);
                }
            }

            // Codec selection: -c / -codec (optionally :v / :a), and the legacy
            // -vcodec / -acodec aliases.
            "c" | "codec" => {
                let name = take_value(args, &mut i, arg)?;
                apply_codec(
                    spec,
                    &name,
                    &mut video_codec,
                    &mut audio_codec,
                    &mut subtitle_codec,
                    &mut audio_sample_format,
                    &mut warnings,
                );
            }
            "vcodec" => {
                let name = take_value(args, &mut i, arg)?;
                apply_codec(
                    Some("v"),
                    &name,
                    &mut video_codec,
                    &mut audio_codec,
                    &mut subtitle_codec,
                    &mut audio_sample_format,
                    &mut warnings,
                );
            }
            "acodec" => {
                let name = take_value(args, &mut i, arg)?;
                apply_codec(
                    Some("a"),
                    &name,
                    &mut video_codec,
                    &mut audio_codec,
                    &mut subtitle_codec,
                    &mut audio_sample_format,
                    &mut warnings,
                );
            }
            "scodec" => {
                let name = take_value(args, &mut i, arg)?;
                apply_codec(
                    Some("s"),
                    &name,
                    &mut video_codec,
                    &mut audio_codec,
                    &mut subtitle_codec,
                    &mut audio_sample_format,
                    &mut warnings,
                );
            }

            // Stream selection: -map INPUT[:v|:a|:N] (repeatable).
            "map" => {
                let value = take_value(args, &mut i, arg)?;
                match parse_map(&value) {
                    Some(m) => maps.push(m),
                    None => warnings.push(format!("ignoring invalid -map `{value}`")),
                }
            }

            // Video filter graph: -vf / -filter:v. Audio: -af / -filter:a.
            "vf" => video_filters = Some(take_value(args, &mut i, arg)?),
            "af" => audio_filters = Some(take_value(args, &mut i, arg)?),
            // Multi-input filter graph: -filter_complex / -lavfi.
            "filter_complex" | "lavfi" => filter_complex = Some(take_value(args, &mut i, arg)?),
            "filter" => {
                let value = take_value(args, &mut i, arg)?;
                match spec {
                    Some(s) if s.starts_with('v') => video_filters = Some(value),
                    Some(s) if s.starts_with('a') => audio_filters = Some(value),
                    _ => warnings.push(format!("ignoring filter spec `{value}`")),
                }
            }

            // Trim window: -ss START, -t DURATION, -to END (`HH:MM:SS.mmm` or
            // seconds). Applied to the output: decode-and-discard, so it is
            // frame-accurate for transcodes and keyframe-cut for -c copy.
            "ss" => trim_start = Some(parse_time(&take_value(args, &mut i, arg)?)?),
            "t" => trim_duration = Some(parse_time(&take_value(args, &mut i, arg)?)?),
            "to" => trim_to = Some(parse_time(&take_value(args, &mut i, arg)?)?),

            // -r RATE: constant output frame rate (25, 29.97, 30000/1001).
            "r" | "framerate" => frame_rate = Some(parse_rate(&take_value(args, &mut i, arg)?)?),

            // -s WxH: shorthand for a trailing scale filter.
            "s" | "video_size" => {
                let value = take_value(args, &mut i, arg)?;
                let (w, h) = value
                    .split_once(['x', 'X'])
                    .and_then(|(w, h)| Some((w.parse::<u32>().ok()?, h.parse::<u32>().ok()?)))
                    .ok_or_else(|| format!("-s: expected WxH, got `{value}`"))?;
                let scale = format!("scale={w}:{h}");
                video_filters = Some(match video_filters.take() {
                    Some(chain) => format!("{chain},{scale}"),
                    None => scale,
                });
            }

            // -ar RATE / -ac CHANNELS: audio output rate and channel count.
            "ar" => {
                let value = take_value(args, &mut i, arg)?;
                audio_rate = Some(
                    value
                        .parse()
                        .map_err(|_| format!("-ar: bad sample rate `{value}`"))?,
                );
            }
            "ac" => {
                let value = take_value(args, &mut i, arg)?;
                audio_channels = Some(
                    value
                        .parse()
                        .map_err(|_| format!("-ac: bad channel count `{value}`"))?,
                );
            }

            // HLS segmenting: -hls_time SECONDS. (-hls_list_size shapes LIVE
            // sliding-window playlists; our HLS output is VOD, so say so.)
            "hls_time" => {
                let value = take_value(args, &mut i, arg)?;
                format_options.set("hls_time", value);
            }
            // DASH segmenting: -seg_duration SECONDS (FFmpeg's dash option).
            "seg_duration" => {
                let value = take_value(args, &mut i, arg)?;
                format_options.set("seg_duration", value);
            }
            "hls_list_size" => {
                let _ = take_value(args, &mut i, arg)?;
                warnings.push("-hls_list_size: HLS output is a VOD playlist; ignored".into());
            }

            // -metadata key=value (repeatable).
            "metadata" => {
                let value = take_value(args, &mut i, arg)?;
                match value.split_once('=') {
                    Some((k, v)) => metadata.set(k.trim(), v),
                    None => warnings.push(format!("-metadata: expected key=value, got `{value}`")),
                }
            }

            // Bitrate: -b:v / -b:a (bare -b defaults to video).
            "b" => {
                let value = take_value(args, &mut i, arg)?;
                match spec {
                    Some(s) if s.starts_with('a') => audio_opts.set("b", value),
                    _ => video_opts.set("b", value),
                }
            }

            // Rate control / tuning (video by default; `:a` targets audio):
            // -crf / -qp / -q / -qscale (quality), -preset (speed<->quality), -pass (1|2),
            // -cpu-used / -speed (VP9 speed preset 0 best..4 fastest),
            // -profile (h264: baseline|main|high), -g (keyframe interval).
            // `-frames:v N` / `-frames N` — stop after N video frames. Needed for
            // any rate-vs-quality measurement over a clip prefix: without it a
            // harness silently encodes the whole input while scoring a prefix.
            "frames" | "vframes" => {
                let value = take_value(args, &mut i, arg)?;
                match value.parse::<u64>() {
                    Ok(n) => max_video_frames = Some(n),
                    Err(_) => warnings.push(format!("ignoring non-numeric -{arg} {value}")),
                }
            }

            // JPEG/MJPEG private options default to video (an image codec has no
            // audio side): -jpeg_quality 1..100, -sampling 444|440|422|420|411,
            // -progressive, -optimize_huffman, -restart_interval, -trellis.
            // `-pred` is PNG's filter/prediction knob (none/sub/up/avg/paeth/
            // mixed), spelled as FFmpeg's PNG encoder spells it. It is video-only
            // by nature — there is no audio codec that takes it.
            "crf" | "qp" | "preset" | "profile" | "g" | "pass" | "q" | "qscale" | "cpu-used"
            | "speed" | "lag" | "lag-in-frames" | "arnr-strength" | "dispatch-budget"
            | "jpeg_quality" | "sampling" | "jpeg_sampling" | "progressive"
            | "optimize_huffman" | "restart_interval" | "trellis" | "pred" | "png_auto_type"
            | "png_auto_config" => {
                let value = take_value(args, &mut i, arg)?;
                if base == "pass" && value != "1" {
                    warnings
                        .push("two-pass (-pass 2) is parsed but runs single-pass for now".into());
                }
                match spec {
                    Some(s) if s.starts_with('a') => audio_opts.set(base, value),
                    _ => video_opts.set(base, value),
                }
            }

            // `-compression_level` is not audio-only: FFmpeg treats it as a
            // generic codec option, and PNG uses it (0..9) exactly as Opus does
            // (0..10). Unscoped it therefore has to reach BOTH dictionaries, or
            // `rff -i in.png -c:v png -compression_level 9 out.png` silently
            // encodes at the default — which is what it used to do. `:v` / `:a`
            // still target one side.
            "compression_level" | "threads" => {
                let value = take_value(args, &mut i, arg)?;
                match spec {
                    Some(s) if s.starts_with('v') => video_opts.set(base, value),
                    Some(s) if s.starts_with('a') => audio_opts.set(base, value),
                    _ => shared_opts.set(base, value),
                }
            }

            // Codec private / tuning options forwarded to the encoder's
            // `configure` Dictionary (audio by default; `:v` targets video).
            // Includes Opus: -application, -vbr, and the R1 frame-parallel
            // controls -opus_parallel / -opus_warmup / -threads.
            "application" | "vbr" | "opus_parallel" | "opus_warmup" | "frame_duration" => {
                let value = take_value(args, &mut i, arg)?;
                match spec {
                    Some(s) if s.starts_with('v') => video_opts.set(base, value),
                    _ => audio_opts.set(base, value),
                }
            }

            // Anything else: accept gracefully. Best-effort consume a trailing
            // value so we don't mistake it for the output path.
            _ => {
                warnings.push(format!("unrecognized option `-{opt}` (ignored)"));
                if let Some(next) = args.get(i + 1) {
                    if !next.starts_with('-') {
                        i += 1;
                    }
                }
            }
        }

        i += 1;
    }

    if let Some(action) = action_override {
        return Ok(Cli {
            hide_banner,
            loglevel,
            warnings,
            action,
        });
    }

    // Attach the unscoped shared options to whichever codecs are actually
    // present. An explicit `:v`/`:a` value already set above wins over these.
    for (key, value) in shared_opts.iter() {
        if video_codec.is_some() && video_opts.get(key).is_none() {
            video_opts.set(key, value);
        }
        if audio_codec.is_some() && audio_opts.get(key).is_none() {
            audio_opts.set(key, value);
        }
    }

    // Warn about codec options that have no codec to attach to.
    if !video_opts.is_empty() && video_codec.is_none() {
        warnings.push("video options given without -c:v; ignored".into());
    }
    if !audio_opts.is_empty() && audio_codec.is_none() {
        warnings.push("audio options given without -c:a; ignored".into());
    }
    // Re-encode-only options on a stream-copy: say so instead of silence.
    if audio_codec.is_none()
        && (audio_filters.is_some() || audio_rate.is_some() || audio_channels.is_some())
    {
        warnings.push("-af/-ar/-ac need a re-encode; pass -c:a (ignored on stream copy)".into());
    }

    // `-vf fps=N` is the same CFR stage as `-r`: lift it out of the chain.
    if let Some(vf) = &video_filters {
        let mut kept: Vec<&str> = Vec::new();
        for token in vf.split(',') {
            match token.trim().strip_prefix("fps=") {
                Some(rate) => match parse_rate(rate) {
                    Ok(r) => frame_rate = Some(r),
                    Err(e) => warnings.push(e),
                },
                None => kept.push(token),
            }
        }
        if kept.len() != vf.split(',').count() {
            let kept = kept.join(",");
            video_filters = (!kept.trim().is_empty()).then_some(kept);
        }
    }
    if frame_rate.is_some() && video_codec.is_none() {
        warnings.push("-r/-vf fps= need a re-encode; pass -c:v (ignored on stream copy)".into());
    }

    // -ss/-t/-to resolve to an absolute [start, end) window; -to wins over -t
    // only when both name the same bound (FFmpeg takes the earlier end).
    let trim_end = match (trim_to, trim_duration) {
        (Some(to), Some(t)) => Some(to.min(trim_start.unwrap_or(0.0) + t)),
        (Some(to), None) => Some(to),
        (None, Some(t)) => Some(trim_start.unwrap_or(0.0) + t),
        (None, None) => None,
    };

    let output = output_path.map(|path| OutputSpec {
        path,
        format: out_format,
        video_codec: video_codec.map(|codec| StreamCodec {
            codec,
            options: video_opts,
            sample_format: None,
        }),
        audio_codec: audio_codec.map(|codec| StreamCodec {
            codec,
            options: audio_opts,
            sample_format: audio_sample_format,
        }),
        subtitle_codec,
        video_filters,
        filter_complex,
        max_video_frames,
        maps,
        overwrite,
        trim_start,
        trim_end,
        frame_rate,
        audio_rate,
        audio_channels,
        audio_filters,
        metadata,
        format_options,
    });

    let spec = TranscodeSpec {
        inputs,
        outputs: output.into_iter().collect(),
    };

    Ok(Cli {
        hide_banner,
        loglevel,
        warnings,
        action: Action::Transcode(spec),
    })
}

/// Consume and return the value following an option, advancing the cursor.
fn take_value(args: &[String], i: &mut usize, opt: &str) -> Result<String, String> {
    *i += 1;
    args.get(*i)
        .cloned()
        .ok_or_else(|| format!("option `{opt}` requires an argument"))
}

/// Parse an FFmpeg time value: plain seconds (`12.5`) or `[HH:]MM:SS[.mmm]`.
fn parse_time(value: &str) -> Result<f64, String> {
    let value = value.trim();
    let bad = || format!("bad time `{value}` (want seconds or [HH:]MM:SS[.mmm])");
    if !value.contains(':') {
        return value.parse::<f64>().map_err(|_| bad());
    }
    let parts: Vec<&str> = value.split(':').collect();
    if parts.len() > 3 || parts.is_empty() {
        return Err(bad());
    }
    let mut seconds = 0.0;
    for p in &parts {
        seconds = seconds * 60.0 + p.parse::<f64>().map_err(|_| bad())?;
    }
    Ok(seconds)
}

/// Parse a frame rate: integer (`25`), decimal (`29.97`), or fraction
/// (`30000/1001`). Decimals become exact fractions over a power of ten.
fn parse_rate(value: &str) -> Result<(u32, u32), String> {
    let value = value.trim();
    let bad = || format!("bad frame rate `{value}`");
    if let Some((n, d)) = value.split_once('/') {
        let (n, d) = (
            n.trim().parse::<u32>().map_err(|_| bad())?,
            d.trim().parse::<u32>().map_err(|_| bad())?,
        );
        if n == 0 || d == 0 {
            return Err(bad());
        }
        return Ok((n, d));
    }
    if let Some((int, frac)) = value.split_once('.') {
        let digits = frac.len().min(3) as u32;
        let den = 10u32.pow(digits);
        let int: u32 = int.parse().map_err(|_| bad())?;
        let frac: u32 = frac[..digits as usize].parse().map_err(|_| bad())?;
        let num = int * den + frac;
        if num == 0 {
            return Err(bad());
        }
        return Ok((num, den));
    }
    let n: u32 = value.parse().map_err(|_| bad())?;
    if n == 0 {
        return Err(bad());
    }
    Ok((n, 1))
}

/// Resolve a codec name to an id (treating `copy` as "no re-encode" → `None`)
/// and assign it to the slot selected by the stream specifier.
#[allow(clippy::too_many_arguments)]
fn apply_codec(
    spec: Option<&str>,
    name: &str,
    video: &mut Option<CodecId>,
    audio: &mut Option<CodecId>,
    subtitle: &mut Option<CodecId>,
    audio_format: &mut Option<rff_core::SampleFormat>,
    warnings: &mut Vec<String>,
) {
    if name == "copy" {
        // Stream copy: leave the slot unset; the pipeline will passthrough.
        return;
    }
    let Some(id) = CodecId::from_name(name) else {
        warnings.push(format!("unknown codec `{name}` (ignored)"));
        return;
    };
    // `pcm_s16le` vs `pcm_f32le` differ only in the name; keep what it pins.
    let pinned = CodecId::sample_format_from_name(name);
    match spec {
        Some(s) if s.starts_with('v') => *video = Some(id),
        Some(s) if s.starts_with('a') => {
            *audio = Some(id);
            if pinned.is_some() {
                *audio_format = pinned;
            }
        }
        Some(s) if s.starts_with('s') => match id.media_type() {
            rff_core::MediaType::Subtitle => *subtitle = Some(id),
            _ => warnings.push(format!("-c:s: `{name}` is not a subtitle codec (ignored)")),
        },
        // No specifier: apply to whichever media type this codec is.
        None => match id.media_type() {
            rff_core::MediaType::Video => *video = Some(id),
            rff_core::MediaType::Audio => {
                *audio = Some(id);
                if pinned.is_some() {
                    *audio_format = pinned;
                }
            }
            rff_core::MediaType::Subtitle => *subtitle = Some(id),
            _ => {}
        },
        _ => {}
    }
}