diff --git a/.gitignore b/.gitignore index 90791199..c24dab46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target Cargo.lock /tmp +/.idea \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 1703d2f5..ff9da3e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "ffmpeg-sys" -version = "4.0.2" +version = "4.1.3" build = "build.rs" links = "ffmpeg" -authors = ["meh. "] +authors = ["meh. ", "Xana Hopper "] license = "WTFPL" description = "FFI bindings to FFmpeg" diff --git a/README.md b/README.md new file mode 100644 index 00000000..5c61ece8 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# FFmpeg binding for Rust + +## Quick Start + +If setting environment variable `FFMPEG_VERSION` to X.X.X will fetch FFmpeg source from Github and build from it. +If setting environment variable `FFMPEG_DIR` to path that FFmpeg installed will skip build and link to it directly. + +Note that version must be full version included patch number. If none of above is set it will fetch FFmpeg which version matched ffmpeg-sys. + \ No newline at end of file diff --git a/build.rs b/build.rs index f570032e..81752949 100644 --- a/build.rs +++ b/build.rs @@ -73,17 +73,40 @@ impl ParseCallbacks for IntCallbacks { } } +fn branch_version() -> String { + if let Ok(version) = env::var("FFMPEG_VERSION") { + if version.is_empty() { + ::version() + } else { + version + } + } else { + version() + } +} + fn version() -> String { - let major: u8 = env::var("CARGO_PKG_VERSION_MAJOR") + let major: u32 = env::var("CARGO_PKG_VERSION_MAJOR") + .unwrap() + .parse() + .unwrap(); + let minor: u32 = env::var("CARGO_PKG_VERSION_MINOR") .unwrap() .parse() .unwrap(); - let minor: u8 = env::var("CARGO_PKG_VERSION_MINOR") + let patch: u32 = env::var("CARGO_PKG_VERSION_PATCH") .unwrap() .parse() .unwrap(); + version_str(major, minor, patch) +} - format!("{}.{}", major, minor) +fn version_str(major: u32, minor: u32, patch: u32) -> String { + if patch == 0 { + format!("{}.{}", major, minor) + } else { + format!("{}.{}.{}", major, minor, patch) + } } fn output() -> PathBuf { @@ -91,7 +114,7 @@ fn output() -> PathBuf { } fn source() -> PathBuf { - output().join(format!("ffmpeg-{}", version())) + output().join(format!("ffmpeg-{}", branch_version())) } fn search() -> PathBuf { @@ -103,16 +126,16 @@ fn search() -> PathBuf { } fn fetch() -> io::Result<()> { - let status = try!( - Command::new("git") - .current_dir(&output()) - .arg("clone") - .arg("-b") - .arg(format!("release/{}", version())) - .arg("https://github.com/FFmpeg/FFmpeg") - .arg(format!("ffmpeg-{}", version())) - .status() - ); + let version = branch_version(); + println!("fetching FFmpeg {} to {}/ffmpeg-{}", version, output().to_str().unwrap(), version); + let status = Command::new("git") + .current_dir(&output()) + .arg("clone") + .arg("-b") + .arg(format!("n{}", version)) + .arg("https://github.com/FFmpeg/FFmpeg") + .arg(format!("ffmpeg-{}", version)) + .status()?; if status.success() { Ok(()) @@ -166,14 +189,6 @@ fn build() -> io::Result<()> { ) } - // macro_rules! disable { - // ($conf:expr, $feat:expr, $name:expr) => ( - // if env::var(concat!("CARGO_FEATURE_", $feat)).is_err() { - // $conf.arg(concat!("--disable-", $name)); - // } - // ) - // } - // the binary using ffmpeg-sys must comply with GPL switch(&mut configure, "BUILD_LICENSE_GPL", "gpl"); @@ -267,24 +282,20 @@ fn build() -> io::Result<()> { } // run make - if !try!( - Command::new("make") - .arg("-j") - .arg(num_cpus::get().to_string()) - .current_dir(&source()) - .status() - ).success() + if !Command::new("make") + .arg("-j") + .arg(num_cpus::get().to_string()) + .current_dir(&source()) + .status()?.success() { return Err(io::Error::new(io::ErrorKind::Other, "make failed")); } // run make install - if !try!( - Command::new("make") - .current_dir(&source()) - .arg("install") - .status() - ).success() + if !Command::new("make") + .current_dir(&source()) + .arg("install") + .status()?.success() { return Err(io::Error::new(io::ErrorKind::Other, "make install failed")); }