pub fn movie_fragment(mp4: &MP4, seq_num: u32, source: &[FragmentSource]) -> io::Result<Vec<MP4Box>> {
    let movie = mp4.movie();
    let mut mdat = MediaDataBox::default();

    // Create moof and push movie fragment header.
    let mut moof = MovieFragmentBox::default();
    moof.boxes.push(
        MovieFragmentHeaderBox {
            sequence_number: seq_num,
        }
        .to_mp4box(),
    );

    // Track fragments.
    for src in source {
        let track = movie.track_by_id(src.src_track_id).ok_or(ioerr!(
            NotFound,
            "{}: no such track",
            src.src_track_id
        ))?;
        let traf = track_fragment(
            track,
            src.from_sample,
            src.to_sample,
            src.dst_track_id,
            mp4.data_ref.clone(),
            &mut mdat,
        )?;
        moof.boxes.push(traf.to_mp4box());
    }

    // Now that the moof is done, edit the data_offset field in all the trun boxes.
    let mut cb = CountBytes::new();
    moof.to_bytes(&mut cb).unwrap();
    let moof_sz = cb.size();
    if moof_sz > i32::MAX as u64 {
        return Err(ioerr!(InvalidData, "MovieFragmentBox too large: {}", moof_sz));
    }
    let moof_sz = moof_sz as i32;

    for traf in iter_box_mut!(moof, TrackFragmentBox) {
        for trun in iter_box_mut!(traf, TrackRunBox) {
            trun.data_offset.as_mut().map(|d| *d += moof_sz);
        }
    }

    // moof + mdat.
    let mut boxes = Vec::new();
    boxes.push(moof.to_mp4box());
    boxes.push(mdat.to_mp4box());

    Ok(boxes)
}
/// Generate a MovieFragmentBox + MediaDataBox for a range of samples from one or more tracks.
///
/// Note that from_sample and to_sample for different tracks need to have
/// the same composition time.
Generate a MovieFragmentBox + MediaDataBox for a range of samples from one or more tracks.
Note that from_sample and to_sample for different tracks need to have
the same composition time.
Generate a MovieFragmentBox + MediaDataBox for a range of samples from one or more tracks . Note that from_sample and to_sample for different tracks need to have the same composition time .
pub fn movie_fragment(mp4: &MP4, seq_num: u32, source: &[FragmentSource]) -> io::Result<Vec<MP4Box>> {
    let movie = mp4.movie();
    let mut mdat = MediaDataBox::default();
    // Create moof and push movie fragment header.
    let mut moof = MovieFragmentBox::default();
    moof.boxes.push(
        MovieFragmentHeaderBox {
            sequence_number: seq_num,
        }
        .to_mp4box(),
    );
    // Track fragments.
    for src in source {
        let track = movie.track_by_id(src.src_track_id).ok_or(ioerr!(
            NotFound,
            "{}: no such track",
            src.src_track_id
        ))?;
        let traf = track_fragment(
            track,
            src.from_sample,
            src.to_sample,
            src.dst_track_id,
            mp4.data_ref.clone(),
            &mut mdat,
        )?;
        moof.boxes.push(traf.to_mp4box());
    }
    // Now that the moof is done, edit the data_offset field in all the trun boxes.
    let mut cb = CountBytes::new();
    moof.to_bytes(&mut cb).unwrap();
    let moof_sz = cb.size();
    if moof_sz > i32::MAX as u64 {
        return Err(ioerr!(InvalidData, "MovieFragmentBox too large: {}", moof_sz));
    }
    let moof_sz = moof_sz as i32;
    for traf in iter_box_mut!(moof, TrackFragmentBox) {
        for trun in iter_box_mut!(traf, TrackRunBox) {
            trun.data_offset.as_mut().map(|d| *d += moof_sz);
        }
    }
    // moof + mdat.
    let mut boxes = Vec::new();
    boxes.push(moof.to_mp4box());
    boxes.push(mdat.to_mp4box());
    Ok(boxes)
}
pub fn movie_fragment ( mp4 : & MP4 , seq_num : u32 , source : & [ FragmentSource ] ) -> io :: Result < Vec < MP4Box > > { let movie = mp4 . movie ( ) ; let mut mdat = MediaDataBox :: default ( ) ; // Create moof and push movie fragment header. let mut moof = MovieFragmentBox :: default ( ) ; moof . boxes . push ( MovieFragmentHeaderBox { sequence_number : seq_num , } . to_mp4box ( ) , ) ; // Track fragments. for src in source { let track = movie . track_by_id ( src . src_track_id ) . ok_or ( ioerr ! ( NotFound " " src src_track_id ) ) ? ; let traf = track_fragment ( track , src . from_sample , src . to_sample , src . dst_track_id , mp4 . data_ref . clone ( ) , & mut mdat , ) ? ; moof . boxes . push ( traf . to_mp4box ( ) ) ; } // Now that the moof is done, edit the data_offset field in all the trun boxes. let mut cb = CountBytes :: new ( ) ; moof . to_bytes ( & mut cb ) . unwrap ( ) ; let moof_sz = cb . size ( ) ; if moof_sz > i32 :: MAX as u64 { return Err ( ioerr ! ( InvalidData " " moof_sz ) ) ; } let moof_sz = moof_sz as i32 ; for traf in iter_box_mut ! ( moof TrackFragmentBox ) { for trun in iter_box_mut ! ( traf TrackRunBox ) { trun . data_offset . as_mut ( ) . map ( | d | * d += moof_sz ) ; } } // moof + mdat. let mut boxes = Vec :: new ( ) ; boxes . push ( moof . to_mp4box ( ) ) ; boxes . push ( mdat . to_mp4box ( ) ) ; Ok ( boxes ) }
Generate a MovieFragmentBox + MediaDataBox for a range of samples from one or more tracks.
Generate a MovieFragmentBox + MediaDataBox for a range of samples from one or more tracks .
mp4
&MP4
seq_num
u32
source
&[FragmentSource]
mp4
&MP4
seq_num
u32
source
&[FragmentSource]