Struct Owned

Source
pub struct Owned<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Owned<'a>

Source

pub unsafe fn own(ptr: *mut AVDictionary) -> Self

Source

pub unsafe fn disown(self) -> *mut AVDictionary

Source§

impl<'a> Owned<'a>

Source

pub fn new() -> Self

Methods from Deref<Target = Ref<'a>>§

Source

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

Source

pub fn set(&mut self, key: &str, value: &str)

Methods from Deref<Target = Ref<'a>>§

Source

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

Source

pub fn get(&'a self, key: &str) -> Option<&'a str>

Examples found in repository?
examples/chapters.rs (line 27)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
9        Ok(ictx) => {
10            println!("Nb chapters: {}", ictx.nb_chapters());
11
12            for chapter in ictx.chapters() {
13                println!("chapter id {}:", chapter.id());
14                println!("\ttime_base: {}", chapter.time_base());
15                println!("\tstart: {}", chapter.start());
16                println!("\tend: {}", chapter.end());
17
18                for (k, v) in chapter.metadata().iter() {
19                    println!("\t{}: {}", k, v);
20                }
21            }
22
23            let mut octx =
24                ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file");
25
26            for chapter in ictx.chapters() {
27                let title = match chapter.metadata().get("title") {
28                    Some(title) => String::from(title),
29                    None => String::new(),
30                };
31
32                match octx.add_chapter(
33                    chapter.id(),
34                    chapter.time_base(),
35                    chapter.start(),
36                    chapter.end(),
37                    &title,
38                ) {
39                    Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
40                    Err(error) => {
41                        println!("Error adding chapter with id: {} - {}", chapter.id(), error)
42                    }
43                }
44            }
45
46            println!("\nOuput: nb chapters: {}", octx.nb_chapters());
47            for chapter in octx.chapters() {
48                println!("chapter id {}:", chapter.id());
49                println!("\ttime_base: {}", chapter.time_base());
50                println!("\tstart: {}", chapter.start());
51                println!("\tend: {}", chapter.end());
52                for (k, v) in chapter.metadata().iter() {
53                    println!("\t{}: {}", k, v);
54                }
55            }
56        }
57
58        Err(error) => println!("error: {}", error),
59    }
60}
Source

pub fn iter(&self) -> Iter<'_>

