pub fn open(path: impl Into<String>, tracks: impl Into<Vec<u32>>) -> io::Result<Mp4Stream> {
        let path = path.into();
        let mut tracks = tracks.into();

        let file = fs::File::open(&path)?;
        let meta = file.metadata()?;
        let modified = meta.modified().unwrap();
        let inode = meta.ino();

        // This is kind of aribitraty.
        //
        // Depending on the file size, we either mmap the entire file, or,
        // every `read_at` the part we need. This is supposing that mapping
        // really large files is more expensive than mapping parts of it
        // multiple times. Is that actually true? XXX TESTME
        let mmap = if meta.len() < 750_000_000 && tracks.len() > 0 {
            Some(unsafe { Mmap::map(&file)? })
        } else {
            None
        };

        // If no tracks were selected, we choose the first video and the first audio track.
        if tracks.len() == 0 {
            let mp4 = open_mp4(&path)?;
            let info = crate::track::track_info(&mp4);
            if let Some(id) = info.iter().find(|t| t.track_type == "vide").map(|t| t.id) {
                tracks.push(id);
            }
            if let Some(id) = info.iter().find(|t| t.track_type == "soun").map(|t| t.id) {
                tracks.push(id);
            }
        }

        // prime the LRU cache.
        let key = SectionKey { path, tracks };
        let mapping = InitSection::mapping(&key)?;
        let init_size = mapping.init_size;
        let size = init_size as u64 + 16 + mapping.virt_size;

        Ok(Mp4Stream {
            key,
            file,
            init_section: None,
            init_size,
            inode,
            modified,
            size,
            pos: 0,
            mmap,
        })
    }
/// Open an MP4 file.
///
/// The opened file is virtual. It only contains the tracks indicated
/// in the `tracks` argument. Also:
///
/// - the tracks are interleaved in 500 ms periods, even if the original file wasn't
/// - the MovieBox box is located at the front of the file rather than at the back.
///
Open an MP4 file.
The opened file is virtual. It only contains the tracks indicated
in the `tracks` argument. Also.

the tracks are interleaved in 500 ms periods, even if the original file wasn't
the MovieBox box is located at the front of the file rather than at the back.
Open an MP4 file . The opened file is virtual . It only contains the tracks indicated in the ` tracks ` argument . Also . the tracks are interleaved in 500 ms periods even if the original file wasn ' t the MovieBox box is located at the front of the file rather than at the back .
pub fn open(path: impl Into<String>, tracks: impl Into<Vec<u32>>) -> io::Result<Mp4Stream> {
        let path = path.into();
        let mut tracks = tracks.into();
        let file = fs::File::open(&path)?;
        let meta = file.metadata()?;
        let modified = meta.modified().unwrap();
        let inode = meta.ino();
        // This is kind of aribitraty.
        //
        // Depending on the file size, we either mmap the entire file, or,
        // every `read_at` the part we need. This is supposing that mapping
        // really large files is more expensive than mapping parts of it
        // multiple times. Is that actually true? XXX TESTME
        let mmap = if meta.len() < 750_000_000 && tracks.len() > 0 {
            Some(unsafe { Mmap::map(&file)? })
        } else {
            None
        };
        // If no tracks were selected, we choose the first video and the first audio track.
        if tracks.len() == 0 {
            let mp4 = open_mp4(&path)?;
            let info = crate::track::track_info(&mp4);
            if let Some(id) = info.iter().find(|t| t.track_type == "vide").map(|t| t.id) {
                tracks.push(id);
            }
            if let Some(id) = info.iter().find(|t| t.track_type == "soun").map(|t| t.id) {
                tracks.push(id);
            }
        }
        // prime the LRU cache.
        let key = SectionKey { path, tracks };
        let mapping = InitSection::mapping(&key)?;
        let init_size = mapping.init_size;
        let size = init_size as u64 + 16 + mapping.virt_size;
        Ok(Mp4Stream {
            key,
            file,
            init_section: None,
            init_size,
            inode,
            modified,
            size,
            pos: 0,
            mmap,
        })
    }
pub fn open ( path : impl Into < String > , tracks : impl Into < Vec < u32 > > ) -> io :: Result < Mp4Stream > { let path = path . into ( ) ; let mut tracks = tracks . into ( ) ; let file = fs :: File :: open ( & path ) ? ; let meta = file . metadata ( ) ? ; let modified = meta . modified ( ) . unwrap ( ) ; let inode = meta . ino ( ) ; // This is kind of aribitraty. // // Depending on the file size, we either mmap the entire file, or, // every `read_at` the part we need. This is supposing that mapping // really large files is more expensive than mapping parts of it // multiple times. Is that actually true? XXX TESTME let mmap = if meta . len ( ) < 750_000_000 && tracks . len ( ) > 0 { Some ( unsafe { Mmap :: map ( & file ) ? } ) } else { None } ; // If no tracks were selected, we choose the first video and the first audio track. if tracks . len ( ) == 0 { let mp4 = open_mp4 ( & path ) ? ; let info = crate :: track :: track_info ( & mp4 ) ; if let Some ( id ) = info . iter ( ) . find ( | t | t . track_type == " " ) . map ( | t | t . id ) { tracks . push ( id ) ; } if let Some ( id ) = info . iter ( ) . find ( | t | t . track_type == " " ) . map ( | t | t . id ) { tracks . push ( id ) ; } } // prime the LRU cache. let key = SectionKey { path , tracks } ; let mapping = InitSection :: mapping ( & key ) ? ; let init_size = mapping . init_size ; let size = init_size as u64 + 16 + mapping . virt_size ; Ok ( Mp4Stream { key , file , init_section : None , init_size , inode , modified , size , pos : 0 , mmap , } ) }
Open an MP4 file.
Open an MP4 file .
path
impl Into<String>
tracks
impl Into<Vec<u32>>
path
impl Into<String>
tracks
impl Into<Vec<u32>>