├── .github └── workflows │ └── libav.yml ├── .gitignore ├── Cargo.toml ├── README.md ├── libav-sys ├── .gitignore ├── Cargo.toml ├── LICENSE ├── build.rs ├── data │ ├── libavcodec.h │ ├── libavfilter.h │ ├── libavformat.h │ ├── libavresample.h │ └── libswresample.h └── src │ └── lib.rs └── src └── lib.rs /.github/workflows/libav.yml: -------------------------------------------------------------------------------- 1 | name: libav 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Install nasm 13 | run: | 14 | sudo apt-get install nasm 15 | - name: Cache libav 16 | uses: actions/cache@preview 17 | id: cache 18 | with: 19 | path: libav 20 | key: ${{ runner.os }}-${{ hashFiles('**/libav-sys/Cargo.toml')}} 21 | - name: Build libav 22 | if: steps.cache.outputs.cache-hit != 'true' 23 | run: | 24 | git clone --depth 1 https://github.com/libav/libav 25 | cd libav 26 | ./configure --prefix=$HOME/libav_dir 27 | make 28 | - name: Install libav 29 | run: | 30 | cd libav 31 | make install 32 | - name: Run tests 33 | run: | 34 | export PKG_CONFIG_PATH=$HOME/libav_dir/lib/pkgconfig:$PKG_CONFIG_PATH 35 | cargo test --all-features 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libav-rs" 3 | version = "0.1.0" 4 | authors = ["Luca Barbato "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libav bindings 2 | 3 | [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) 4 | [![Actions Status](https://github.com/rust-av/libav-rs/workflows/libav/badge.svg)](https://github.com/rust-av/libav-rs/actions) 5 | 6 | It is a simple [binding][1] and safe abstraction over [libav][2] avcodec, avformat, avfilter, avresample, and swresample. 7 | 8 | ## Building 9 | 10 | The bindings are generated using the headers and libraries that ought to be present in the system. 11 | 12 | ## TODO 13 | - [ ] Simple bindings 14 | - [ ] Safe abstraction 15 | - [ ] Examples 16 | 17 | [1]: https://github.com/servo/rust-bindgen 18 | [2]: https://libav.org/ 19 | -------------------------------------------------------------------------------- /libav-sys/.gitignore: -------------------------------------------------------------------------------- 1 | src/avformat.rs 2 | src/avcodec.rs 3 | src/avresample.rs 4 | src/avfilter.rs 5 | src/swresample.rs 6 | target/ 7 | -------------------------------------------------------------------------------- /libav-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "libav-sys" 3 | version = "0.1.0" 4 | authors = ["Luca Barbato "] 5 | license = "MIT" 6 | description = "FFI bindings to libav" 7 | repository = "https://github.com/rust-av/libav-rs" 8 | 9 | build = "build.rs" 10 | 11 | [build-dependencies] 12 | bindgen = "0.30" 13 | system-deps = "1.3" 14 | 15 | [package.metadata.system-deps] 16 | libavcodec = "58" 17 | libavformat = "58" 18 | libavfilter = "7.40.101" 19 | libavresample = "4.0.0" 20 | libswresample = "3.3.100" 21 | 22 | [dependencies] 23 | -------------------------------------------------------------------------------- /libav-sys/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Luca Barbato 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /libav-sys/build.rs: -------------------------------------------------------------------------------- 1 | extern crate bindgen; 2 | extern crate system_deps; 3 | 4 | use std::fs::File; 5 | use std::io::Write; 6 | 7 | fn format_write(builder: bindgen::Builder, output: &str) { 8 | let s = builder 9 | .generate() 10 | .unwrap() 11 | .to_string() 12 | .replace("/**", "/*") 13 | .replace("/*!", "/*"); 14 | 15 | let mut file = File::create(output).unwrap(); 16 | 17 | let _ = file.write(s.as_bytes()); 18 | } 19 | 20 | fn common_builder() -> bindgen::Builder { 21 | bindgen::builder() 22 | .raw_line("#![allow(deprecated)]") 23 | .raw_line("#![allow(dead_code)]") 24 | .raw_line("#![allow(non_camel_case_types)]") 25 | .raw_line("#![allow(non_snake_case)]") 26 | .raw_line("#![allow(non_upper_case_globals)]") 27 | } 28 | 29 | fn main() { 30 | let libs = system_deps::Config::new().probe().unwrap(); 31 | 32 | for e in [ 33 | "avcodec", 34 | "avfilter", 35 | "avformat", 36 | "avresample", 37 | "swresample", 38 | ] 39 | .iter() 40 | { 41 | let headers = libs 42 | .get(&format!("lib{}", e)) 43 | .unwrap() 44 | .include_paths 45 | .clone(); 46 | 47 | let mut builder = common_builder().header(format!("data/lib{}.h", e)); 48 | 49 | for header in headers.iter() { 50 | builder = builder.clang_arg("-I").clang_arg(header.to_str().unwrap()); 51 | } 52 | 53 | // Manually fix the comment so rustdoc won't try to pick them 54 | format_write(builder, &format!("src/{}.rs", e)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libav-sys/data/libavcodec.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libav-sys/data/libavfilter.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libav-sys/data/libavformat.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libav-sys/data/libavresample.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libav-sys/data/libswresample.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /libav-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | // TODO do w/out the unions? 2 | #![feature(untagged_unions)] 3 | 4 | pub mod avcodec; 5 | pub mod avformat; 6 | pub mod avfilter; 7 | pub mod avresample; 8 | pub mod swresample; 9 | 10 | #[cfg(test)] 11 | mod tests { 12 | use super::avcodec::avcodec_configuration; 13 | use super::avformat::avformat_configuration; 14 | use super::avresample::avresample_configuration; 15 | use std::ffi::CStr; 16 | #[test] 17 | fn version() { 18 | unsafe { 19 | println!( 20 | "{}{}{}", 21 | CStr::from_ptr(avcodec_configuration()).to_string_lossy(), 22 | CStr::from_ptr(avformat_configuration()).to_string_lossy(), 23 | CStr::from_ptr(avresample_configuration()).to_string_lossy() 24 | ) 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod tests { 3 | #[test] 4 | fn it_works() { 5 | assert_eq!(2 + 2, 4); 6 | } 7 | } 8 | --------------------------------------------------------------------------------