diff --git a/src/codec/encoder/video.rs b/src/codec/encoder/video.rs index f8cd4e3..f0eefab 100644 --- a/src/codec/encoder/video.rs +++ b/src/codec/encoder/video.rs @@ -358,6 +358,10 @@ pub struct Encoder(pub Video); impl Encoder { pub fn encode(&mut self, frame: &frame::Video, out: &mut Packet) -> Result { unsafe { + if self.format() != frame.format() { + return Err(Error::InvalidData); + } + let mut got: c_int = 0; match avcodec_encode_video2(self.0.as_mut_ptr(), out.as_mut_ptr(), frame.as_ptr(), &mut got) { @@ -369,7 +373,12 @@ impl Encoder { pub fn flush(&mut self, out: &mut Packet) -> Result { unsafe { - self.encode(&frame::Video::wrap(ptr::null_mut()), out) + 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) + } } }