Use 'ffmpeg' commandline to decode files, and not ffmpeg libraries.

This commit is contained in:
CDrummond 2025-03-01 15:45:47 +00:00
parent 68ed1fc3b0
commit 22133436b9
6 changed files with 63 additions and 122 deletions

136
Cargo.lock generated
View File

@ -87,36 +87,12 @@ version = "0.21.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "bindgen"
version = "0.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f49d8fed880d473ea71efb9bf597651e77201bdd4893efe54c9e5d65ae04ce6f"
dependencies = [
"bitflags 2.6.0",
"cexpr",
"clang-sys",
"itertools",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 2.0.28",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "blake2b_simd"
version = "0.5.11"
@ -139,10 +115,12 @@ dependencies = [
"configparser",
"dirs",
"env_logger",
"hound",
"if_chain",
"indicatif",
"lofty",
"log",
"md5",
"num_cpus",
"regex",
"rusqlite",
@ -152,15 +130,13 @@ dependencies = [
[[package]]
name = "bliss-audio"
version = "0.9.3"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "191f4a248aa795440b59bc9f994fddc21428959d00ddef704e81cced1453411d"
checksum = "9af3dbc2bc1dd8b43a93d10b1f4752f283c06451f9d3a6e1433fb6bf1c9afc53"
dependencies = [
"adler32",
"bliss-audio-aubio-rs",
"extended-isolation-forest",
"ffmpeg-next",
"ffmpeg-sys-next",
"log",
"ndarray",
"ndarray-stats",
@ -212,15 +188,6 @@ dependencies = [
"libc",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -246,17 +213,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]]
name = "clang-sys"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "configparser"
version = "3.0.0"
@ -394,31 +350,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "ffmpeg-next"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da02698288e0275e442a47fc12ca26d50daf0d48b15398ba5906f20ac2e2a9f9"
dependencies = [
"bitflags 2.6.0",
"ffmpeg-sys-next",
"libc",
]
[[package]]
name = "ffmpeg-sys-next"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bc3234d0a4b2f7d083699d0860c6c9dd83713908771b60f94a96f8704adfe45"
dependencies = [
"bindgen",
"cc",
"libc",
"num_cpus",
"pkg-config",
"vcpkg",
]
[[package]]
name = "flate2"
version = "1.0.34"
@ -461,12 +392,6 @@ dependencies = [
"wasi 0.10.0+wasi-snapshot-preview1",
]
[[package]]
name = "glob"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "hashbrown"
version = "0.11.2"
@ -506,6 +431,12 @@ version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]]
name = "hound"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f"
[[package]]
name = "humantime"
version = "2.1.0"
@ -590,16 +521,6 @@ version = "0.2.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
[[package]]
name = "libloading"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "libm"
version = "0.2.11"
@ -665,6 +586,12 @@ dependencies = [
"rawpointer",
]
[[package]]
name = "md5"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"
[[package]]
name = "memchr"
version = "2.4.1"
@ -680,12 +607,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.8.0"
@ -733,17 +654,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "nom"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
dependencies = [
"memchr",
"minimal-lexical",
"version_check",
]
[[package]]
name = "num-complex"
version = "0.4.0"
@ -987,7 +897,7 @@ version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c4b1eaf239b47034fb450ee9cdedd7d0226571689d8823030c4b6c2cb407152"
dependencies = [
"bitflags 1.3.2",
"bitflags",
"fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
@ -1008,12 +918,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustfft"
version = "6.1.0"
@ -1063,12 +967,6 @@ dependencies = [
"untrusted",
]
[[package]]
name = "shlex"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "smallvec"
version = "1.8.0"

View File

@ -10,7 +10,6 @@ keywords = ["audio", "song", "similarity"]
readme = "README.md"
[dependencies]
bliss-audio = { version = "0.9.3", features = ["ffmpeg", "aubio-static"] }
argparse = "0.2.2"
anyhow = "1.0.40"
rusqlite = { version = "0.25.0", features = ["bundled"] }
@ -26,3 +25,10 @@ ureq = "2.4.0"
configparser = "3.0.0"
if_chain = "1.0.2"
num_cpus = "1.13.0"
md5 = "0.7.0"
hound = "3.5.1"
[dependencies.bliss-audio]
default-features = false
features = ["aubio-static"]
version = "0.9.4"

View File

@ -2,6 +2,7 @@
-----
1. Add support for (DSD) WavPack - thanks to Bart Lauret
2. Update version of bliss library.
3. Use 'ffmpeg' commandline to decode files, and not ffmpeg libraries.
0.2.3
-----

View File

@ -7,9 +7,10 @@
**/
use crate::db;
use crate::ffmpeg;
use crate::tags;
use anyhow::Result;
use bliss_audio::decoder::{Decoder, ffmpeg::FFmpeg};
use bliss_audio::decoder::Decoder;
use if_chain::if_chain;
use indicatif::{ProgressBar, ProgressStyle};
use std::collections::HashSet;
@ -101,7 +102,7 @@ pub fn analyse_new_files(db: &db::Db, mpath: &PathBuf, track_paths: Vec<String>,
let mut reported_cue:HashSet<String> = HashSet::new();
log::info!("Analysing new files");
for (path, result) in <FFmpeg as Decoder>::analyze_paths_with_cores(track_paths, cpu_threads) {
for (path, result) in <ffmpeg::FFmpegCmdDecoder as Decoder>::analyze_paths_with_cores(track_paths, cpu_threads) {
let stripped = path.strip_prefix(mpath).unwrap();
let spbuff = stripped.to_path_buf();
let sname = String::from(spbuff.to_string_lossy());

34
src/ffmpeg.rs Normal file
View File

@ -0,0 +1,34 @@
/**
* Analyse music with Bliss
*
* Copyright (c) 2022-2025 Craig Drummond <craig.p.drummond@gmail.com>
* GPLv3 license.
*
**/
use bliss_audio::decoder::Decoder as DecoderTrait;
use bliss_audio::decoder::PreAnalyzedSong;
use bliss_audio::BlissResult;
use std::fs;
use std::path::Path;
use std::process::Command;
use md5;
pub struct FFmpegCmdDecoder;
impl DecoderTrait for FFmpegCmdDecoder {
fn decode(path: &Path) -> BlissResult<PreAnalyzedSong> {
let mut decoded_song = PreAnalyzedSong::default();
let digest = md5::compute(path.to_str().unwrap_or("null").as_bytes().to_vec());
let tmp_path = format!("/tmp/{:x}.wav", digest);
let _ = Command::new("ffmpeg").arg("-i").arg(path).arg("-ar").arg("22050").arg("-ac").arg("1").arg("-c:a").arg("pcm_f32le").arg(tmp_path.clone()).output();
let cloned_path = tmp_path.clone();
let wav_file = Path::new(&cloned_path);
if wav_file.exists() {
let mut reader = hound::WavReader::open(tmp_path).unwrap();
decoded_song.sample_array = reader.samples::<f32>().flatten().collect();
let _ = fs::remove_file(wav_file);
}
Ok(decoded_song)
}
}

View File

@ -16,6 +16,7 @@ use std::path::PathBuf;
use std::process;
mod analyse;
mod db;
mod ffmpeg;
mod tags;
mod upload;