feat: use `audiowaveform` for audio preview generation

much faster than ffmpeg - not sure if it's a recent regression or my system, but ffmpeg took **minutes** to generate an image, whereas `audiowaveform` does the same in seconds
feat/type-attributes
Tomáš Mládek 2023-08-20 18:06:31 +02:00
parent a2192f5143
commit e0b824b9da
1 changed files with 13 additions and 13 deletions

View File

@ -10,7 +10,7 @@ use super::Previewable;
pub struct AudioPath<'a>(pub &'a Path);
const COLOR: &str = "#dc322f"; // solarized red
const COLOR: &str = "dc322f"; // solarized red
impl<'a> Previewable for AudioPath<'a> {
fn get_thumbnail(&self, options: HashMap<String, String>) -> Result<Option<Vec<u8>>> {
@ -38,27 +38,27 @@ impl<'a> Previewable for AudioPath<'a> {
Ok(Some(buffer))
}
Some("image") | None => {
let outfile = tempfile::Builder::new().suffix(".webp").tempfile()?;
let outfile = tempfile::Builder::new().suffix(".png").tempfile()?;
let color = options
.get("color")
.map(String::to_owned)
.unwrap_or_else(|| COLOR.into());
let dimensions = options
.get("dimensions")
.map(String::to_owned)
.unwrap_or_else(|| "860x256".into());
let mut ffmpeg = Command::new("ffmpeg");
let command = ffmpeg
let mut audiowaveform = Command::new("audiowaveform");
let command = audiowaveform
.args(["-i", &self.0.to_string_lossy()])
.args([
"-filter_complex",
&format!("[0:a]aformat=channel_layouts=mono,compand=gain=-2,showwavespic=s={dimensions}:colors={color},drawbox=x=(iw-w)/2:y=(ih-h)/2:w=iw:h=1:color={color}"),
"--border-color",
"00000000",
"--background-color",
"00000000",
"--waveform-color",
&color,
"--no-axis-label",
])
.args(["-vframes", "1"])
.arg(&*outfile.path().to_string_lossy())
.arg("-y");
.args(["--width", "860", "--height", "256"])
.args(["-o", &*outfile.path().to_string_lossy()]);
trace!("Running `{:?}`", command);
let now = std::time::Instant::now();