Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/file-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use data_encoding::BASE64URL_NOPAD;
use linked_hash_map::LinkedHashMap;
use rand::RngCore;
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::fs::{self, Metadata};
use std::io::{self, Read, Write};
Expand Down Expand Up @@ -49,6 +48,7 @@ impl From<Metadata> for FileModTime {
fn from(meta: Metadata) -> Self {
#[cfg(unix)]
{
use std::cmp::Ordering;
use std::os::unix::fs::MetadataExt;
let mtime = meta.mtime();
let ctime = meta.ctime();
Expand Down
1 change: 1 addition & 0 deletions crates/media_info/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ clap = { version = "4", features = ["derive"] }

[build-dependencies]
pkg-config = "0.3.30"
bindgen = "0.72.1"

[features]
static = []
Expand Down
87 changes: 85 additions & 2 deletions crates/media_info/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const FFMPEG_VERSION_4: &str = "ffmpeg-4.4.6";
const FFMPEG_VERSION_5: &str = "ffmpeg-5.1.7";
const FFMPEG_VERSION_6: &str = "ffmpeg-6.1.1";
const FFMPEG_VERSION_7: &str = "ffmpeg-7.1.1";
const FFMPEG_VERSION_8: &str = "ffmpeg-8.0";

// macro_rules! warn {
// ($fmt:literal $(, $arg:expr)* ) => {
Expand All @@ -26,8 +27,10 @@ fn main() {
match pkg {
Ok(lib) => {
if let Some(version) = parse_main_version(&lib.version) {
if version > 61 {
if version > 62 {
panic!("libavformat is too new - need to update source with new ffi");
} else if version == 62 {
FFMPEG_VERSION_8
} else if version == 61 {
FFMPEG_VERSION_7
} else if version == 60 {
Expand All @@ -44,10 +47,16 @@ fn main() {
}
}
Err(e) => {
panic!("Cannot find libavformat: {}", e);
if cfg!(windows) {
get_ffmpeg_version_windows()
} else {
panic!("Cannot find libavformat: {}", e);
}
}
}
};

generate_ffi(ffmpeg_version);
let ffi_src = format!("src/ffi_{}.rs", ffmpeg_version);
eprintln!("ffmpeg version: {}", ffmpeg_version);
let ffi_target =
Expand Down Expand Up @@ -119,3 +128,77 @@ fn main() {
println!("cargo:rustc-link-lib=avcodec");
}
}

fn generate_ffi(ffmpeg_version: &str) {
let mut args = vec![format!("-I{ffmpeg_version}")];
let out_file = format!("src/ffi_{ffmpeg_version}.rs");

if cfg!(windows) {
println!("cargo:rustc-link-search=C:/ffmpeg/lib");
args.push("-IC:/ffmpeg/include".to_string());
}

println!("cargo:rustc-link-lib=avformat");
println!("cargo:rustc-link-lib=avutil");
println!("cargo:rustc-link-lib=avcodec");

let _bindings = bindgen::Builder::default()
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate_comments(false)
.allowlist_type("AVFormatContext")
.allowlist_type("AVDictionary")
.allowlist_type("AVChapter")
.allowlist_type("AVRational")
.allowlist_function("av_dict_get")
.allowlist_function("av_dict_count")
.allowlist_function("av_log_set_level")
.allowlist_function("av_register_all")
.allowlist_function("avformat_version")
.allowlist_function("avformat_alloc_context")
.allowlist_function("avformat_open_input")
.allowlist_function("avformat_find_stream_info")
.allowlist_function("avformat_close_input")
.allowlist_function("av_dump_format")
.allowlist_var("AV_LOG_QUIET")
.allowlist_var("AV_DICT_IGNORE_SUFFIX")
.allowlist_var("AV_TIME_BASE")
.clang_args(args)
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_file)
.expect("Couldn't write bindings!");
}

fn get_ffmpeg_version_windows() -> &'static str {
let paths = std::fs::read_dir("C:/ffmpeg/bin").unwrap();
for path in paths {
let path = path.unwrap().path();
let file_name = path.file_name().unwrap().to_str().unwrap();
if file_name.starts_with("avformat-") && file_name.ends_with(".dll") {
let version = file_name
.trim_start_matches("avformat-")
.trim_end_matches(".dll")
.parse::<u32>()
.unwrap_or(0);
if version > 62 {
panic!("libavformat is too new - need to update source with new ffi");
} else if version == 62 {
return FFMPEG_VERSION_8;
} else if version == 61 {
return FFMPEG_VERSION_7;
} else if version == 60 {
return FFMPEG_VERSION_6;
} else if version == 59 {
return FFMPEG_VERSION_5;
} else if version == 58 {
return FFMPEG_VERSION_4;
} else {
panic!("unknown libavformat version {}", version);
}
}
}
panic!("Unknown ffmpeg location");
}
28 changes: 0 additions & 28 deletions crates/media_info/generate_ffi.sh

This file was deleted.

Loading
Loading