| 1 | pub mod encoder; |
| 2 | pub use self::encoder::Encoder; |
| 3 | |
| 4 | pub mod video; |
| 5 | pub use self::video::Encoder as Video; |
| 6 | |
| 7 | pub mod audio; |
| 8 | pub use self::audio::Encoder as Audio; |
| 9 | |
| 10 | pub mod subtitle; |
| 11 | pub use self::subtitle::Encoder as Subtitle; |
| 12 | |
| 13 | pub mod motion_estimation; |
| 14 | pub use self::motion_estimation::MotionEstimation; |
| 15 | |
| 16 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
| 17 | pub mod prediction; |
| 18 | #[cfg (not(feature = "ffmpeg_5_0" ))] |
| 19 | pub use self::prediction::Prediction; |
| 20 | |
| 21 | pub mod comparison; |
| 22 | pub use self::comparison::Comparison; |
| 23 | |
| 24 | pub mod decision; |
| 25 | pub use self::decision::Decision; |
| 26 | |
| 27 | use std::ffi::CString; |
| 28 | |
| 29 | use codec::Context; |
| 30 | use codec::Id; |
| 31 | use ffi::*; |
| 32 | use Codec; |
| 33 | |
| 34 | pub fn new() -> Encoder { |
| 35 | Context::new().encoder() |
| 36 | } |
| 37 | |
| 38 | pub fn find(id: Id) -> Option<Codec> { |
| 39 | unsafe { |
| 40 | // We get a clippy warning in 4.4 but not in 5.0 and newer, so we allow that cast to not complicate the code |
| 41 | #[allow (clippy::unnecessary_cast)] |
| 42 | let ptr: *mut {unknown} = avcodec_find_encoder(id.into()) as *mut AVCodec; |
| 43 | |
| 44 | if ptr.is_null() { |
| 45 | None |
| 46 | } else { |
| 47 | Some(Codec::wrap(ptr)) |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | pub fn find_by_name(name: &str) -> Option<Codec> { |
| 53 | unsafe { |
| 54 | let name: CString = CString::new(name).unwrap(); |
| 55 | #[allow (clippy::unnecessary_cast)] |
| 56 | let ptr: *mut {unknown} = avcodec_find_encoder_by_name(name.as_ptr()) as *mut AVCodec; |
| 57 | |
| 58 | if ptr.is_null() { |
| 59 | None |
| 60 | } else { |
| 61 | Some(Codec::wrap(ptr)) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |