Struct Parameters

Source
pub struct Parameters { /* private fields */ }

Implementations§

Source§

impl Parameters

Source

pub unsafe fn wrap( ptr: *mut AVCodecParameters, owner: Option<Rc<dyn Any>>, ) -> Self

Source

pub unsafe fn as_ptr(&self) -> *const AVCodecParameters

Source

pub unsafe fn as_mut_ptr(&mut self) -> *mut AVCodecParameters

Examples found in repository?
examples/remux.rs (line 37)
6fn main() {
7    let input_file = env::args().nth(1).expect("missing input file");
8    let output_file = env::args().nth(2).expect("missing output file");
9
10    ffmpeg_rs::init().unwrap();
11    log::set_level(log::Level::Warning);
12
13    let mut ictx = format::input(&input_file).unwrap();
14    let mut octx = format::output(&output_file).unwrap();
15
16    let mut stream_mapping = vec![0; ictx.nb_streams() as _];
17    let mut ist_time_bases = vec![Rational(0, 1); ictx.nb_streams() as _];
18    let mut ost_index = 0;
19    for (ist_index, ist) in ictx.streams().enumerate() {
20        let ist_medium = ist.parameters().codec_type();
21        if ist_medium != media::Type::Audio
22            && ist_medium != media::Type::Video
23            && ist_medium != media::Type::Subtitle
24        {
25            stream_mapping[ist_index] = -1;
26            continue;
27        }
28        stream_mapping[ist_index] = ost_index;
29        ist_time_bases[ist_index] = ist.time_base();
30        ost_index += 1;
31        let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
32        ost.set_parameters(ist.parameters());
33        // We need to set codec_tag to 0 lest we run into incompatible codec tag
34        // issues when muxing into a different container format. Unfortunately
35        // there's no high level API to do this (yet).
36        unsafe {
37            (*ost.parameters().as_mut_ptr()).codec_tag = 0;
38        }
39    }
40
41    octx.set_metadata(ictx.metadata().to_owned());
42    octx.write_header().unwrap();
43
44    for (stream, mut packet) in ictx.packets() {
45        let ist_index = stream.index();
46        let ost_index = stream_mapping[ist_index];
47        if ost_index < 0 {
48            continue;
49        }
50        let ost = octx.stream(ost_index as _).unwrap();
51        packet.rescale_ts(ist_time_bases[ist_index], ost.time_base());
52        packet.set_position(-1);
53        packet.set_stream(ost_index as _);
54        packet.write_interleaved(&mut octx).unwrap();
55    }
56
57    octx.write_trailer().unwrap();
58}
More examples
Hide additional examples
examples/transcode-x264.rs (line 225)
164fn main() {
165    let input_file = env::args().nth(1).expect("missing input file");
166    let output_file = env::args().nth(2).expect("missing output file");
167    let x264_opts = parse_opts(
168        env::args()
169            .nth(3)
170            .unwrap_or_else(|| DEFAULT_X264_OPTS.to_string()),
171    )
172    .expect("invalid x264 options string");
173
174    eprintln!("x264 options: {:?}", x264_opts);
175
176    ffmpeg_rs::init().unwrap();
177    log::set_level(log::Level::Info);
178
179    let mut ictx = format::input(&input_file).unwrap();
180    let mut octx = format::output(&output_file).unwrap();
181
182    format::context::input::dump(&ictx, 0, Some(&input_file));
183
184    let best_video_stream_index = ictx
185        .streams()
186        .best(media::Type::Video)
187        .map(|stream| stream.index());
188    let mut stream_mapping: Vec<isize> = vec![0; ictx.nb_streams() as _];
189    let mut ist_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
190    let mut ost_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
191    let mut transcoders = HashMap::new();
192    let mut ost_index = 0;
193    for (ist_index, ist) in ictx.streams().enumerate() {
194        let ist_medium = ist.parameters().codec_type();
195        if ist_medium != media::Type::Audio
196            && ist_medium != media::Type::Video
197            && ist_medium != media::Type::Subtitle
198        {
199            stream_mapping[ist_index] = -1;
200            continue;
201        }
202        stream_mapping[ist_index] = ost_index;
203        ist_time_bases[ist_index] = ist.time_base();
204        if ist_medium == media::Type::Video {
205            // Initialize transcoder for video stream.
206            transcoders.insert(
207                ist_index,
208                Transcoder::new(
209                    &ist,
210                    &mut octx,
211                    ost_index as _,
212                    x264_opts.to_owned(),
213                    Some(ist_index) == best_video_stream_index,
214                )
215                .unwrap(),
216            );
217        } else {
218            // Set up for stream copy for non-video stream.
219            let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
220            ost.set_parameters(ist.parameters());
221            // We need to set codec_tag to 0 lest we run into incompatible codec tag
222            // issues when muxing into a different container format. Unfortunately
223            // there's no high level API to do this (yet).
224            unsafe {
225                (*ost.parameters().as_mut_ptr()).codec_tag = 0;
226            }
227        }
228        ost_index += 1;
229    }
230
231    octx.set_metadata(ictx.metadata().to_owned());
232    format::context::output::dump(&octx, 0, Some(&output_file));
233    octx.write_header().unwrap();
234
235    for (ost_index, _) in octx.streams().enumerate() {
236        ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
237    }
238
239    for (stream, mut packet) in ictx.packets() {
240        let ist_index = stream.index();
241        let ost_index = stream_mapping[ist_index];
242        if ost_index < 0 {
243            continue;
244        }
245        let ost_time_base = ost_time_bases[ost_index as usize];
246        match transcoders.get_mut(&ist_index) {
247            Some(transcoder) => {
248                packet.rescale_ts(stream.time_base(), transcoder.decoder.time_base());
249                transcoder.send_packet_to_decoder(&packet);
250                transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
251            }
252            None => {
253                // Do stream copy on non-video streams.
254                packet.rescale_ts(ist_time_bases[ist_index], ost_time_base);
255                packet.set_position(-1);
256                packet.set_stream(ost_index as _);
257                packet.write_interleaved(&mut octx).unwrap();
258            }
259        }
260    }
261
262    // Flush encoders and decoders.
263    for (ost_index, transcoder) in transcoders.iter_mut() {
264        let ost_time_base = ost_time_bases[*ost_index];
265        transcoder.send_eof_to_decoder();
266        transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
267        transcoder.send_eof_to_encoder();
268        transcoder.receive_and_process_encoded_packets(&mut octx, ost_time_base);
269    }
270
271    octx.write_trailer().unwrap();
272}
Source§

