From 0328dc111a6350edce39ea715547f23a269e9f45 Mon Sep 17 00:00:00 2001 From: Eric Kidd Date: Sat, 21 Nov 2015 17:38:00 -0500 Subject: [PATCH] format: fix avformat_find_stream_info return handling According to: https://ffmpeg.org/doxygen/2.8/group__lavf__decoding.html#gad42172e27cddafb81096939783b157bb ...avformat_find_stream_info returns ">=0 if OK, AVERROR_xxx on error". This occurs with several common formats, including MP4 and MKV. --- src/format/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/format/mod.rs b/src/format/mod.rs index 93a44c0..6bea3f9 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -72,8 +72,8 @@ pub fn open>(path: &P, format: &Format) -> Result match avformat_open_input(&mut ps, path.as_ptr(), format.as_ptr(), ptr::null_mut()) { 0 => { match avformat_find_stream_info(ps, ptr::null_mut()) { - 0 => Ok(Context::Input(context::Input::wrap(ps))), - e => Err(Error::from(e)), + r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), + e => Err(Error::from(e)), } } @@ -112,8 +112,8 @@ pub fn open_with>(path: &P, format: &Format, options: Dictionary) match res { 0 => { match avformat_find_stream_info(ps, ptr::null_mut()) { - 0 => Ok(Context::Input(context::Input::wrap(ps))), - e => Err(Error::from(e)), + r if r >= 0 => Ok(Context::Input(context::Input::wrap(ps))), + e => Err(Error::from(e)), } } @@ -145,8 +145,8 @@ pub fn input>(path: &P) -> Result { match avformat_open_input(&mut ps, path.as_ptr(), ptr::null_mut(), ptr::null_mut()) { 0 => { match avformat_find_stream_info(ps, ptr::null_mut()) { - 0 => Ok(context::Input::wrap(ps)), - e => Err(Error::from(e)) + r if r >= 0 => Ok(context::Input::wrap(ps)), + e => Err(Error::from(e)), } } @@ -167,8 +167,8 @@ pub fn input_with>(path: &P, options: Dictionary) -> Result { match avformat_find_stream_info(ps, ptr::null_mut()) { - 0 => Ok(context::Input::wrap(ps)), - e => Err(Error::from(e)) + r if r >= 0 => Ok(context::Input::wrap(ps)), + e => Err(Error::from(e)), } }