Struct Context

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

Implementations§

Source§

impl Context

Source

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

Source

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

Source§

impl Context

Source

pub fn get( src_format: Pixel, src_w: u32, src_h: u32, dst_format: Pixel, dst_w: u32, dst_h: u32, flags: Flags, ) -> Result<Self, Error>

Examples found in repository?
examples/dump-frames.rs (lines 24-32)
10fn main() -> Result<(), ffmpeg_rs::Error> {
11    ffmpeg_rs::init().unwrap();
12
13    if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
14        let input = ictx
15            .streams()
16            .best(Type::Video)
17            .ok_or(ffmpeg_rs::Error::StreamNotFound)?;
18        let video_stream_index = input.index();
19
20        let context_decoder =
21            ffmpeg_rs::codec::context::Context::from_parameters(input.parameters())?;
22        let mut decoder = context_decoder.decoder().video()?;
23
24        let mut scaler = Context::get(
25            decoder.format(),
26            decoder.width(),
27            decoder.height(),
28            Pixel::RGB24,
29            decoder.width(),
30            decoder.height(),
31            Flags::BILINEAR,
32        )?;
33
34        let mut frame_index = 0;
35
36        let mut receive_and_process_decoded_frames =
37            |decoder: &mut ffmpeg_rs::decoder::Video| -> Result<(), ffmpeg_rs::Error> {
38                let mut decoded = Video::empty();
39                while decoder.receive_frame(&mut decoded).is_ok() {
40                    let mut rgb_frame = Video::empty();
41                    scaler.run(&decoded, &mut rgb_frame)?;
42                    save_file(&rgb_frame, frame_index).unwrap();
43                    frame_index += 1;
44                }
45                Ok(())
46            };
47
48        for (stream, packet) in ictx.packets() {
49            if stream.index() == video_stream_index {
50                decoder.send_packet(&packet)?;
51                receive_and_process_decoded_frames(&mut decoder)?;
52            }
53        }
54        decoder.send_eof()?;
55        receive_and_process_decoded_frames(&mut decoder)?;
56    }
57
58    Ok(())
59}
Source

pub fn cached( &mut self, src_format: Pixel, src_w: u32, src_h: u32, dst_format: Pixel, dst_w: u32, dst_h: u32, flags: Flags, )

Source

pub fn input(&self) -> &Definition

Source

pub fn output(&self) -> &Definition

Source

pub fn run(&mut self, input: &Video, output: &mut Video) -> Result<(), Error>

Examples found in repository?
examples/dump-frames.rs (line 41)
10fn main() -> Result<(), ffmpeg_rs::Error> {
11    ffmpeg_rs::init().unwrap();
12
13    if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
14        let input = ictx
15            .streams()
16            .best(Type::Video)
17            .ok_or(ffmpeg_rs::Error::StreamNotFound)?;
18        let video_stream_index = input.index();
19
20        let context_decoder =
21            ffmpeg_rs::codec::context::Context::from_parameters(input.parameters())?;
22        let mut decoder = context_decoder.decoder().video()?;
23
24        let mut scaler = Context::get(
25            decoder.format(),
26            decoder.width(),
27            decoder.height(),
28            Pixel::RGB24,
29            decoder.width(),
30            decoder.height(),
31            Flags::BILINEAR,
32        )?;
33
34        let mut frame_index = 0;
35
36        let mut receive_and_process_decoded_frames =
37            |decoder: &mut ffmpeg_rs::decoder::Video| -> Result<(), ffmpeg_rs::Error> {
38                let mut decoded = Video::empty();
39                while decoder.receive_frame(&mut decoded).is_ok() {
40                    let mut rgb_frame = Video::empty();
41                    scaler.run(&decoded, &mut rgb_frame)?;
42                    save_file(&rgb_frame, frame_index).unwrap();
43                    frame_index += 1;
44                }
45                Ok(())
46            };
47
48        for (stream, packet) in ictx.packets() {
49            if stream.index() == video_stream_index {
50                decoder.send_packet(&packet)?;
51                receive_and_process_decoded_frames(&mut decoder)?;
52            }
53        }
54        decoder.send_eof()?;
55        receive_and_process_decoded_frames(&mut decoder)?;
56    }
57
58    Ok(())
59}

Trait Implementations§

Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Context

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> 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, 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.