pub struct Video(_);

Implementations§

source§

impl Video

source

pub unsafe fn wrap(ptr: *mut AVFrame) -> Self

source

pub unsafe fn alloc(&mut self, format: Pixel, width: u32, height: u32)

source§

impl Video

source

pub fn empty() -> Self

Examples found in repository?
examples/transcode-x264.rs (line 101)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    fn receive_and_process_decoded_frames(
        &mut self,
        octx: &mut format::context::Output,
        ost_time_base: Rational,
    ) {
        let mut frame = frame::Video::empty();
        while self.decoder.receive_frame(&mut frame).is_ok() {
            self.frame_count += 1;
            let timestamp = frame.timestamp();
            self.log_progress(f64::from(
                Rational(timestamp.unwrap_or(0) as i32, 1) * self.decoder.time_base(),
            ));
            frame.set_pts(timestamp);
            frame.set_kind(picture::Type::None);
            self.send_frame_to_encoder(&frame);
            self.receive_and_process_encoded_packets(octx, ost_time_base);
        }
    }
More examples
Hide additional examples
examples/dump-frames.rs (line 38)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
fn main() -> Result<(), ffmpeg::Error> {
    ffmpeg::init().unwrap();

    if let Ok(mut ictx) = input(&env::args().nth(1).expect("Cannot open file.")) {
        let input = ictx
            .streams()
            .best(Type::Video)
            .ok_or(ffmpeg::Error::StreamNotFound)?;
        let video_stream_index = input.index();

        let context_decoder = ffmpeg::codec::context::Context::from_parameters(input.parameters())?;
        let mut decoder = context_decoder.decoder().video()?;

        let mut scaler = Context::get(
            decoder.format(),
            decoder.width(),
            decoder.height(),
            Pixel::RGB24,
            decoder.width(),
            decoder.height(),
            Flags::BILINEAR,
        )?;

        let mut frame_index = 0;

        let mut receive_and_process_decoded_frames =
            |decoder: &mut ffmpeg::decoder::Video| -> Result<(), ffmpeg::Error> {
                let mut decoded = Video::empty();
                while decoder.receive_frame(&mut decoded).is_ok() {
                    let mut rgb_frame = Video::empty();
                    scaler.run(&decoded, &mut rgb_frame)?;
                    save_file(&rgb_frame, frame_index).unwrap();
                    frame_index += 1;
                }
                Ok(())
            };

        for (stream, packet) in ictx.packets() {
            if stream.index() == video_stream_index {
                decoder.send_packet(&packet)?;
                receive_and_process_decoded_frames(&mut decoder)?;
            }
        }
        decoder.send_eof()?;
        receive_and_process_decoded_frames(&mut decoder)?;
    }

    Ok(())
}
source

pub fn new(format: Pixel, width: u32, height: u32) -> Self

source

pub fn format(&self) -> Pixel

source

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

source

pub fn kind(&self) -> Type

source

pub fn set_kind(&mut self, value: Type)

Examples found in repository?
examples/transcode-x264.rs (line 109)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    fn receive_and_process_decoded_frames(
        &mut self,
        octx: &mut format::context::Output,
        ost_time_base: Rational,
    ) {
        let mut frame = frame::Video::empty();
        while self.decoder.receive_frame(&mut frame).is_ok() {
            self.frame_count += 1;
            let timestamp = frame.timestamp();
            self.log_progress(f64::from(
                Rational(timestamp.unwrap_or(0) as i32, 1) * self.decoder.time_base(),
            ));
            frame.set_pts(timestamp);
            frame.set_kind(picture::Type::None);
            self.send_frame_to_encoder(&frame);
            self.receive_and_process_encoded_packets(octx, ost_time_base);
        }
    }
source

pub fn is_interlaced(&self) -> bool

source

pub fn is_top_first(&self) -> bool

source

pub fn has_palette_changed(&self) -> bool

source

pub fn width(&self) -> u32

Examples found in repository?
examples/dump-frames.rs (line 63)
61
62
63
64
65
66
fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> {
    let mut file = File::create(format!("frame{}.ppm", index))?;
    file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?;
    file.write_all(frame.data(0))?;
    Ok(())
}
source

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

source

pub fn height(&self) -> u32

Examples found in repository?
examples/dump-frames.rs (line 63)
61
62
63
64
65
66
fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> {
    let mut file = File::create(format!("frame{}.ppm", index))?;
    file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?;
    file.write_all(frame.data(0))?;
    Ok(())
}
source

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

source

pub fn color_space(&self) -> Space

source

pub fn set_color_space(&mut self, value: Space)

source

pub fn color_range(&self) -> Range

source

pub fn set_color_range(&mut self, value: Range)

source

pub fn color_primaries(&self) -> Primaries

source

pub fn set_color_primaries(&mut self, value: Primaries)

source

pub fn color_transfer_characteristic(&self) -> TransferCharacteristic

source

pub fn set_color_transfer_characteristic( &mut self, value: TransferCharacteristic )

source

pub fn chroma_location(&self) -> Location

source

pub fn aspect_ratio(&self) -> Rational

source

pub fn coded_number(&self) -> usize

source

pub fn display_number(&self) -> usize

source

pub fn repeat(&self) -> f64

source

pub fn stride(&self, index: usize) -> usize

source

pub fn planes(&self) -> usize

