diff --git a/src/format/mod.rs b/src/format/mod.rs index ccfd1d9..d175ced 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -54,10 +54,16 @@ pub fn open(path_or_url: impl AsRef, format: &Format) -> Result { match avformat_alloc_output_context2(&mut ps, format.as_ptr() as *mut _, ptr::null(), path.as_ptr()) { - 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(Context::Output(context::Output::wrap(ps))), - e => Err(Error::from(e)), - }, + 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(Context::Output(output)); + } + match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(Context::Output(output)), + e => Err(Error::from(e)), + } + } e => Err(Error::from(e)), } @@ -90,10 +96,16 @@ pub fn open_with(path_or_url: impl AsRef, format: &Format, options: Dicti Format::Output(ref format) => { match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null(), path.as_ptr()) { - 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(Context::Output(context::Output::wrap(ps))), - e => Err(Error::from(e)), - }, + 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(Context::Output(output)); + } + match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(Context::Output(output)), + e => Err(Error::from(e)), + } + } e => Err(Error::from(e)), } @@ -173,10 +185,16 @@ pub fn output(path_or_url: impl AsRef) -> Result let path = from_os_str(path_or_url); match avformat_alloc_output_context2(&mut ps, ptr::null(), ptr::null(), path.as_ptr()) { - 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)), - }, + 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(output); + } + match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(output), + e => Err(Error::from(e)), + } + } e => Err(Error::from(e)), } @@ -191,12 +209,16 @@ pub fn output_with(path_or_url: impl AsRef, options: Dictionary) -> Resul match avformat_alloc_output_context2(&mut ps, ptr::null(), ptr::null(), path.as_ptr()) { 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(output); + } let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts); Dictionary::own(opts); match res { - 0 => Ok(context::Output::wrap(ps)), + 0 => Ok(output), e => Err(Error::from(e)), } } @@ -206,16 +228,22 @@ pub fn output_with(path_or_url: impl AsRef, options: Dictionary) -> Resul } } -pub fn output_as(path_or_url: impl AsRef, format: format::Output) -> Result { +pub fn output_as(path_or_url: impl AsRef, format: Output) -> Result { unsafe { let mut ps = ptr::null_mut(); let path = from_os_str(path_or_url); match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null_mut(), path.as_ptr()) { - 0 => match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { - 0 => Ok(context::Output::wrap(ps)), - e => Err(Error::from(e)), - }, + 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(output); + } + match avio_open(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE) { + 0 => Ok(output), + e => Err(Error::from(e)), + } + } e => Err(Error::from(e)), } @@ -224,7 +252,7 @@ pub fn output_as(path_or_url: impl AsRef, format: format::Output) -> Resu pub fn output_as_with( path_or_url: impl AsRef, - format: format::Output, + format: Output, options: Dictionary, ) -> Result { unsafe { @@ -234,12 +262,16 @@ pub fn output_as_with( match avformat_alloc_output_context2(&mut ps, format.as_ptr(), ptr::null_mut(), path.as_ptr()) { 0 => { + let output = context::Output::wrap(ps); + if (output.format().flags() & Flags::NO_FILE) == Flags::NO_FILE { + return Ok(output); + } let res = avio_open2(&mut (*ps).pb, path.as_ptr(), AVIO_FLAG_WRITE, ptr::null(), &mut opts); Dictionary::own(opts); match res { - 0 => Ok(context::Output::wrap(ps)), + 0 => Ok(output), e => Err(Error::from(e)), } }