impl Parameters

Source

pub fn new() -> Self

Source

pub fn medium(&self) -> Type

👎Deprecated since 5.1.1: Use codec_type instead
Source

pub fn id(&self) -> Id

👎Deprecated since 5.1.1: Use codec_id instead
Source

pub fn width(&self) -> u32

Source

pub fn set_width(&mut self, value: u32)

Source

pub fn height(&self) -> u32

Source

pub fn set_height(&mut self, value: u32)

Source

pub fn format(&self) -> AVPixelFormat

Source

pub fn set_format(&mut self, format: Pixel)

Source

pub fn codec_type(&self) -> Type

Examples found in repository?
examples/remux.rs (line 20)
6fn main() {
7    let input_file = env::args().nth(1).expect("missing input file");
8    let output_file = env::args().nth(2).expect("missing output file");
9
10    ffmpeg_rs::init().unwrap();
11    log::set_level(log::Level::Warning);
12
13    let mut ictx = format::input(&input_file).unwrap();
14    let mut octx = format::output(&output_file).unwrap();
15
16    let mut stream_mapping = vec![0; ictx.nb_streams() as _];
17    let mut ist_time_bases = vec![Rational(0, 1); ictx.nb_streams() as _];
18    let mut ost_index = 0;
19    for (ist_index, ist) in ictx.streams().enumerate() {
20        let ist_medium = ist.parameters().codec_type();
21        if ist_medium != media::Type::Audio
22            && ist_medium != media::Type::Video
23            && ist_medium != media::Type::Subtitle
24        {
25            stream_mapping[ist_index] = -1;
26            continue;
27        }
28        stream_mapping[ist_index] = ost_index;
29        ist_time_bases[ist_index] = ist.time_base();
30        ost_index += 1;
31        let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
32        ost.set_parameters(ist.parameters());
33        // We need to set codec_tag to 0 lest we run into incompatible codec tag
34        // issues when muxing into a different container format. Unfortunately
35        // there's no high level API to do this (yet).
36        unsafe {
37            (*ost.parameters().as_mut_ptr()).codec_tag = 0;
38        }
39    }
40
41    octx.set_metadata(ictx.metadata().to_owned());
42    octx.write_header().unwrap();
43
44    for (stream, mut packet) in ictx.packets() {
45        let ist_index = stream.index();
46        let ost_index = stream_mapping[ist_index];
47        if ost_index < 0 {
48            continue;
49        }
50        let ost = octx.stream(ost_index as _).unwrap();
51        packet.rescale_ts(ist_time_bases[ist_index], ost.time_base());
52        packet.set_position(-1);
53        packet.set_stream(ost_index as _);
54        packet.write_interleaved(&mut octx).unwrap();
55    }
56
57    octx.write_trailer().unwrap();
58}
More examples
Hide additional examples
examples/transcode-x264.rs (line 194)
164fn main() {
165    let input_file = env::args().nth(1).expect("missing input file");
166    let output_file = env::args().nth(2).expect("missing output file");
167    let x264_opts = parse_opts(
168        env::args()
169            .nth(3)
170            .unwrap_or_else(|| DEFAULT_X264_OPTS.to_string()),
171    )
172    .expect("invalid x264 options string");
173
174    eprintln!("x264 options: {:?}", x264_opts);
175
176    ffmpeg_rs::init().unwrap();
177    log::set_level(log::Level::Info);
178
179    let mut ictx = format::input(&input_file).unwrap();
180    let mut octx = format::output(&output_file).unwrap();
181
182    format::context::input::dump(&ictx, 0, Some(&input_file));
183
184    let best_video_stream_index = ictx
185        .streams()
186        .best(media::Type::Video)
187        .map(|stream| stream.index());
188    let mut stream_mapping: Vec<isize> = vec![0; ictx.nb_streams() as _];
189    let mut ist_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
190    let mut ost_time_bases = vec![Rational(0, 0); ictx.nb_streams() as _];
191    let mut transcoders = HashMap::new();
192    let mut ost_index = 0;
193    for (ist_index, ist) in ictx.streams().enumerate() {
194        let ist_medium = ist.parameters().codec_type();
195        if ist_medium != media::Type::Audio
196            && ist_medium != media::Type::Video
197            && ist_medium != media::Type::Subtitle
198        {
199            stream_mapping[ist_index] = -1;
200            continue;
201        }
202        stream_mapping[ist_index] = ost_index;
203        ist_time_bases[ist_index] = ist.time_base();
204        if ist_medium == media::Type::Video {
205            // Initialize transcoder for video stream.
206            transcoders.insert(
207                ist_index,
208                Transcoder::new(
209                    &ist,
210                    &mut octx,
211                    ost_index as _,
212                    x264_opts.to_owned(),
213                    Some(ist_index) == best_video_stream_index,
214                )
215                .unwrap(),
216            );
217        } else {
218            // Set up for stream copy for non-video stream.
219            let mut ost = octx.add_stream(encoder::find(codec::Id::None)).unwrap();
220            ost.set_parameters(ist.parameters());
221            // We need to set codec_tag to 0 lest we run into incompatible codec tag
222            // issues when muxing into a different container format. Unfortunately
223            // there's no high level API to do this (yet).
224            unsafe {
225                (*ost.parameters().as_mut_ptr()).codec_tag = 0;
226            }
227        }
228        ost_index += 1;
229    }
230
231    octx.set_metadata(ictx.metadata().to_owned());
232    format::context::output::dump(&octx, 0, Some(&output_file));
233    octx.write_header().unwrap();
234
235    for (ost_index, _) in octx.streams().enumerate() {
236        ost_time_bases[ost_index] = octx.stream(ost_index as _).unwrap().time_base();
237    }
238
239    for (stream, mut packet) in ictx.packets() {
240        let ist_index = stream.index();
241        let ost_index = stream_mapping[ist_index];
242        if ost_index < 0 {
243            continue;
244        }
245        let ost_time_base = ost_time_bases[ost_index as usize];
246        match transcoders.get_mut(&ist_index) {
247            Some(transcoder) => {
248                packet.rescale_ts(stream.time_base(), transcoder.decoder.time_base());
249                transcoder.send_packet_to_decoder(&packet);
250                transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
251            }
252            None => {
253                // Do stream copy on non-video streams.
254                packet.rescale_ts(ist_time_bases[ist_index], ost_time_base);
255                packet.set_position(-1);
256                packet.set_stream(ost_index as _);
257                packet.write_interleaved(&mut octx).unwrap();
258            }
259        }
260    }
261
262    // Flush encoders and decoders.
263    for (ost_index, transcoder) in transcoders.iter_mut() {
264        let ost_time_base = ost_time_bases[*ost_index];
265        transcoder.send_eof_to_decoder();
266        transcoder.receive_and_process_decoded_frames(&mut octx, ost_time_base);
267        transcoder.send_eof_to_encoder();
268        transcoder.receive_and_process_encoded_packets(&mut octx, ost_time_base);
269    }
270
271    octx.write_trailer().unwrap();
272}
Source

pub fn set_codec_type(&mut self, codec_type: Type)

Source

pub fn codec_id(&self) -> Id

Source

pub fn set_codec_id(&mut self, codec_id: Id)

Source

pub fn extradata(&mut self) -> &[u8]

Source

pub fn set_extradata(&mut self, extradata: Vec<u8>)

Trait Implementations§

Source§

impl Clone for Parameters

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Parameters

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Parameters

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<C: AsRef<Context>> From<C> for Parameters

Source§

fn from(context: C) -> Parameters

Converts to this type from the input type.
Source§

impl Send for Parameters

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.