Examples found in repository?
examples/chapters.rs (line 18)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing input file name")) {
9        Ok(ictx) => {
10            println!("Nb chapters: {}", ictx.nb_chapters());
11
12            for chapter in ictx.chapters() {
13                println!("chapter id {}:", chapter.id());
14                println!("\ttime_base: {}", chapter.time_base());
15                println!("\tstart: {}", chapter.start());
16                println!("\tend: {}", chapter.end());
17
18                for (k, v) in chapter.metadata().iter() {
19                    println!("\t{}: {}", k, v);
20                }
21            }
22
23            let mut octx =
24                ffmpeg::format::output(&"test.mkv".to_owned()).expect("Couldn't open test file");
25
26            for chapter in ictx.chapters() {
27                let title = match chapter.metadata().get("title") {
28                    Some(title) => String::from(title),
29                    None => String::new(),
30                };
31
32                match octx.add_chapter(
33                    chapter.id(),
34                    chapter.time_base(),
35                    chapter.start(),
36                    chapter.end(),
37                    &title,
38                ) {
39                    Ok(chapter) => println!("Added chapter with id {} to output", chapter.id()),
40                    Err(error) => {
41                        println!("Error adding chapter with id: {} - {}", chapter.id(), error)
42                    }
43                }
44            }
45
46            println!("\nOuput: nb chapters: {}", octx.nb_chapters());
47            for chapter in octx.chapters() {
48                println!("chapter id {}:", chapter.id());
49                println!("\ttime_base: {}", chapter.time_base());
50                println!("\tstart: {}", chapter.start());
51                println!("\tend: {}", chapter.end());
52                for (k, v) in chapter.metadata().iter() {
53                    println!("\t{}: {}", k, v);
54                }
55            }
56        }
57
58        Err(error) => println!("error: {}", error),
59    }
60}
More examples
Hide additional examples
examples/metadata.rs (line 10)
5fn main() {
6    ffmpeg::init().unwrap();
7
8    match ffmpeg::format::input(&env::args().nth(1).expect("missing file")) {
9        Ok(context) => {
10            for (k, v) in context.metadata().iter() {
11                println!("{}: {}", k, v);
12            }
13
14            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Video) {
15                println!("Best video stream index: {}", stream.index());
16            }
17
18            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Audio) {
19                println!("Best audio stream index: {}", stream.index());
20            }
21
22            if let Some(stream) = context.streams().best(ffmpeg::media::Type::Subtitle) {
23                println!("Best subtitle stream index: {}", stream.index());
24            }
25
26            println!(
27                "duration (seconds): {:.2}",
28                context.duration() as f64 / f64::from(ffmpeg::ffi::AV_TIME_BASE)
29            );
30
31            for stream in context.streams() {
32                println!("stream index {}:", stream.index());
33                println!("\ttime_base: {}", stream.time_base());
34                println!("\tstart_time: {}", stream.start_time());
35                println!("\tduration (stream timebase): {}", stream.duration());
36                println!(
37                    "\tduration (seconds): {:.2}",
38                    stream.duration() as f64 * f64::from(stream.time_base())
39                );
40                println!("\tframes: {}", stream.frames());
41                println!("\tdisposition: {:?}", stream.disposition());
42                println!("\tdiscard: {:?}", stream.discard());
43                println!("\trate: {}", stream.rate());
44
45                let codec = stream.codec();
46                println!("\tmedium: {:?}", codec.medium());
47                println!("\tid: {:?}", codec.id());
48
49                if codec.medium() == ffmpeg::media::Type::Video {
50                    if let Ok(video) = codec.decoder().video() {
51                        println!("\tbit_rate: {}", video.bit_rate());
52                        println!("\tmax_rate: {}", video.max_bit_rate());
53                        println!("\tdelay: {}", video.delay());
54                        println!("\tvideo.width: {}", video.width());
55                        println!("\tvideo.height: {}", video.height());
56                        println!("\tvideo.format: {:?}", video.format());
57                        println!("\tvideo.has_b_frames: {}", video.has_b_frames());
58                        println!("\tvideo.aspect_ratio: {}", video.aspect_ratio());
59                        println!("\tvideo.color_space: {:?}", video.color_space());
60                        println!("\tvideo.color_range: {:?}", video.color_range());
61                        println!("\tvideo.color_primaries: {:?}", video.color_primaries());
62                        println!(
63                            "\tvideo.color_transfer_characteristic: {:?}",
64                            video.color_transfer_characteristic()
65                        );
66                        println!("\tvideo.chroma_location: {:?}", video.chroma_location());
67                        println!("\tvideo.references: {}", video.references());
68                        println!("\tvideo.intra_dc_precision: {}", video.intra_dc_precision());
69                    }
70                } else if codec.medium() == ffmpeg::media::Type::Audio {
71                    if let Ok(audio) = codec.decoder().audio() {
72                        println!("\tbit_rate: {}", audio.bit_rate());
73                        println!("\tmax_rate: {}", audio.max_bit_rate());
74                        println!("\tdelay: {}", audio.delay());
75                        println!("\taudio.rate: {}", audio.rate());
76                        println!("\taudio.channels: {}", audio.channels());
77                        println!("\taudio.format: {:?}", audio.format());
78                        println!("\taudio.frames: {}", audio.frames());
79                        println!("\taudio.align: {}", audio.align());
80                        println!("\taudio.channel_layout: {:?}", audio.channel_layout());
81                        println!("\taudio.frame_start: {:?}", audio.frame_start());
82                    }
83                }
84            }
85        }
86
87        Err(error) => println!("error: {}", error),
88    }
89}
Source

pub fn to_owned<'b>(&self) -> Owned<'b>

