ff-probe 0.14.2

Media file metadata extraction - the Rust way
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
//! Integration tests for ff-probe using real media files.
//!
//! These tests verify that ff-probe correctly extracts metadata from
//! actual media files in the assets directory.
//!
//! # Temporary file cleanup
//!
//! These tests are read-only: they call `ff_probe::open()` to inspect existing
//! media files and do not produce any temporary output files. No
//! `fixtures/mod.rs` with `FileGuard`/`DirGuard` is needed.

use std::path::PathBuf;
use std::time::Duration;

use ff_format::PixelFormat;
use ff_format::channel::ChannelLayout;
use ff_format::codec::{AudioCodec, VideoCodec};
use ff_probe::open;

// ============================================================================
// Test Helpers
// ============================================================================

/// Returns the path to the test assets directory.
fn assets_dir() -> PathBuf {
    let manifest_dir = env!("CARGO_MANIFEST_DIR");
    PathBuf::from(format!("{}/../../assets", manifest_dir))
}

/// Returns the path to the test video file.
fn test_video_path() -> PathBuf {
    assets_dir().join("video/gameplay.mp4")
}

/// Returns the path to the test audio file.
fn test_audio_path() -> PathBuf {
    assets_dir().join("audio/konekonoosanpo.mp3")
}

// ============================================================================
// Video File Integration Tests
// ============================================================================

#[test]
fn test_probe_video_file_opens_successfully() {
    let path = test_video_path();
    let result = open(&path);

    assert!(
        result.is_ok(),
        "Failed to open video file: {:?}",
        result.err()
    );
}

#[test]
fn test_probe_video_file_has_correct_format() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // MP4 files should be detected as mov,mp4,m4a,3gp,3g2,mj2 format
    assert!(
        info.format().contains("mp4") || info.format().contains("mov"),
        "Expected mp4/mov format, got: {}",
        info.format()
    );
}

#[test]
fn test_probe_video_file_has_video_stream() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    assert!(info.has_video(), "Video file should have video stream");
    assert!(
        !info.video_streams().is_empty(),
        "Video streams should not be empty"
    );
}

#[test]
fn test_probe_video_file_video_stream_properties() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Verify video stream has valid properties
    assert!(video.width() > 0, "Video width should be positive");
    assert!(video.height() > 0, "Video height should be positive");

    // Common video codecs
    let valid_codecs = [
        VideoCodec::H264,
        VideoCodec::H265,
        VideoCodec::Vp9,
        VideoCodec::Av1,
    ];
    assert!(
        valid_codecs.contains(&video.codec()) || video.codec() == VideoCodec::Unknown,
        "Video codec should be a known codec or Unknown"
    );

    // Verify pixel format is set
    assert!(
        !matches!(video.pixel_format(), PixelFormat::Other(_)),
        "Pixel format should be a known format"
    );

    // Frame rate should be positive
    assert!(video.fps() > 0.0, "Frame rate should be positive");
}

#[test]
fn test_probe_video_file_has_audio_stream() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Video file may or may not have audio
    if info.has_audio() {
        let audio = info
            .primary_audio()
            .expect("Should have primary audio stream");

        // Verify audio stream has valid properties
        assert!(audio.sample_rate() > 0, "Sample rate should be positive");
        assert!(audio.channels() > 0, "Channel count should be positive");
    }
}

#[test]
fn test_probe_video_file_duration() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Duration should be positive
    assert!(
        info.duration() > Duration::ZERO,
        "Duration should be positive"
    );

    // Duration should be reasonable (less than 1 hour for test files)
    assert!(
        info.duration() < Duration::from_secs(3600),
        "Duration seems unreasonably long for a test file"
    );
}

#[test]
fn test_probe_video_file_size() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // File size should be positive
    assert!(info.file_size() > 0, "File size should be positive");
}

#[test]
fn test_probe_video_file_path() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Path should match
    assert_eq!(info.path(), path);

    // File name should be correct
    assert_eq!(info.file_name(), Some("gameplay.mp4"));

    // Extension should be mp4
    assert_eq!(info.extension(), Some("mp4"));
}

// ============================================================================
// Audio File Integration Tests
// ============================================================================

#[test]
fn test_probe_audio_file_opens_successfully() {
    let path = test_audio_path();
    let result = open(&path);

    assert!(
        result.is_ok(),
        "Failed to open audio file: {:?}",
        result.err()
    );
}

#[test]
fn test_probe_audio_file_has_correct_format() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // MP3 files should be detected as mp3 format
    assert!(
        info.format().contains("mp3"),
        "Expected mp3 format, got: {}",
        info.format()
    );
}

#[test]
fn test_probe_audio_file_has_audio_stream() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    assert!(info.has_audio(), "Audio file should have audio stream");
    assert!(
        !info.audio_streams().is_empty(),
        "Audio streams should not be empty"
    );
}

