mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
Add Output::add_stream_with(&Context)
Calls `avcodec_parameters_from_context` to set the stream attributes from an AVCodecContext.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user