Debian Codegraph @

tests/test.rs

raw
1 use gio::prelude::*;
2
3 #[test]
4 fn test_video_thumbnailer() {
5 for (path, var_ref) in [
6 ("1.webm", 2200.),
7 ("2.webm", 2200.),
8 ("3.webm", 2200.),
9 ("long.webm", 1000.),
10 ("uneven.webm", 2200.),
11 // Should use embedded cover image instead of frame
12 ("1-cover.mkv", 5118.),
13 ] {
14 let frame = run_video_thumbnailer(path).unwrap();
15 let var = gst_thumbnailers::variance(
16 &frame.buf_bytes(),
17 frame.width(),
18 frame.stride(),
19 frame.height(),
20 );
21
22 assert!(
23 f32::abs(var - var_ref) < 200.,
24 "{path}: {var:.0} is not approx equal {var_ref}"
25 )
26 }
27 }
28
29 #[test]
30 fn test_video_thumbnailer_on_audio() {
31 let err = run_video_thumbnailer("audio-cover-jpg.mp3").unwrap_err();
32 assert!(
33 err.to_string()
34 .contains("Stream is of type 'audio' instead of 'video'")
35 );
36 }
37
38 #[test]
39 fn test_audio_thumbnailer() {
40 for (path, var_ref) in [
41 ("audio-cover-jpg.mp3", 14500.),
42 ("audio-cover-png.flac", 14500.),
43 ] {
44 let frame = run_audio_thumbnailer(path);
45 let var = gst_thumbnailers::variance(
46 &frame.buf_bytes(),
47 frame.width(),
48 frame.stride(),
49 frame.height(),
50 );
51
52 assert!(
53 f32::abs(var - var_ref) < 200.,
54 "{path}: {var:.0} is not approx equal {var_ref}"
55 )
56 }
57 }
58
59 fn run_video_thumbnailer(video: &str) -> gst_thumbnailers::Result<gly::Frame> {
60 gst_thumbnailers::main_video_thumbnailer([
61 "gst-video-thumbnailer",
62 "-i",
63 &gio::File::for_path(format!("tests/{video}")).uri(),
64 "-o",
65 "tests/test-video-output.png",
66 "-s",
67 "256",
68 ])?;
69
70 Ok(read_png("tests/test-video-output.png"))
71 }
72
73 fn run_audio_thumbnailer(audio: &str) -> gly::Frame {
74 gst_thumbnailers::main_audio_thumbnailer([
75 "gst-audio-thumbnailer",
76 "-i",
77 &gio::File::for_path(format!("tests/{audio}")).uri(),
78 "-o",
79 "tests/test-audio-output.png",
80 "-s",
81 "256",
82 ])
83 .unwrap();
84
85 read_png("tests/test-audio-output.png")
86 }
87
88 fn read_png(path: &str) -> gly::Frame {
89 let loader = gly::Loader::new(&gly::gio::File::for_path(path));
90 let image = loader.load().unwrap();
91 image.next_frame().unwrap()
92 }