Examples found in repository?
examples/transcode-audio.rs (line 156)
136fn main() {
137    ffmpeg::init().unwrap();
138
139    let input = env::args().nth(1).expect("missing input");
140    let output = env::args().nth(2).expect("missing output");
141    let filter = env::args().nth(3).unwrap_or_else(|| "anull".to_owned());
142    let seek = env::args().nth(4).and_then(|s| s.parse::<i64>().ok());
143
144    let mut ictx = format::input(&input).unwrap();
145    let mut octx = format::output(&output).unwrap();
146    let mut transcoder = transcoder(&mut ictx, &mut octx, &output, &filter).unwrap();
147
148    if let Some(position) = seek {
149        // If the position was given in seconds, rescale it to ffmpegs base timebase.
150        let position = position.rescale((1, 1), rescale::TIME_BASE);
151        // If this seek was embedded in the transcoding loop, a call of `flush()`
152        // for every opened buffer after the successful seek would be advisable.
153        ictx.seek(position, ..position).unwrap();
154    }
155
156    octx.set_metadata(ictx.metadata().to_owned());
157    octx.write_header().unwrap();
158
159    let in_time_base = transcoder.decoder.time_base();
160    let out_time_base = octx.stream(0).unwrap().time_base();
161
162    let mut decoded = frame::Audio::empty();
163    let mut encoded = ffmpeg::Packet::empty();
164
165    for (stream, mut packet) in ictx.packets() {
166        if stream.index() == transcoder.stream {
167            packet.rescale_ts(stream.time_base(), in_time_base);
168
169            if let Ok(true) = transcoder.decoder.decode(&packet, &mut decoded) {
170                let timestamp = decoded.timestamp();
171                decoded.set_pts(timestamp);
172
173                transcoder
174                    .filter
175                    .get("in")
176                    .unwrap()
177                    .source()
178                    .add(&decoded)
179                    .unwrap();
180
181                while let Ok(..) = transcoder
182                    .filter
183                    .get("out")
184                    .unwrap()
185                    .sink()
186                    .frame(&mut decoded)
187                {
188                    if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
189                        encoded.set_stream(0);
190                        encoded.rescale_ts(in_time_base, out_time_base);
191                        encoded.write_interleaved(&mut octx).unwrap();
192                    }
193                }
194            }
195        }
196    }
197
198    transcoder
199        .filter
200        .get("in")
201        .unwrap()
202        .source()
203        .flush()
204        .unwrap();
205
206    while let Ok(..) = transcoder
207        .filter
208        .get("out")
209        .unwrap()
210        .sink()
211        .frame(&mut decoded)
212    {
213        if let Ok(true) = transcoder.encoder.encode(&decoded, &mut encoded) {
214            encoded.set_stream(0);
215            encoded.rescale_ts(in_time_base, out_time_base);
216            encoded.write_interleaved(&mut octx).unwrap();
217        }
218    }
219
220    if let Ok(true) = transcoder.encoder.flush(&mut encoded) {
221        encoded.set_stream(0);
222        encoded.rescale_ts(in_time_base, out_time_base);
223        encoded.write_interleaved(&mut octx).unwrap();
224    }
225
226    octx.write_trailer().unwrap();
227}

Trait Implementations§

Source§

impl<'a> Clone for Owned<'a>

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<'a> Default for Owned<'a>

Source§

fn default() -> Self

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

impl<'a> Deref for Owned<'a>

Source§

type Target = Ref<'a>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> DerefMut for Owned<'a>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a> Drop for Owned<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, 'b> FromIterator<&'b (&'b str, &'b str)> for Owned<'a>

Source§

fn from_iter<T: IntoIterator<Item = &'b (&'b str, &'b str)>>( iterator: T, ) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, 'b> FromIterator<&'b (String, String)> for Owned<'a>

Source§

fn from_iter<T: IntoIterator<Item = &'b (String, String)>>(iterator: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, 'b> FromIterator<(&'b str, &'b str)> for Owned<'a>

Source§

fn from_iter<T: IntoIterator<Item = (&'b str, &'b str)>>(iterator: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> FromIterator<(String, String)> for Owned<'a>

Source§

fn from_iter<T: IntoIterator<Item = (String, String)>>(iterator: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Owned<'a>

§

impl<'a> RefUnwindSafe for Owned<'a>

§

impl<'a> !Send for Owned<'a>

§

impl<'a> !Sync for Owned<'a>

§

impl<'a> Unpin for Owned<'a>

§

impl<'a> UnwindSafe for Owned<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.