Add Output::add_stream_with(&Context)

Calls `avcodec_parameters_from_context` to set the stream attributes from an AVCodecContext.
This commit is contained in:
Luke Street
2023-10-30 11:30:06 -04:00
parent a8c9dbea84
commit 00d5c72290
+20 -1
View File
@@ -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<StreamMut, Error> {
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<R: Into<Rational>, S: AsRef<str>>(
&mut self,
id: i64,