*: format code with rustfmt and fix clippy suggestions
* Add avformat_close_input call to clean up AVFormantContext * Format code with rustfmt * Fix clippy lint double_parens * Fix clippy lint deref_addrof * Fix clippy lint identity_conversion * Fix clippy lint match_ref_pats * Fix clippy lint cast_lossless * Fix clippy lint cmp_null * Fix clippy lint clone_on_ref_ptr * Fix clippy lint map_clone * Fix clippy lint needless_borrow * Fix clippy lint needless_pass_by_value * Fix clippy lints for examples * Fix clippy lint unused_io_amount * Fix clippy lint new_without_default * Ignore inline_always clippy lint * Add vim temp files to .gitignore
This commit is contained in:
@ -1,200 +1,206 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::Encoder as Super;
|
||||
use ::{packet, Error, Dictionary, ChannelLayout, frame};
|
||||
use ::util::format;
|
||||
use codec::{traits, Context};
|
||||
use util::format;
|
||||
use {frame, packet, ChannelLayout, Dictionary, Error};
|
||||
|
||||
pub struct Audio(pub Super);
|
||||
|
||||
impl Audio {
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_with(mut self, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts);
|
||||
pub fn open_with(mut self, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as_with<E: traits::Encoder>(mut self, codec: E, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
pub fn open_as_with<E: traits::Encoder>(
|
||||
mut self,
|
||||
codec: E,
|
||||
options: Dictionary,
|
||||
) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_rate(&mut self, rate: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_rate = rate;
|
||||
}
|
||||
}
|
||||
pub fn set_rate(&mut self, rate: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_rate = rate;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).sample_rate as u32
|
||||
}
|
||||
}
|
||||
pub fn rate(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).sample_rate as u32 }
|
||||
}
|
||||
|
||||
pub fn set_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
pub fn set_format(&mut self, value: format::Sample) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_fmt = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe {
|
||||
format::Sample::from((*self.as_ptr()).sample_fmt)
|
||||
}
|
||||
}
|
||||
pub fn format(&self) -> format::Sample {
|
||||
unsafe { format::Sample::from((*self.as_ptr()).sample_fmt) }
|
||||
}
|
||||
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channel_layout = value.bits();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe {
|
||||
ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout)
|
||||
}
|
||||
}
|
||||
pub fn channel_layout(&self) -> ChannelLayout {
|
||||
unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) }
|
||||
}
|
||||
|
||||
pub fn set_channels(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channels = value;
|
||||
}
|
||||
}
|
||||
pub fn set_channels(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).channels = value;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).channels as u16
|
||||
}
|
||||
}
|
||||
pub fn channels(&self) -> u16 {
|
||||
unsafe { (*self.as_ptr()).channels as u16 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Audio {
|
||||
type Target = Super;
|
||||
type Target = Super;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Audio {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Audio {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Audio {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Encoder(pub Audio);
|
||||
|
||||
impl Encoder {
|
||||
pub fn encode<P: packet::Mut>(&mut self, frame: &frame::Audio, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
if self.format() != frame.format() {
|
||||
return Err(Error::InvalidData);
|
||||
}
|
||||
pub fn encode<P: packet::Mut>(
|
||||
&mut self,
|
||||
frame: &frame::Audio,
|
||||
out: &mut P,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
if self.format() != frame.format() {
|
||||
return Err(Error::InvalidData);
|
||||
}
|
||||
|
||||
let mut got: c_int = 0;
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_encode_audio2(
|
||||
self.0.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
frame.as_ptr(),
|
||||
&mut got,
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flush<P: packet::Mut>(&mut self, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
pub fn flush<P: packet::Mut>(&mut self, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_encode_audio2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_encode_audio2(
|
||||
self.0.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
ptr::null(),
|
||||
&mut got,
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_size as u32
|
||||
}
|
||||
}
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).frame_size as u32 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Encoder {
|
||||
type Target = Audio;
|
||||
type Target = Audio;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Encoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Encoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +1,70 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Comparison {
|
||||
SAD,
|
||||
SSE,
|
||||
SATD,
|
||||
DCT,
|
||||
PSNR,
|
||||
BIT,
|
||||
RD,
|
||||
ZERO,
|
||||
VSAD,
|
||||
VSSE,
|
||||
NSSE,
|
||||
W53,
|
||||
W97,
|
||||
DCTMAX,
|
||||
DCT264,
|
||||
CHROMA,
|
||||
SAD,
|
||||
SSE,
|
||||
SATD,
|
||||
DCT,
|
||||
PSNR,
|
||||
BIT,
|
||||
RD,
|
||||
ZERO,
|
||||
VSAD,
|
||||
VSSE,
|
||||
NSSE,
|
||||
W53,
|
||||
W97,
|
||||
DCTMAX,
|
||||
DCT264,
|
||||
CHROMA,
|
||||
}
|
||||
|
||||
impl From<c_int> for Comparison {
|
||||
fn from(value: c_int) -> Comparison {
|
||||
match value {
|
||||
FF_CMP_SAD => Comparison::SAD,
|
||||
FF_CMP_SSE => Comparison::SSE,
|
||||
FF_CMP_SATD => Comparison::SATD,
|
||||
FF_CMP_DCT => Comparison::DCT,
|
||||
FF_CMP_PSNR => Comparison::PSNR,
|
||||
FF_CMP_BIT => Comparison::BIT,
|
||||
FF_CMP_RD => Comparison::RD,
|
||||
FF_CMP_ZERO => Comparison::ZERO,
|
||||
FF_CMP_VSAD => Comparison::VSAD,
|
||||
FF_CMP_VSSE => Comparison::VSSE,
|
||||
FF_CMP_NSSE => Comparison::NSSE,
|
||||
FF_CMP_W53 => Comparison::W53,
|
||||
FF_CMP_W97 => Comparison::W97,
|
||||
FF_CMP_DCTMAX => Comparison::DCTMAX,
|
||||
FF_CMP_DCT264 => Comparison::DCT264,
|
||||
FF_CMP_CHROMA => Comparison::CHROMA,
|
||||
fn from(value: c_int) -> Comparison {
|
||||
match value {
|
||||
FF_CMP_SAD => Comparison::SAD,
|
||||
FF_CMP_SSE => Comparison::SSE,
|
||||
FF_CMP_SATD => Comparison::SATD,
|
||||
FF_CMP_DCT => Comparison::DCT,
|
||||
FF_CMP_PSNR => Comparison::PSNR,
|
||||
FF_CMP_BIT => Comparison::BIT,
|
||||
FF_CMP_RD => Comparison::RD,
|
||||
FF_CMP_ZERO => Comparison::ZERO,
|
||||
FF_CMP_VSAD => Comparison::VSAD,
|
||||
FF_CMP_VSSE => Comparison::VSSE,
|
||||
FF_CMP_NSSE => Comparison::NSSE,
|
||||
FF_CMP_W53 => Comparison::W53,
|
||||
FF_CMP_W97 => Comparison::W97,
|
||||
FF_CMP_DCTMAX => Comparison::DCTMAX,
|
||||
FF_CMP_DCT264 => Comparison::DCT264,
|
||||
FF_CMP_CHROMA => Comparison::CHROMA,
|
||||
|
||||
_ => Comparison::ZERO,
|
||||
}
|
||||
}
|
||||
_ => Comparison::ZERO,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<c_int> for Comparison {
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Comparison::SAD => FF_CMP_SAD,
|
||||
Comparison::SSE => FF_CMP_SSE,
|
||||
Comparison::SATD => FF_CMP_SATD,
|
||||
Comparison::DCT => FF_CMP_DCT,
|
||||
Comparison::PSNR => FF_CMP_PSNR,
|
||||
Comparison::BIT => FF_CMP_BIT,
|
||||
Comparison::RD => FF_CMP_RD,
|
||||
Comparison::ZERO => FF_CMP_ZERO,
|
||||
Comparison::VSAD => FF_CMP_VSAD,
|
||||
Comparison::VSSE => FF_CMP_VSSE,
|
||||
Comparison::NSSE => FF_CMP_NSSE,
|
||||
Comparison::W53 => FF_CMP_W53,
|
||||
Comparison::W97 => FF_CMP_W97,
|
||||
Comparison::DCTMAX => FF_CMP_DCTMAX,
|
||||
Comparison::DCT264 => FF_CMP_DCT264,
|
||||
Comparison::CHROMA => FF_CMP_CHROMA,
|
||||
}
|
||||
}
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Comparison::SAD => FF_CMP_SAD,
|
||||
Comparison::SSE => FF_CMP_SSE,
|
||||
Comparison::SATD => FF_CMP_SATD,
|
||||
Comparison::DCT => FF_CMP_DCT,
|
||||
Comparison::PSNR => FF_CMP_PSNR,
|
||||
Comparison::BIT => FF_CMP_BIT,
|
||||
Comparison::RD => FF_CMP_RD,
|
||||
Comparison::ZERO => FF_CMP_ZERO,
|
||||
Comparison::VSAD => FF_CMP_VSAD,
|
||||
Comparison::VSSE => FF_CMP_VSSE,
|
||||
Comparison::NSSE => FF_CMP_NSSE,
|
||||
Comparison::W53 => FF_CMP_W53,
|
||||
Comparison::W97 => FF_CMP_W97,
|
||||
Comparison::DCTMAX => FF_CMP_DCTMAX,
|
||||
Comparison::DCT264 => FF_CMP_DCT264,
|
||||
Comparison::CHROMA => FF_CMP_CHROMA,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Decision {
|
||||
Simple,
|
||||
Bits,
|
||||
RateDistortion,
|
||||
Simple,
|
||||
Bits,
|
||||
RateDistortion,
|
||||
}
|
||||
|
||||
impl From<c_int> for Decision {
|
||||
fn from(value: c_int) -> Decision {
|
||||
match value {
|
||||
FF_MB_DECISION_SIMPLE => Decision::Simple,
|
||||
FF_MB_DECISION_BITS => Decision::Bits,
|
||||
FF_MB_DECISION_RD => Decision::RateDistortion,
|
||||
fn from(value: c_int) -> Decision {
|
||||
match value {
|
||||
FF_MB_DECISION_SIMPLE => Decision::Simple,
|
||||
FF_MB_DECISION_BITS => Decision::Bits,
|
||||
FF_MB_DECISION_RD => Decision::RateDistortion,
|
||||
|
||||
_ => Decision::Simple,
|
||||
}
|
||||
}
|
||||
_ => Decision::Simple,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<c_int> for Decision {
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Decision::Simple => FF_MB_DECISION_SIMPLE,
|
||||
Decision::Bits => FF_MB_DECISION_BITS,
|
||||
Decision::RateDistortion => FF_MB_DECISION_RD,
|
||||
}
|
||||
}
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Decision::Simple => FF_MB_DECISION_SIMPLE,
|
||||
Decision::Bits => FF_MB_DECISION_BITS,
|
||||
Decision::RateDistortion => FF_MB_DECISION_RD,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,149 +1,135 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use libc::{c_int, int64_t};
|
||||
use super::{audio, subtitle, video};
|
||||
use codec::Context;
|
||||
use ::{Error, Rational, media};
|
||||
use super::{video, audio, subtitle};
|
||||
use libc::{c_int, int64_t};
|
||||
use {media, Error, Rational};
|
||||
|
||||
pub struct Encoder(pub Context);
|
||||
|
||||
impl Encoder {
|
||||
pub fn video(mut self) -> Result<video::Video, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Video.into();
|
||||
}
|
||||
pub fn video(mut self) -> Result<video::Video, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Video.into();
|
||||
}
|
||||
|
||||
Ok(video::Video(self))
|
||||
}
|
||||
Ok(video::Video(self))
|
||||
}
|
||||
|
||||
media::Type::Video => {
|
||||
Ok(video::Video(self))
|
||||
}
|
||||
media::Type::Video => Ok(video::Video(self)),
|
||||
|
||||
_ => {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(Error::InvalidData),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn audio(mut self) -> Result<audio::Audio, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Audio.into();
|
||||
}
|
||||
pub fn audio(mut self) -> Result<audio::Audio, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Audio.into();
|
||||
}
|
||||
|
||||
Ok(audio::Audio(self))
|
||||
}
|
||||
Ok(audio::Audio(self))
|
||||
}
|
||||
|
||||
media::Type::Audio => {
|
||||
Ok(audio::Audio(self))
|
||||
}
|
||||
media::Type::Audio => Ok(audio::Audio(self)),
|
||||
|
||||
_ => {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(Error::InvalidData),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtitle(mut self) -> Result<subtitle::Subtitle, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Subtitle.into();
|
||||
}
|
||||
pub fn subtitle(mut self) -> Result<subtitle::Subtitle, Error> {
|
||||
match self.medium() {
|
||||
media::Type::Unknown => {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).codec_type = media::Type::Subtitle.into();
|
||||
}
|
||||
|
||||
Ok(subtitle::Subtitle(self))
|
||||
}
|
||||
Ok(subtitle::Subtitle(self))
|
||||
}
|
||||
|
||||
media::Type::Subtitle => {
|
||||
Ok(subtitle::Subtitle(self))
|
||||
}
|
||||
media::Type::Subtitle => Ok(subtitle::Subtitle(self)),
|
||||
|
||||
_ => {
|
||||
Err(Error::InvalidData)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => Err(Error::InvalidData),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_bit_rate(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).bit_rate = value as int64_t;
|
||||
}
|
||||
}
|
||||
pub fn set_bit_rate(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).bit_rate = value as int64_t;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_max_bit_rate(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).rc_max_rate = value as int64_t;
|
||||
}
|
||||
}
|
||||
pub fn set_max_bit_rate(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).rc_max_rate = value as int64_t;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_tolerance(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).bit_rate_tolerance = value as c_int;
|
||||
}
|
||||
}
|
||||
pub fn set_tolerance(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).bit_rate_tolerance = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_quality(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).global_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
pub fn set_quality(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).global_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_compression(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).compression_level = value as c_int;
|
||||
}
|
||||
else {
|
||||
(*self.as_mut_ptr()).compression_level = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn set_compression(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).compression_level = value as c_int;
|
||||
} else {
|
||||
(*self.as_mut_ptr()).compression_level = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
}
|
||||
}
|
||||
pub fn set_time_base<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).time_base = value.into().into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).framerate = value.into().into();
|
||||
}
|
||||
else {
|
||||
(*self.as_mut_ptr()).framerate.num = 0;
|
||||
(*self.as_mut_ptr()).framerate.den = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn set_frame_rate<R: Into<Rational>>(&mut self, value: Option<R>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).framerate = value.into().into();
|
||||
} else {
|
||||
(*self.as_mut_ptr()).framerate.num = 0;
|
||||
(*self.as_mut_ptr()).framerate.den = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Encoder {
|
||||
type Target = Context;
|
||||
type Target = Context;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Encoder {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Encoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Encoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut *self
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut *self
|
||||
}
|
||||
}
|
||||
|
@ -24,38 +24,36 @@ pub use self::decision::Decision;
|
||||
|
||||
use std::ffi::CString;
|
||||
|
||||
use ffi::*;
|
||||
use codec::Context;
|
||||
use ::Codec;
|
||||
use codec::Id;
|
||||
use ffi::*;
|
||||
use Codec;
|
||||
|
||||
pub fn new() -> Encoder {
|
||||
Context::new().encoder()
|
||||
Context::new().encoder()
|
||||
}
|
||||
|
||||
pub fn find(id: Id) -> Option<Codec> {
|
||||
unsafe {
|
||||
let ptr = avcodec_find_encoder(id.into());
|
||||
unsafe {
|
||||
let ptr = avcodec_find_encoder(id.into());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_by_name(name: &str) -> Option<Codec> {
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_encoder_by_name(name.as_ptr());
|
||||
unsafe {
|
||||
let name = CString::new(name).unwrap();
|
||||
let ptr = avcodec_find_encoder_by_name(name.as_ptr());
|
||||
|
||||
if ptr.is_null() {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(Codec::wrap(ptr))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,50 +2,50 @@ use libc::c_int;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum MotionEstimation {
|
||||
Zero,
|
||||
Full,
|
||||
Log,
|
||||
Phods,
|
||||
Epzs,
|
||||
X1,
|
||||
Hex,
|
||||
Umh,
|
||||
Iter,
|
||||
Tesa,
|
||||
Zero,
|
||||
Full,
|
||||
Log,
|
||||
Phods,
|
||||
Epzs,
|
||||
X1,
|
||||
Hex,
|
||||
Umh,
|
||||
Iter,
|
||||
Tesa,
|
||||
}
|
||||
|
||||
impl From<c_int> for MotionEstimation {
|
||||
fn from(value: c_int) -> MotionEstimation {
|
||||
match value {
|
||||
1 => MotionEstimation::Zero,
|
||||
2 => MotionEstimation::Full,
|
||||
3 => MotionEstimation::Log,
|
||||
4 => MotionEstimation::Phods,
|
||||
5 => MotionEstimation::Epzs,
|
||||
6 => MotionEstimation::X1,
|
||||
7 => MotionEstimation::Hex,
|
||||
8 => MotionEstimation::Umh,
|
||||
9 => MotionEstimation::Iter,
|
||||
10 => MotionEstimation::Tesa,
|
||||
fn from(value: c_int) -> MotionEstimation {
|
||||
match value {
|
||||
1 => MotionEstimation::Zero,
|
||||
2 => MotionEstimation::Full,
|
||||
3 => MotionEstimation::Log,
|
||||
4 => MotionEstimation::Phods,
|
||||
5 => MotionEstimation::Epzs,
|
||||
6 => MotionEstimation::X1,
|
||||
7 => MotionEstimation::Hex,
|
||||
8 => MotionEstimation::Umh,
|
||||
9 => MotionEstimation::Iter,
|
||||
10 => MotionEstimation::Tesa,
|
||||
|
||||
_ => MotionEstimation::Zero
|
||||
}
|
||||
}
|
||||
_ => MotionEstimation::Zero,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<c_int> for MotionEstimation {
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
MotionEstimation::Zero => 1,
|
||||
MotionEstimation::Full => 2,
|
||||
MotionEstimation::Log => 3,
|
||||
MotionEstimation::Phods => 4,
|
||||
MotionEstimation::Epzs => 5,
|
||||
MotionEstimation::X1 => 6,
|
||||
MotionEstimation::Hex => 7,
|
||||
MotionEstimation::Umh => 8,
|
||||
MotionEstimation::Iter => 9,
|
||||
MotionEstimation::Tesa => 10
|
||||
}
|
||||
}
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
MotionEstimation::Zero => 1,
|
||||
MotionEstimation::Full => 2,
|
||||
MotionEstimation::Log => 3,
|
||||
MotionEstimation::Phods => 4,
|
||||
MotionEstimation::Epzs => 5,
|
||||
MotionEstimation::X1 => 6,
|
||||
MotionEstimation::Hex => 7,
|
||||
MotionEstimation::Umh => 8,
|
||||
MotionEstimation::Iter => 9,
|
||||
MotionEstimation::Tesa => 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Prediction {
|
||||
Left,
|
||||
Plane,
|
||||
Median,
|
||||
Left,
|
||||
Plane,
|
||||
Median,
|
||||
}
|
||||
|
||||
impl From<c_int> for Prediction {
|
||||
fn from(value: c_int) -> Prediction {
|
||||
match value {
|
||||
FF_PRED_LEFT => Prediction::Left,
|
||||
FF_PRED_PLANE => Prediction::Plane,
|
||||
FF_PRED_MEDIAN => Prediction::Median,
|
||||
fn from(value: c_int) -> Prediction {
|
||||
match value {
|
||||
FF_PRED_LEFT => Prediction::Left,
|
||||
FF_PRED_PLANE => Prediction::Plane,
|
||||
FF_PRED_MEDIAN => Prediction::Median,
|
||||
|
||||
_ => Prediction::Left
|
||||
}
|
||||
}
|
||||
_ => Prediction::Left,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<c_int> for Prediction {
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Prediction::Left => FF_PRED_LEFT,
|
||||
Prediction::Plane => FF_PRED_PLANE,
|
||||
Prediction::Median => FF_PRED_MEDIAN,
|
||||
}
|
||||
}
|
||||
fn into(self) -> c_int {
|
||||
match self {
|
||||
Prediction::Left => FF_PRED_LEFT,
|
||||
Prediction::Plane => FF_PRED_PLANE,
|
||||
Prediction::Median => FF_PRED_MEDIAN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,114 +1,121 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
use libc::c_int;
|
||||
use ffi::*;
|
||||
use libc::c_int;
|
||||
|
||||
use super::Encoder as Super;
|
||||
use ::{Error, Dictionary};
|
||||
use codec::{traits, Context};
|
||||
use {Dictionary, Error};
|
||||
|
||||
pub struct Subtitle(pub Super);
|
||||
|
||||
impl Subtitle {
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open_as_with<E: traits::Encoder>(mut self, codec: E, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
pub fn open_as_with<E: traits::Encoder>(
|
||||
mut self,
|
||||
codec: E,
|
||||
options: Dictionary,
|
||||
) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Subtitle {
|
||||
type Target = Super;
|
||||
type Target = Super;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Subtitle {
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Subtitle {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Subtitle {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Encoder(pub Subtitle);
|
||||
|
||||
impl Encoder {
|
||||
pub fn encode(&mut self, subtitle: &::Subtitle, out: &mut [u8]) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
match avcodec_encode_subtitle(self.0.as_mut_ptr(), out.as_mut_ptr(), out.len() as c_int, subtitle.as_ptr()) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn encode(&mut self, subtitle: &::Subtitle, out: &mut [u8]) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
match avcodec_encode_subtitle(
|
||||
self.0.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
out.len() as c_int,
|
||||
subtitle.as_ptr(),
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(true),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Encoder {
|
||||
type Target = Subtitle;
|
||||
type Target = Subtitle;
|
||||
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Encoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Encoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
@ -1,490 +1,494 @@
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
|
||||
use libc::{c_int, c_float};
|
||||
use ffi::*;
|
||||
use libc::{c_float, c_int};
|
||||
|
||||
use super::Encoder as Super;
|
||||
use super::{MotionEstimation, Prediction, Comparison, Decision};
|
||||
use ::{color, packet, Error, Rational, Dictionary, frame, format};
|
||||
use super::{Comparison, Decision, MotionEstimation, Prediction};
|
||||
use codec::{traits, Context};
|
||||
use {color, format, frame, packet, Dictionary, Error, Rational};
|
||||
|
||||
pub struct Video(pub Super);
|
||||
|
||||
impl Video {
|
||||
#[inline]
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn open(mut self) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
match avcodec_open2(self.as_mut_ptr(), ptr::null(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn open_as<E: traits::Encoder>(mut self, codec: E) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
match avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), ptr::null_mut()) {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn open_with(mut self, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts);
|
||||
#[inline]
|
||||
pub fn open_with(mut self, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), ptr::null(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn open_as_with<E: traits::Encoder>(mut self, codec: E, options: Dictionary) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
#[inline]
|
||||
pub fn open_as_with<E: traits::Encoder>(
|
||||
mut self,
|
||||
codec: E,
|
||||
options: Dictionary,
|
||||
) -> Result<Encoder, Error> {
|
||||
unsafe {
|
||||
if let Some(codec) = codec.encoder() {
|
||||
let mut opts = options.disown();
|
||||
let res = avcodec_open2(self.as_mut_ptr(), codec.as_ptr(), &mut opts);
|
||||
|
||||
Dictionary::own(opts);
|
||||
Dictionary::own(opts);
|
||||
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e))
|
||||
}
|
||||
}
|
||||
else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
match res {
|
||||
0 => Ok(Encoder(self)),
|
||||
e => Err(Error::from(e)),
|
||||
}
|
||||
} else {
|
||||
Err(Error::EncoderNotFound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).width = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_width(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).width = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).width as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn width(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).width as u32 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).height = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_height(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).height = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).height as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn height(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).height as u32 }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_gop(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).gop_size = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_gop(&mut self, value: u32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).gop_size = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Pixel) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pix_fmt = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_format(&mut self, value: format::Pixel) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pix_fmt = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe {
|
||||
format::Pixel::from((*self.as_ptr()).pix_fmt)
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn format(&self) -> format::Pixel {
|
||||
unsafe { format::Pixel::from((*self.as_ptr()).pix_fmt) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_motion_est")]
|
||||
pub fn set_motion_estimation(&mut self, value: MotionEstimation) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_method = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_motion_est")]
|
||||
pub fn set_motion_estimation(&mut self, value: MotionEstimation) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_method = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_max_b_frames(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).max_b_frames = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_max_b_frames(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).max_b_frames = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_b_quant_factor(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).b_quant_factor = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_b_quant_factor(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).b_quant_factor = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_b_quant_offset(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).b_quant_offset = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_b_quant_offset(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).b_quant_offset = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_i_quant_factor(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).i_quant_factor = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_i_quant_factor(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).i_quant_factor = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_i_quant_offset(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).i_quant_offset = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_i_quant_offset(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).i_quant_offset = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_lumi_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).lumi_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_lumi_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).lumi_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_temporal_cplx_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).temporal_cplx_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_temporal_cplx_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).temporal_cplx_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_spatial_cplx_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).spatial_cplx_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_spatial_cplx_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).spatial_cplx_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_p_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).p_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_p_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).p_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_dark_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).dark_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_dark_masking(&mut self, value: f32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).dark_masking = value as c_float;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_prediction(&mut self, value: Prediction) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).prediction_method = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_prediction(&mut self, value: Prediction) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).prediction_method = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_aspect_ratio<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_aspect_ratio = value.into().into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_aspect_ratio<R: Into<Rational>>(&mut self, value: R) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).sample_aspect_ratio = value.into().into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_me_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_cmp = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_me_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_cmp = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_me_sub_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_sub_cmp = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_me_sub_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_sub_cmp = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_mb_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_cmp = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_mb_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_cmp = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_ildct_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).ildct_cmp = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_ildct_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).ildct_cmp = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_dia_size(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).dia_size = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_dia_size(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).dia_size = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_last_predictors(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).last_predictor_count = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_last_predictors(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).last_predictor_count = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_pre_me(&mut self, value: MotionEstimation) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pre_me = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_pre_me(&mut self, value: MotionEstimation) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pre_me = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_me_pre_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_pre_cmp = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_me_pre_comparison(&mut self, value: Comparison) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_pre_cmp = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_pre_dia_size(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pre_dia_size = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_pre_dia_size(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).pre_dia_size = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_me_subpel_quality(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_subpel_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_me_subpel_quality(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_subpel_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_me_range(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_range = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_me_range(&mut self, value: usize) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).me_range = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_quant_bias")]
|
||||
pub fn set_intra_quant_bias(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).intra_quant_bias = value as c_int;
|
||||
}
|
||||
else {
|
||||
(*self.as_mut_ptr()).intra_quant_bias = FF_DEFAULT_QUANT_BIAS;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_quant_bias")]
|
||||
pub fn set_intra_quant_bias(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).intra_quant_bias = value as c_int;
|
||||
} else {
|
||||
(*self.as_mut_ptr()).intra_quant_bias = FF_DEFAULT_QUANT_BIAS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_quant_bias")]
|
||||
pub fn set_inter_quant_bias(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).inter_quant_bias = value as c_int;
|
||||
}
|
||||
else {
|
||||
(*self.as_mut_ptr()).inter_quant_bias = FF_DEFAULT_QUANT_BIAS;
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[cfg(feature = "ff_api_quant_bias")]
|
||||
pub fn set_inter_quant_bias(&mut self, value: Option<usize>) {
|
||||
unsafe {
|
||||
if let Some(value) = value {
|
||||
(*self.as_mut_ptr()).inter_quant_bias = value as c_int;
|
||||
} else {
|
||||
(*self.as_mut_ptr()).inter_quant_bias = FF_DEFAULT_QUANT_BIAS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_mb_decision(&mut self, value: Decision) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_decision = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_mb_decision(&mut self, value: Decision) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_decision = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_mb_lmin(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_lmin = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_mb_lmin(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_lmin = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_mb_lmax(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_lmax = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_mb_lmax(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).mb_lmax = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_intra_dc_precision(&mut self, value: u8) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).intra_dc_precision = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_intra_dc_precision(&mut self, value: u8) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).intra_dc_precision = i32::from(value);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_qmin(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).qmin = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_qmin(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).qmin = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_qmax(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).qmax = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_qmax(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).qmax = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_global_quality(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).global_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_global_quality(&mut self, value: i32) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).global_quality = value as c_int;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_colorspace(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).colorspace = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_colorspace(&mut self, value: color::Space) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).colorspace = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn colorspace(&self) -> color::Space {
|
||||
unsafe {
|
||||
(*self.as_ptr()).colorspace.into()
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn colorspace(&self) -> color::Space {
|
||||
unsafe { (*self.as_ptr()).colorspace.into() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_range = value.into();
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_color_range(&mut self, value: color::Range) {
|
||||
unsafe {
|
||||
(*self.as_mut_ptr()).color_range = value.into();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe {
|
||||
(*self.as_ptr()).color_range.into()
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color_range(&self) -> color::Range {
|
||||
unsafe { (*self.as_ptr()).color_range.into() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Video {
|
||||
type Target = Super;
|
||||
type Target = Super;
|
||||
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Video {
|
||||
#[inline(always)]
|
||||
fn deref_mut(&mut self) -> &mut<Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
#[inline(always)]
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Video {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Video {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Encoder(pub Video);
|
||||
|
||||
impl Encoder {
|
||||
#[inline]
|
||||
pub fn encode<P: packet::Mut>(&mut self, frame: &frame::Video, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
if self.format() != frame.format() || self.width() != frame.width() || self.height() != frame.height() {
|
||||
return Err(Error::InvalidData);
|
||||
}
|
||||
#[inline]
|
||||
pub fn encode<P: packet::Mut>(
|
||||
&mut self,
|
||||
frame: &frame::Video,
|
||||
out: &mut P,
|
||||
) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
if self.format() != frame.format() || self.width() != frame.width()
|
||||
|| self.height() != frame.height()
|
||||
{
|
||||
return Err(Error::InvalidData);
|
||||
}
|
||||
|
||||
let mut got: c_int = 0;
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_encode_video2(
|
||||
self.0.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
frame.as_ptr(),
|
||||
&mut got,
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn flush<P: packet::Mut>(&mut self, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
#[inline]
|
||||
pub fn flush<P: packet::Mut>(&mut self, out: &mut P) -> Result<bool, Error> {
|
||||
unsafe {
|
||||
let mut got: c_int = 0;
|
||||
|
||||
match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), ptr::null(), &mut got) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
match avcodec_encode_video2(
|
||||
self.0.as_mut_ptr(),
|
||||
out.as_mut_ptr(),
|
||||
ptr::null(),
|
||||
&mut got,
|
||||
) {
|
||||
e if e < 0 => Err(Error::from(e)),
|
||||
_ => Ok(got != 0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe {
|
||||
(*self.as_ptr()).frame_size as u32
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn frame_size(&self) -> u32 {
|
||||
unsafe { (*self.as_ptr()).frame_size as u32 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Encoder {
|
||||
type Target = Video;
|
||||
type Target = Video;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
#[inline]
|
||||
fn deref(&self) -> &<Self as Deref>::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Encoder {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut <Self as Deref>::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Context> for Encoder {
|
||||
fn as_ref(&self) -> &Context {
|
||||
&self
|
||||
}
|
||||
fn as_ref(&self) -> &Context {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Context> for Encoder {
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut Context {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user