Skip to content

Commit

Permalink
Use string as ffmpeg version type
Browse files Browse the repository at this point in the history
Ffmpeg 6 seems to not provide a semver version, as this is only used to
report the version being used a `String` works fine here.
  • Loading branch information
DanNixon committed Dec 4, 2023
1 parent 389c2a4 commit ea3dc4d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ rust-s3 = "0.34.0-rc4"
satori-common = { path = "./common" }
satori-storage = { path = "./storage" }
satori-testing-utils = { path = "./testing-utils" }
semver = "1.0.14"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.0"
serde_json = "1.0.91"
Expand Down
1 change: 0 additions & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ kagiyama.workspace = true
nix.workspace = true
regex.workspace = true
satori-common.workspace = true
semver.workspace = true
serde.workspace = true
serde_with.workspace = true
tempfile.workspace = true
Expand Down
37 changes: 28 additions & 9 deletions agent/src/ffmpeg/version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use regex::Regex;
use semver::Version;
use std::process::Command;
use tracing::info;

/// Gets the version of ffmpeg based on the output of the `ffmpeg -version` command.
pub(crate) fn get_ffmpeg_version() -> Version {
pub(crate) fn get_ffmpeg_version() -> String {
let ffmpeg_process = Command::new("ffmpeg")
.arg("-version")
.output()
Expand All @@ -13,18 +12,36 @@ pub(crate) fn get_ffmpeg_version() -> Version {
}

/// Parses the output of `ffmpeg -version` to extract the version.
fn extract_version_from_version_output(text: &str) -> Version {
let version_string_regex = Regex::new(r"ffmpeg version.+(\d\.\d\.\d)").unwrap();
fn extract_version_from_version_output(text: &str) -> String {
let version_string_regex = Regex::new(r"ffmpeg version (.*) Copyright").unwrap();
let version_string = version_string_regex.captures(text).unwrap();
let version = Version::parse(&version_string[1]).unwrap();
info!("Detected ffmpeg version: {}", version);
version
let version_string = version_string[1].to_string();
info!("Detected ffmpeg version: {}", version_string);
version_string
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_version_6() {
let text = "ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.3.0 (GCC)
configuration: --disable-static --prefix=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0 --target_os=linux --arch=x86_64 --pkg-config=pkg-config --enable-gpl --enable-version3 --disable-nonfree --enable-shared --enable-pic --disable-small --enable-runtime-cpudetect --disable-gray --enable-swscale-alpha --enable-hardcoded-tables --enable-safe-bitstream-reader --enable-pthreads --disable-w32threads --disable-os2threads --enable-network --enable-pixelutils --datadir=/nix/store/hj2xwsm8jigjc3ld27gcqmdv8fghs8qg-ffmpeg-6.0-data/share/ffmpeg --enable-ffmpeg --disable-ffplay --enable-ffprobe --bindir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-bin/bin --enable-avcodec --enable-avdevice --enable-avfilter --enable-avformat --enable-avutil --enable-postproc --enable-swresample --enable-swscale --libdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-lib/lib --incdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-dev/include --enable-doc --enable-htmlpages --enable-manpages --mandir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-man/share/man --enable-podpages --enable-txtpages --docdir=/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ffmpeg-6.0-doc/share/doc/ffmpeg --enable-alsa --enable-bzlib --disable-libcelt --disable-cuda --disable-cuda-llvm --enable-libdav1d --disable-libfdk-aac --disable-libflite --enable-fontconfig --enable-libfreetype --disable-frei0r --disable-libfribidi --disable-libgme --enable-gnutls --disable-libgsm --disable-ladspa --enable-libmp3lame --disable-libaom --enable-libass --disable-libbluray --disable-libbs2b --disable-libdc1394 --enable-libdrm --enable-iconv --disable-libjack --disable-libmfx --disable-libmodplug --disable-libmysofa --enable-libopus --disable-librsvg --enable-libsrt --enable-libssh --disable-libtensorflow --enable-libtheora --enable-libv4l2 --enable-v4l2-m2m --enable-vaapi --enable-vdpau --enable-libvorbis --disable-libvmaf --enable-libvpx --disable-libwebp --disable-xlib --disable-libxcb --disable-libxcb-shm --disable-libxcb-xfixes --disable-libxcb-shape --disable-libxml2 --enable-lzma --enable-cuvid --enable-nvdec --enable-nvenc --disable-openal --disable-opencl --disable-libopencore-amrnb --disable-opengl --disable-libopenh264 --disable-libopenjpeg --disable-libopenmpt --enable-libpulse --disable-librav1e --enable-libsvtav1 --disable-librtmp --enable-sdl2 --enable-libsoxr --enable-libspeex --disable-libvidstab --disable-libvo-amrwbenc --enable-libx264 --enable-libx265 --disable-libxavs --enable-libxvid --disable-libzmq --enable-libzimg --enable-zlib --disable-vulkan --disable-libglslang --disable-libsmbclient --disable-debug --enable-optimizations --disable-extra-warnings --disable-stripping
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
";

assert_eq!(extract_version_from_version_output(text), "6.0".to_string());
}

#[test]
fn test_version_5() {
let text = "ffmpeg version n5.1.2 Copyright (c) 2000-2022 the FFmpeg developers
Expand All @@ -39,9 +56,10 @@ libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
";

assert_eq!(
extract_version_from_version_output(text),
Version::new(5, 1, 2)
"n5.1.2".to_string()
);
}

Expand All @@ -60,9 +78,10 @@ libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
";

assert_eq!(
extract_version_from_version_output(text),
Version::new(4, 3, 5)
"4.3.5-0+deb11u1".to_string()
);
}
}

0 comments on commit ea3dc4d

Please sign in to comment.