#[test]
fn test_probe_audio_file_no_video_stream() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    assert!(
        !info.has_video(),
        "Audio-only file should not have video stream"
    );
    assert!(
        info.video_streams().is_empty(),
        "Video streams should be empty"
    );
}

#[test]
fn test_probe_audio_file_audio_stream_properties() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    let audio = info
        .primary_audio()
        .expect("Should have primary audio stream");

    // Verify audio codec is MP3
    assert_eq!(audio.codec(), AudioCodec::Mp3, "Audio codec should be MP3");

    // Verify sample rate is a common value
    let common_sample_rates = [8000, 11025, 22050, 44100, 48000, 96000];
    assert!(
        common_sample_rates.contains(&audio.sample_rate()),
        "Sample rate {} should be a common value",
        audio.sample_rate()
    );

    // Verify channel count is reasonable (1 = mono, 2 = stereo, etc.)
    assert!(
        audio.channels() >= 1 && audio.channels() <= 8,
        "Channel count {} should be between 1 and 8",
        audio.channels()
    );

    // Verify channel layout matches channel count
    let expected_layouts = match audio.channels() {
        1 => vec![ChannelLayout::Mono],
        2 => vec![ChannelLayout::Stereo],
        _ => vec![],
    };
    if !expected_layouts.is_empty() {
        assert!(
            expected_layouts.contains(&audio.channel_layout()),
            "Channel layout {:?} should match channel count {}",
            audio.channel_layout(),
            audio.channels()
        );
    }
}

#[test]
fn test_probe_audio_file_sample_format() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    let audio = info
        .primary_audio()
        .expect("Should have primary audio stream");

    // MP3 typically decodes to planar float format
    let sample_format = audio.sample_format();
    assert!(
        sample_format.is_float() || sample_format.is_integer(),
        "Sample format should be float or integer"
    );
}

#[test]
fn test_probe_audio_file_duration() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Duration should be positive
    assert!(
        info.duration() > Duration::ZERO,
        "Duration should be positive"
    );

    // Duration should be reasonable for a test file
    assert!(
        info.duration() < Duration::from_secs(600),
        "Duration seems unreasonably long for a test file"
    );
}

#[test]
fn test_probe_audio_file_path() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Path should match
    assert_eq!(info.path(), path);

    // File name should be correct
    assert_eq!(info.file_name(), Some("konekonoosanpo.mp3"));

    // Extension should be mp3
    assert_eq!(info.extension(), Some("mp3"));
}

// ============================================================================
// Error Handling Integration Tests
// ============================================================================

#[test]
fn test_probe_nonexistent_file() {
    let path = assets_dir().join("nonexistent-file.mp4");
    let result = open(&path);

    assert!(result.is_err(), "Opening nonexistent file should fail");
}

#[test]
fn test_probe_invalid_file() {
    // Try to open a non-media file (image)
    let path = assets_dir().join("img/hello-triangle.png");
    let result = open(&path);

    // PNG files might be opened by FFmpeg as image format or might fail
    // Either behavior is acceptable for this test
    if let Ok(info) = result {
        // If it opens, it should have some format info
        assert!(!info.format().is_empty(), "Format should not be empty");
    }
}

// ============================================================================
// Stream Count Tests
// ============================================================================

#[test]
fn test_probe_video_file_stream_counts() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Should have at least one video stream
    assert!(
        info.video_stream_count() >= 1,
        "Should have at least 1 video stream"
    );

    // Total stream count should be at least 1
    let total = info.video_stream_count() + info.audio_stream_count();
    assert!(total >= 1, "Should have at least 1 stream");
}

#[test]
fn test_probe_audio_file_stream_counts() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Should have exactly one audio stream
    assert_eq!(
        info.audio_stream_count(),
        1,
        "Should have exactly 1 audio stream"
    );

    // Should have no video streams
    assert_eq!(info.video_stream_count(), 0, "Should have 0 video streams");
}

// ============================================================================
// Resolution and Aspect Ratio Tests
// ============================================================================

#[test]
fn test_probe_video_resolution() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Should have resolution information
    let resolution = info.resolution();
    assert!(resolution.is_some(), "Video file should have resolution");

    let (width, height) = resolution.unwrap();
    assert!(width > 0 && height > 0, "Resolution should be positive");

    // Common resolutions have reasonable aspect ratios
    let aspect = width as f64 / height as f64;
    assert!(
        aspect > 0.5 && aspect < 3.0,
        "Aspect ratio {} seems unusual",
        aspect
    );
}

#[test]
fn test_probe_video_frame_rate() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Should have frame rate information
    let frame_rate = info.frame_rate();
    assert!(frame_rate.is_some(), "Video file should have frame rate");

    let fps_value = frame_rate.unwrap();

    // Common frame rates: 23.976, 24, 25, 29.97, 30, 50, 59.94, 60
    assert!(
        fps_value > 10.0 && fps_value < 120.0,
        "Frame rate {} seems unusual",
        fps_value
    );
}

