metrale_bench/benchmarks/video/
provision.rs1use anyhow::Result;
15
16use crate::artifacts::{ArtifactStore, Stamp, write_asset_bytes};
17
18pub struct Clip {
20 pub name: &'static str,
21 pub bytes: &'static [u8],
22 pub colors: &'static [&'static str],
24 pub seconds: u32,
27 pub needs_ffmpeg: bool,
31 pub mime: &'static str,
32}
33
34pub const CLIPS: &[Clip] = &[
43 Clip {
44 name: "01_colors_fwd.mp4",
45 bytes: include_bytes!("../../../assets/video/01_colors_fwd.mp4"),
46 colors: &["red", "green", "blue", "yellow"],
47 seconds: 4,
48 needs_ffmpeg: true,
49 mime: "video/mp4",
50 },
51 Clip {
52 name: "02_colors_rev.mp4",
53 bytes: include_bytes!("../../../assets/video/02_colors_rev.mp4"),
54 colors: &["yellow", "blue", "green", "red"],
55 seconds: 4,
56 needs_ffmpeg: true,
57 mime: "video/mp4",
58 },
59 Clip {
60 name: "03_colors_fwd.gif",
61 bytes: include_bytes!("../../../assets/video/03_colors_fwd.gif"),
62 colors: &["red", "green", "blue", "yellow"],
63 seconds: 4,
64 needs_ffmpeg: false,
65 mime: "image/gif",
66 },
67 Clip {
68 name: "05_colors_unit.mp4",
69 bytes: include_bytes!("../../../assets/video/05_colors_unit.mp4"),
70 colors: &["red"],
71 seconds: 1,
72 needs_ffmpeg: true,
73 mime: "video/mp4",
74 },
75 Clip {
76 name: "04_colors_half.mp4",
77 bytes: include_bytes!("../../../assets/video/04_colors_half.mp4"),
78 colors: &["red", "green"],
79 seconds: 2,
80 needs_ffmpeg: true,
81 mime: "video/mp4",
82 },
83];
84
85pub fn clip(name: &str) -> Option<&'static Clip> {
86 CLIPS.iter().find(|c| c.name == name)
87}
88
89fn stamp_value() -> String {
92 crate::benchmarks::content_stamp("video-fixtures-v1", CLIPS.iter().map(|c| (c.name, c.bytes)))
93}
94
95pub const PLUGIN_ID: &str = "video";
96
97pub fn provision(store: &ArtifactStore) -> Result<std::path::PathBuf> {
98 let dir = store.plugin_dir(PLUGIN_ID)?;
99 let stamp = Stamp::new(&dir, ".provisioned", stamp_value());
100 if stamp.is_current() {
101 return Ok(dir);
102 }
103 for c in CLIPS {
104 write_asset_bytes(&dir, c.name, c.bytes)?;
105 }
106 stamp.commit()?;
109 Ok(dir)
110}
111
112#[cfg(test)]
113#[path = "provision_tests.rs"]
114mod provision_tests;