From bde17a8baeababb4f006eef88ebb591f0aa28cb8 Mon Sep 17 00:00:00 2001 From: lummax Date: Fri, 25 Sep 2015 14:33:46 +0200 Subject: [PATCH] format: add `_with()` variants to `open()` --- src/format/mod.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/format/mod.rs b/src/format/mod.rs index 66aa43f..93a44c0 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -195,6 +195,29 @@ pub fn output>(path: &P) -> Result { } } +pub fn output_with>(path: &P, options: Dictionary) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let mut opts = options.disown(); + + match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), ptr::null(), path.as_ptr()) { + 0 => { + 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)), + e => Err(Error::from(e)) + } + } + + e => Err(Error::from(e)) + } + } +} + pub fn output_as>(path: &P, format: &str) -> Result { unsafe { let mut ps = ptr::null_mut(); @@ -213,3 +236,27 @@ pub fn output_as>(path: &P, format: &str) -> Result>(path: &P, format: &str, options: Dictionary) -> Result { + unsafe { + let mut ps = ptr::null_mut(); + let path = from_path(path); + let format = CString::new(format).unwrap(); + let mut opts = options.disown(); + + match avformat_alloc_output_context2(&mut ps, ptr::null_mut(), format.as_ptr(), path.as_ptr()) { + 0 => { + 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)), + e => Err(Error::from(e)) + } + } + + e => Err(Error::from(e)) + } + } +}