diff --git a/src/format/context/output.rs b/src/format/context/output.rs index 84bac41..b200f63 100644 --- a/src/format/context/output.rs +++ b/src/format/context/output.rs @@ -9,7 +9,7 @@ use super::common::Context; use super::destructor; use codec::traits; use ffi::*; -use {format, ChapterMut, Dictionary, Error, Rational, StreamMut}; +use {codec, format, ChapterMut, Dictionary, Error, Rational, StreamMut}; pub struct Output { ptr: *mut AVFormatContext, @@ -86,6 +86,25 @@ impl Output { } } + pub fn add_stream_with(&mut self, context: &codec::Context) -> Result { + unsafe { + let ptr = avformat_new_stream(self.as_mut_ptr(), ptr::null()); + + if ptr.is_null() { + return Err(Error::Unknown); + } + + match avcodec_parameters_from_context((*ptr).codecpar, context.as_ptr()) { + 0 => (), + e => return Err(Error::from(e)), + } + + let index = (*self.ctx.as_ptr()).nb_streams - 1; + + Ok(StreamMut::wrap(&mut self.ctx, index as usize)) + } + } + pub fn add_chapter, S: AsRef>( &mut self, id: i64,