Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Cargo.lock
/tmp
/.idea
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "ffmpeg-sys"
version = "4.0.2"
version = "4.1.3"
build = "build.rs"
links = "ffmpeg"

authors = ["meh. <meh@schizofreni.co>"]
authors = ["meh. <meh@schizofreni.co>", "Xana Hopper <xanahopper@163.com>"]
license = "WTFPL"

description = "FFI bindings to FFmpeg"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

81 changes: 46 additions & 35 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,48 @@ 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 {
PathBuf::from(env::var("OUT_DIR").unwrap())
}

fn source() -> PathBuf {
output().join(format!("ffmpeg-{}", version()))
output().join(format!("ffmpeg-{}", branch_version()))
}

fn search() -> PathBuf {
Expand All @@ -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(())
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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"));
}
Expand Down