source

pub fn plane_width(&self, index: usize) -> u32

source

pub fn plane_height(&self, index: usize) -> u32

source

pub fn plane<T: Component>(&self, index: usize) -> &[T]

source

pub fn plane_mut<T: Component>(&mut self, index: usize) -> &mut [T]

source

pub fn data(&self, index: usize) -> &[u8]

Examples found in repository?
examples/dump-frames.rs (line 64)
61
62
63
64
65
66
fn save_file(frame: &Video, index: usize) -> std::result::Result<(), std::io::Error> {
    let mut file = File::create(format!("frame{}.ppm", index))?;
    file.write_all(format!("P6\n{} {}\n255\n", frame.width(), frame.height()).as_bytes())?;
    file.write_all(frame.data(0))?;
    Ok(())
}
source

pub fn data_mut(&mut self, index: usize) -> &mut [u8]

source§

impl Video

source

pub fn scaler( &self, width: u32, height: u32, flags: Flags ) -> Result<Context, Error>

source

pub fn converter(&self, format: Pixel) -> Result<Context, Error>

Methods from Deref<Target = Frame>§

source

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

source

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

source

pub unsafe fn is_empty(&self) -> bool

source

pub fn is_key(&self) -> bool

source

pub fn is_corrupt(&self) -> bool

source

pub fn packet(&self) -> Packet

source

pub fn pts(&self) -> Option<i64>

source

pub fn set_pts(&mut self, value: Option<i64>)

Examples found in repository?
examples/transcode-audio.rs (line 187)
183
184
185
186
187
188
189
190
191
    fn receive_and_process_decoded_frames(&mut self, octx: &mut format::context::Output) {
        let mut decoded = frame::Audio::empty();
        while self.decoder.receive_frame(&mut decoded).is_ok() {
            let timestamp = decoded.timestamp();
            decoded.set_pts(timestamp);
            self.add_frame_to_filter(&decoded);
            self.get_and_process_filtered_frames(octx);
        }
    }
More examples
Hide additional examples
examples/transcode-x264.rs (line 108)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    fn receive_and_process_decoded_frames(
        &mut self,
        octx: &mut format::context::Output,
        ost_time_base: Rational,
    ) {
        let mut frame = frame::Video::empty();
        while self.decoder.receive_frame(&mut frame).is_ok() {
            self.frame_count += 1;
            let timestamp = frame.timestamp();
            self.log_progress(f64::from(
                Rational(timestamp.unwrap_or(0) as i32, 1) * self.decoder.time_base(),
            ));
            frame.set_pts(timestamp);
            frame.set_kind(picture::Type::None);
            self.send_frame_to_encoder(&frame);
            self.receive_and_process_encoded_packets(octx, ost_time_base);
        }
    }
source

pub fn timestamp(&self) -> Option<i64>

Examples found in repository?
examples/transcode-audio.rs (line 186)
183
184
185
186
187
188
189
190
191
    fn receive_and_process_decoded_frames(&mut self, octx: &mut format::context::Output) {
        let mut decoded = frame::Audio::empty();
        while self.decoder.receive_frame(&mut decoded).is_ok() {
            let timestamp = decoded.timestamp();
            decoded.set_pts(timestamp);
            self.add_frame_to_filter(&decoded);
            self.get_and_process_filtered_frames(octx);
        }
    }
More examples
Hide additional examples
examples/transcode-x264.rs (line 104)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
    fn receive_and_process_decoded_frames(
        &mut self,
        octx: &mut format::context::Output,
        ost_time_base: Rational,
    ) {
        let mut frame = frame::Video::empty();
        while self.decoder.receive_frame(&mut frame).is_ok() {
            self.frame_count += 1;
            let timestamp = frame.timestamp();
            self.log_progress(f64::from(
                Rational(timestamp.unwrap_or(0) as i32, 1) * self.decoder.time_base(),
            ));
            frame.set_pts(timestamp);
            frame.set_kind(picture::Type::None);
            self.send_frame_to_encoder(&frame);
            self.receive_and_process_encoded_packets(octx, ost_time_base);
        }
    }
source

pub fn quality(&self) -> usize

source

pub fn flags(&self) -> Flags

source

pub fn metadata(&self) -> DictionaryRef<'_>

source

pub fn set_metadata(&mut self, value: Dictionary<'_>)

source

pub fn side_data(&self, kind: Type) -> Option<SideData<'_>>

source

pub fn new_side_data(&mut self, kind: Type, size: usize) -> Option<SideData<'_>>

source

pub fn remove_side_data(&mut self, kind: Type)

Trait Implementations§

source§

impl Clone for Video

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 Deref for Video

§

type Target = Frame

The resulting type after dereferencing.
source§

fn deref(&self) -> &Frame

Dereferences the value.
source§

impl DerefMut for Video

source§

fn deref_mut(&mut self) -> &mut Frame

Mutably dereferences the value.
source§

impl From<Frame> for Video

source§

fn from(frame: Frame) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Video> for Video

source§

fn eq(&self, other: &Video) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Video

source§

impl StructuralEq for Video

source§

impl StructuralPartialEq for Video

Auto Trait Implementations§

§

impl RefUnwindSafe for Video

§

impl Send for Video

§

impl Sync for Video

§

impl Unpin for Video

§

impl UnwindSafe for Video

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.