// ============================================================================
// Audio Properties Tests
// ============================================================================

#[test]
fn test_probe_audio_sample_rate() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Should have sample rate information
    let sample_rate = info.sample_rate();
    assert!(sample_rate.is_some(), "Audio file should have sample rate");

    let rate = sample_rate.unwrap();
    assert!(
        rate >= 8000 && rate <= 192000,
        "Sample rate {} seems unusual",
        rate
    );
}

#[test]
fn test_probe_audio_channels() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Should have channel count information
    let channels = info.channels();
    assert!(channels.is_some(), "Audio file should have channel count");

    let ch = channels.unwrap();
    assert!(ch >= 1 && ch <= 8, "Channel count {} seems unusual", ch);
}

// ============================================================================
// Metadata Extraction Tests
// ============================================================================

#[test]
fn test_probe_video_file_metadata_accessible() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Metadata should be accessible (may be empty for some files)
    // Just verify we can get the metadata without panicking
    let _metadata = info.metadata();

    // Test that convenience methods work without panicking
    let _ = info.title();
    let _ = info.artist();
    let _ = info.album();
    let _ = info.creation_time();
    let _ = info.date();
    let _ = info.comment();
    let _ = info.encoder();
}

#[test]
fn test_probe_audio_file_metadata_accessible() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Metadata should be accessible (may be empty for some files)
    // Just verify we can get the metadata without panicking
    let _metadata = info.metadata();

    // MP3 files often have ID3 tags with title, artist, etc.
    // Just verify the methods don't panic
    let _ = info.title();
    let _ = info.artist();
    let _ = info.album();
    let _ = info.date();
}

#[test]
fn test_probe_video_file_metadata_keys() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Test that we can iterate over metadata
    for (key, _value) in info.metadata() {
        // Keys should be non-empty strings
        assert!(!key.is_empty(), "Metadata key should not be empty");
        // Value can be empty (valid empty string) - just ensure iteration works
    }
}

#[test]
fn test_probe_audio_file_metadata_keys() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Test that we can iterate over metadata
    for (key, _value) in info.metadata() {
        // Keys should be non-empty strings
        assert!(!key.is_empty(), "Metadata key should not be empty");
        // Value can be empty (valid empty string) - just ensure iteration works
    }
}

// ============================================================================
// Color Space Extraction Tests
// ============================================================================

#[test]
fn test_probe_video_color_space_extraction() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Verify color space is extracted (may be Unknown for some files)
    let color_space = video.color_space();
    // Valid color spaces: BT.709 (HD), BT.601 (SD), BT.2020 (HDR), sRGB, or Unknown
    let valid_spaces = [
        ff_format::color::ColorSpace::Bt709,
        ff_format::color::ColorSpace::Bt601,
        ff_format::color::ColorSpace::Bt2020,
        ff_format::color::ColorSpace::Srgb,
        ff_format::color::ColorSpace::Unknown,
    ];
    assert!(
        valid_spaces.contains(&color_space),
        "Color space {:?} should be a valid value",
        color_space
    );
}

#[test]
fn test_probe_video_color_range_extraction() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Verify color range is extracted
    let color_range = video.color_range();
    // Valid color ranges: Limited (TV), Full (PC), or Unknown
    let valid_ranges = [
        ff_format::color::ColorRange::Limited,
        ff_format::color::ColorRange::Full,
        ff_format::color::ColorRange::Unknown,
    ];
    assert!(
        valid_ranges.contains(&color_range),
        "Color range {:?} should be a valid value",
        color_range
    );
}

#[test]
fn test_probe_video_color_primaries_extraction() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Verify color primaries are extracted
    let color_primaries = video.color_primaries();
    // Valid color primaries: BT.709, BT.601, BT.2020, or Unknown
    let valid_primaries = [
        ff_format::color::ColorPrimaries::Bt709,
        ff_format::color::ColorPrimaries::Bt601,
        ff_format::color::ColorPrimaries::Bt2020,
        ff_format::color::ColorPrimaries::Unknown,
    ];
    assert!(
        valid_primaries.contains(&color_primaries),
        "Color primaries {:?} should be a valid value",
        color_primaries
    );
}

#[test]
fn test_probe_video_color_info_consistency() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // If color space is HD (BT.709), primaries should typically also be BT.709
    let color_space = video.color_space();
    let color_primaries = video.color_primaries();

    // Check for common consistency patterns (not strictly required, but good practice)
    // Note: Some encoders may not set all color parameters consistently
    if color_space == ff_format::color::ColorSpace::Bt2020 {
        // HDR content should have BT.2020 primaries
        // (or Unknown if encoder didn't set it)
        assert!(
            color_primaries == ff_format::color::ColorPrimaries::Bt2020
                || color_primaries == ff_format::color::ColorPrimaries::Unknown,
            "BT.2020 color space should have BT.2020 or Unknown primaries, got {:?}",
            color_primaries
        );
    }
}

