pub fn new(mut reader: R) -> Result<Self> {
        let mut d = vec![0u8; std::mem::size_of::<IvfHeader>()];
        reader.read_exact(&mut d)?;

        let header = IvfHeader {
            signature: [d[0], d[1], d[2], d[3]],
            version: u16::from_le_bytes(d[4..=5].try_into()?),
            length: u16::from_le_bytes(d[6..=7].try_into()?),
            four_cc: [d[8], d[9], d[10], d[11]],
            width: u16::from_le_bytes(d[12..=13].try_into()?),
            height: u16::from_le_bytes(d[14..=15].try_into()?),
            frame_rate_rate: u32::from_le_bytes(d[16..=19].try_into()?),
            frame_rate_scale: u32::from_le_bytes(d[20..=23].try_into()?),
            frame_count: u32::from_le_bytes(d[24..=27].try_into()?),
            reserved: [d[28], d[29], d[30], d[31]],
        };

        if header.signature != [0x44, 0x4B, 0x49, 0x46] {
            return Err(IvfError::InvalidHeader("invalid signature".to_owned()));
        }

        if header.version != 0 {
            return Err(IvfError::InvalidHeader("invalid version".to_owned()));
        }

        if header.length != 32 {
            return Err(IvfError::InvalidHeader("invalid length".to_owned()));
        }

        if header.four_cc != [0x56, 0x50, 0x39, 0x30] {
            return Err(IvfError::InvalidHeader(format!(
                "invalid four_cc: {:?}",
                header.four_cc
            )));
        }

        Ok(Self {
            reader,
            header,
            size_buffer: [0u8; 4],
            timestamp_buffer: [0u8; 8],
        })
    }
/// Creates a new IVF using the given reader.
Creates a new IVF using the given reader.
Creates a new IVF using the given reader .
pub fn new(mut reader: R) -> Result<Self> {
        let mut d = vec![0u8; std::mem::size_of::<IvfHeader>()];
        reader.read_exact(&mut d)?;
        let header = IvfHeader {
            signature: [d[0], d[1], d[2], d[3]],
            version: u16::from_le_bytes(d[4..=5].try_into()?),
            length: u16::from_le_bytes(d[6..=7].try_into()?),
            four_cc: [d[8], d[9], d[10], d[11]],
            width: u16::from_le_bytes(d[12..=13].try_into()?),
            height: u16::from_le_bytes(d[14..=15].try_into()?),
            frame_rate_rate: u32::from_le_bytes(d[16..=19].try_into()?),
            frame_rate_scale: u32::from_le_bytes(d[20..=23].try_into()?),
            frame_count: u32::from_le_bytes(d[24..=27].try_into()?),
            reserved: [d[28], d[29], d[30], d[31]],
        };
        if header.signature != [0x44, 0x4B, 0x49, 0x46] {
            return Err(IvfError::InvalidHeader("invalid signature".to_owned()));
        }
        if header.version != 0 {
            return Err(IvfError::InvalidHeader("invalid version".to_owned()));
        }
        if header.length != 32 {
            return Err(IvfError::InvalidHeader("invalid length".to_owned()));
        }
        if header.four_cc != [0x56, 0x50, 0x39, 0x30] {
            return Err(IvfError::InvalidHeader(format!(
                "invalid four_cc: {:?}",
                header.four_cc
            )));
        }
        Ok(Self {
            reader,
            header,
            size_buffer: [0u8; 4],
            timestamp_buffer: [0u8; 8],
        })
    }
pub fn new ( mut reader : R ) -> Result < Self > { let mut d = vec ! [ 0u8 std mem size_of IvfHeader ( ) ] ; reader . read_exact ( & mut d ) ? ; let header = IvfHeader { signature : [ d [ 0 ] , d [ 1 ] , d [ 2 ] , d [ 3 ] ] , version : u16 :: from_le_bytes ( d [ 4 ..= 5 ] . try_into ( ) ? ) , length : u16 :: from_le_bytes ( d [ 6 ..= 7 ] . try_into ( ) ? ) , four_cc : [ d [ 8 ] , d [ 9 ] , d [ 10 ] , d [ 11 ] ] , width : u16 :: from_le_bytes ( d [ 12 ..= 13 ] . try_into ( ) ? ) , height : u16 :: from_le_bytes ( d [ 14 ..= 15 ] . try_into ( ) ? ) , frame_rate_rate : u32 :: from_le_bytes ( d [ 16 ..= 19 ] . try_into ( ) ? ) , frame_rate_scale : u32 :: from_le_bytes ( d [ 20 ..= 23 ] . try_into ( ) ? ) , frame_count : u32 :: from_le_bytes ( d [ 24 ..= 27 ] . try_into ( ) ? ) , reserved : [ d [ 28 ] , d [ 29 ] , d [ 30 ] , d [ 31 ] ] , } ; if header . signature != [ 0x44 , 0x4B , 0x49 , 0x46 ] { return Err ( IvfError :: InvalidHeader ( " " . to_owned ( ) ) ) ; } if header . version != 0 { return Err ( IvfError :: InvalidHeader ( " " . to_owned ( ) ) ) ; } if header . length != 32 { return Err ( IvfError :: InvalidHeader ( " " . to_owned ( ) ) ) ; } if header . four_cc != [ 0x56 , 0x50 , 0x39 , 0x30 ] { return Err ( IvfError :: InvalidHeader ( format ! ( " " header four_cc ) ) ) ; } Ok ( Self { reader , header , size_buffer : [ 0u8 ; 4 ] , timestamp_buffer : [ 0u8 ; 8 ] , } ) }
Creates a new IVF using the given reader.
Creates a new IVF using the given reader .
reader
R
reader
R