#[test]
fn test_probe_video_hdr_detection() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Check for HDR indicators
    let color_space = video.color_space();
    let color_primaries = video.color_primaries();

    // HDR content is indicated by BT.2020 color space or primaries
    let is_hdr = color_space == ff_format::color::ColorSpace::Bt2020
        || color_primaries == ff_format::color::ColorPrimaries::Bt2020;

    // For test files, we don't require HDR, just verify detection works
    // If HDR is detected, log it for manual verification
    if is_hdr {
        println!("HDR content detected in test file");
    }

    // The test passes regardless - we're just verifying the detection logic runs
    assert!(true, "HDR detection completed successfully");
}

// ============================================================================
// Bitrate Extraction Tests
// ============================================================================

#[test]
fn test_probe_video_file_bitrate() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Container bitrate should be available (either from FFmpeg or calculated)
    let bitrate = info.bitrate();
    assert!(
        bitrate.is_some(),
        "Video file should have container bitrate"
    );

    // Verify bitrate is within reasonable range (1 kbps to 100 Mbps)
    let bps = bitrate.unwrap();
    assert!(
        bps > 1_000 && bps < 100_000_000,
        "Bitrate {} bps seems unreasonable (expected 1 kbps - 100 Mbps)",
        bps
    );
}

#[test]
fn test_probe_audio_file_bitrate() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    // Container bitrate should be available (either from FFmpeg or calculated)
    let bitrate = info.bitrate();
    assert!(
        bitrate.is_some(),
        "Audio file should have container bitrate"
    );

    // Verify bitrate is within reasonable range for audio (8 kbps to 10 Mbps)
    let bps = bitrate.unwrap();
    assert!(
        bps > 8_000 && bps < 10_000_000,
        "Audio bitrate {} bps seems unreasonable (expected 8 kbps - 10 Mbps)",
        bps
    );
}

#[test]
fn test_probe_video_stream_bitrate() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    let video = info
        .primary_video()
        .expect("Should have primary video stream");

    // Video stream bitrate may or may not be available depending on the container
    // If available, it should be within reasonable bounds
    if let Some(bps) = video.bitrate() {
        assert!(
            bps > 1_000 && bps < 100_000_000,
            "Video stream bitrate {} bps seems unreasonable",
            bps
        );
    }
}

#[test]
fn test_probe_audio_stream_bitrate() {
    let path = test_audio_path();
    let info = open(&path).expect("Failed to open audio file");

    let audio = info
        .primary_audio()
        .expect("Should have primary audio stream");

    // Audio stream bitrate may or may not be available depending on the container
    // If available, it should be within reasonable bounds
    if let Some(bps) = audio.bitrate() {
        assert!(
            bps > 1_000 && bps < 10_000_000,
            "Audio stream bitrate {} bps seems unreasonable",
            bps
        );
    }
}

#[test]
fn test_probe_bitrate_consistency() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    // Verify bitrate is consistent with file size and duration
    let file_size = info.file_size();
    let duration = info.duration();
    let bitrate = info.bitrate();

    if let Some(bps) = bitrate {
        // Calculate expected bitrate from file size and duration
        let duration_secs = duration.as_secs_f64();
        if duration_secs > 0.0 {
            #[allow(clippy::cast_precision_loss)]
            let calculated_bps = (file_size as f64 * 8.0 / duration_secs) as u64;

            // Allow 20% tolerance for container overhead and rounding
            let min_expected = calculated_bps * 80 / 100;
            let max_expected = calculated_bps * 120 / 100;

            assert!(
                bps >= min_expected && bps <= max_expected,
                "Bitrate {} should be close to calculated value {} (within 20%)",
                bps,
                calculated_bps
            );
        }
    }
}

// ============================================================================
// Subtitle Stream Tests
// ============================================================================

#[test]
fn test_probe_video_file_has_no_subtitle_streams() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    assert!(
        info.subtitle_streams().is_empty(),
        "Video file without subtitles should have empty subtitle_streams()"
    );
}

#[test]
fn test_probe_video_file_has_subtitles_returns_false() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    assert!(
        !info.has_subtitles(),
        "has_subtitles() should return false for a video file without subtitle streams"
    );
}

#[test]
fn test_probe_video_file_subtitle_stream_count_is_zero() {
    let path = test_video_path();
    let info = open(&path).expect("Failed to open video file");

    assert_eq!(
        info.subtitle_stream_count(),
        0,
        "subtitle_stream_count() should be 0 for a video file without subtitle streams"
    );
}